From c897b9207ef394c5c0c5c99fd6929632026428b4 Mon Sep 17 00:00:00 2001 From: Andreas Ek Date: Tue, 10 May 2016 11:36:46 +0200 Subject: [PATCH] More of cache expired as override class and file removal at WP_DEBUG --- bladerunner.php | 3 ++- composer.json | 2 +- readme.txt | 2 +- src/Blade.php | 4 ++-- src/Globals.php | 9 +++++++++ src/WPCompiler.php | 34 ++++++++++++++++++++++++++++++++++ 6 files changed, 49 insertions(+), 5 deletions(-) create mode 100644 src/WPCompiler.php diff --git a/bladerunner.php b/bladerunner.php index 51f9f53..a740c4a 100644 --- a/bladerunner.php +++ b/bladerunner.php @@ -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 @@ -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'); diff --git a/composer.json b/composer.json index db54d1e..2501047 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/readme.txt b/readme.txt index 90edcf6..c469ea5 100644 --- a/readme.txt +++ b/readme.txt @@ -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 diff --git a/src/Blade.php b/src/Blade.php index f0f4029..5f0b152 100644 --- a/src/Blade.php +++ b/src/Blade.php @@ -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; @@ -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)) { diff --git a/src/Globals.php b/src/Globals.php index e2e6bf7..f4f3bdf 100644 --- a/src/Globals.php +++ b/src/Globals.php @@ -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(); diff --git a/src/WPCompiler.php b/src/WPCompiler.php new file mode 100644 index 0000000..5b7d5a3 --- /dev/null +++ b/src/WPCompiler.php @@ -0,0 +1,34 @@ +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); + } +}