Skip to content

Commit

Permalink
More of cache expired as override class and file removal at WP_DEBUG
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas Ek committed May 10, 2016
1 parent 789a83f commit c897b92
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 5 deletions.
3 changes: 2 additions & 1 deletion bladerunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Plugin Name: Bladerunner
Plugin URI: http://bladerunner.aekab.se
Description: Laravel Blade template engine for WordPress
Version: 1.4.2
Version: 1.4.3
Author: Andreas Ek
Author URI: http://www.aekab.se/
License: MIT License
Expand All @@ -24,6 +24,7 @@
require_once __DIR__.'/src/Extension.php';
require_once __DIR__.'/src/CompilerExtensions.php';
require_once __DIR__.'/src/Admin.php';
require_once __DIR__.'/src/WPCompiler.php';

add_action('save_post', 'Bladerunner\Cache::removeAllViews');
add_action('admin_init', 'Bladerunner\Init::checkWriteableUpload');
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ekandreas/bladerunner",
"type": "wordpress-plugin",
"version": "1.4.2",
"version": "1.4.3",
"description": "WordPress Blade L5 template engine",
"keywords": ["laravel", "blade", "wordpress"],
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Contributors: ekandreas
Tags: Blade,templates,development,laravel
Requires at least: 4.4
Tested up to: 4.5.2
Stable tag: 1.4.2
Stable tag: 1.4.3
License: MIT

WordPress plugin for Blade L5 templating
Expand Down
4 changes: 2 additions & 2 deletions src/Blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Illuminate\Events\Dispatcher;
use Illuminate\Filesystem\Filesystem;
use Illuminate\View\Engines\CompilerEngine;
use Illuminate\View\Compilers\BladeCompiler;
//use Illuminate\View\Compilers\BladeCompiler;
use Illuminate\View\Engines\EngineResolver;
use Illuminate\View\Engines\PhpEngine;
use Illuminate\View\Factory;
Expand Down Expand Up @@ -149,7 +149,7 @@ public function registerBladeEngine($resolver)
$this->container->singleton('blade.compiler', function ($app) use ($me) {

$cache = $me->cachePath;
$compiler = new BladeCompiler($app['files'], $cache);
$compiler = new WPCompiler($app['files'], $cache);

$extensions = CompilerExtensions::getAllExtensions();
if ($extensions && is_array($extensions)) {
Expand Down
9 changes: 9 additions & 0 deletions src/Globals.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@
*/
function bladerunner($view, $data = [])
{
if (defined('WP_DEBUG') && true === WP_DEBUG) {
$files = glob(\Bladerunner\Cache::path().'/*');
foreach ($files as $file) {
if (is_file($file)) {
@unlink($file);
}
}
}

$bladepath = apply_filters('bladerunner/template/bladepath', get_stylesheet_directory());
$blade = new \Bladerunner\Blade($bladepath, \Bladerunner\Cache::path());
echo $blade->view()->make($view, $data)->render();
Expand Down
34 changes: 34 additions & 0 deletions src/WPCompiler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
namespace Bladerunner;

use Illuminate\View\Compilers\BladeCompiler;
use Illuminate\Filesystem\Filesystem;

class WPCompiler extends BladeCompiler
{
/**
* Determine if the view at the given path is expired.
*
* @param string $path
* @return bool
*/
public function isExpired($path)
{
if (defined('WP_DEBUG') && true === WP_DEBUG) {
return true;
}

$compiled = $this->getCompiledPath($path);

// If the compiled file doesn't exist we will indicate that the view is expired
// so that it can be re-compiled. Else, we will verify the last modification
// of the views is less than the modification times of the compiled views.
if (! $this->cachePath || ! $this->files->exists($compiled)) {
return true;
}

$lastModified = $this->files->lastModified($path);

return $lastModified >= $this->files->lastModified($compiled);
}
}

0 comments on commit c897b92

Please sign in to comment.