diff --git a/src/Illuminate/View/Compilers/Compiler.php b/src/Illuminate/View/Compilers/Compiler.php index 42aa0f6d7be6..3237d5aed926 100755 --- a/src/Illuminate/View/Compilers/Compiler.php +++ b/src/Illuminate/View/Compilers/Compiler.php @@ -29,17 +29,25 @@ abstract class Compiler */ protected $basePath; + /** + * Determines if compiled views should be cached. + * + * @var bool + */ + protected $shouldCache; + /** * Create a new compiler instance. * * @param \Illuminate\Filesystem\Filesystem $files * @param string $cachePath * @param string $basePath + * @param bool $shouldCache * @return void * * @throws \InvalidArgumentException */ - public function __construct(Filesystem $files, $cachePath, $basePath = '') + public function __construct(Filesystem $files, $cachePath, $basePath = '', $shouldCache = true) { if (! $cachePath) { throw new InvalidArgumentException('Please provide a valid cache path.'); @@ -48,6 +56,7 @@ public function __construct(Filesystem $files, $cachePath, $basePath = '') $this->files = $files; $this->cachePath = $cachePath; $this->basePath = $basePath; + $this->shouldCache = $shouldCache; } /** @@ -69,6 +78,10 @@ public function getCompiledPath($path) */ public function isExpired($path) { + if (! $this->shouldCache) { + return true; + } + $compiled = $this->getCompiledPath($path); // If the compiled file doesn't exist we will indicate that the view is expired diff --git a/src/Illuminate/View/ViewServiceProvider.php b/src/Illuminate/View/ViewServiceProvider.php index 9baeb2c83777..5a53f422868e 100755 --- a/src/Illuminate/View/ViewServiceProvider.php +++ b/src/Illuminate/View/ViewServiceProvider.php @@ -89,6 +89,7 @@ public function registerBladeCompiler() $app['files'], $app['config']['view.compiled'], $app['config']->get('view.relative_hash', false) ? $app->basePath() : '', + $app['config']->get('view.cache', true), ), function ($blade) { $blade->component('dynamic-component', DynamicComponent::class); }); diff --git a/tests/View/ViewBladeCompilerTest.php b/tests/View/ViewBladeCompilerTest.php index 2be9e8760fbf..e0841c949732 100644 --- a/tests/View/ViewBladeCompilerTest.php +++ b/tests/View/ViewBladeCompilerTest.php @@ -39,6 +39,21 @@ public function testIsExpiredReturnsTrueWhenModificationTimesWarrant() $this->assertTrue($compiler->isExpired('foo')); } + public function testIsExpiredReturnsFalseWhenUseCacheIsTrueAndNoFileModification() + { + $compiler = new BladeCompiler($files = $this->getFiles(), __DIR__); + $files->shouldReceive('exists')->once()->with(__DIR__.'/'.sha1('v2foo').'.php')->andReturn(true); + $files->shouldReceive('lastModified')->once()->with('foo')->andReturn(0); + $files->shouldReceive('lastModified')->once()->with(__DIR__.'/'.sha1('v2foo').'.php')->andReturn(100); + $this->assertFalse($compiler->isExpired('foo')); + } + + public function testIsExpiredReturnsTrueWhenUseCacheIsFalse() + { + $compiler = new BladeCompiler($files = $this->getFiles(), __DIR__, $basePath = '', $useCache = false); + $this->assertTrue($compiler->isExpired('foo')); + } + public function testCompilePathIsProperlyCreated() { $compiler = new BladeCompiler($this->getFiles(), __DIR__);