diff --git a/src/Illuminate/View/Engines/CompilerEngine.php b/src/Illuminate/View/Engines/CompilerEngine.php index 65688bd61a17..1e59142ac3d6 100755 --- a/src/Illuminate/View/Engines/CompilerEngine.php +++ b/src/Illuminate/View/Engines/CompilerEngine.php @@ -22,15 +22,24 @@ class CompilerEngine extends PhpEngine */ protected $lastCompiled = []; + /** + * Flag to check expired views. + * + * @var bool + */ + protected $checkExpiredViews; + /** * Create a new Blade view engine instance. * * @param \Illuminate\View\Compilers\CompilerInterface $compiler + * @param bool $checkExpiredViews * @return void */ - public function __construct(CompilerInterface $compiler) + public function __construct(CompilerInterface $compiler, $checkExpiredViews = true) { $this->compiler = $compiler; + $this->checkExpiredViews = $checkExpiredViews; } /** @@ -47,7 +56,7 @@ public function get($path, array $data = []) // If this given view has expired, which means it has simply been edited since // it was last compiled, we will re-compile the views so we can evaluate a // fresh copy of the view. We'll pass the compiler the path of the view. - if ($this->compiler->isExpired($path)) { + if ($this->checkExpiredViews && $this->compiler->isExpired($path)) { $this->compiler->compile($path); } diff --git a/src/Illuminate/View/ViewServiceProvider.php b/src/Illuminate/View/ViewServiceProvider.php index c06624f82f7c..109eaab753f2 100755 --- a/src/Illuminate/View/ViewServiceProvider.php +++ b/src/Illuminate/View/ViewServiceProvider.php @@ -150,7 +150,7 @@ public function registerPhpEngine($resolver) public function registerBladeEngine($resolver) { $resolver->register('blade', function () { - return new CompilerEngine($this->app['blade.compiler']); + return new CompilerEngine($this->app['blade.compiler'], $this->app['config']['view.check_compiled'] ?? true); }); } } diff --git a/tests/View/ViewCompilerEngineTest.php b/tests/View/ViewCompilerEngineTest.php index 2237110980ff..08176719f8ab 100755 --- a/tests/View/ViewCompilerEngineTest.php +++ b/tests/View/ViewCompilerEngineTest.php @@ -38,8 +38,20 @@ public function testViewsAreNotRecompiledIfTheyAreNotExpired() ', $results); } - protected function getEngine() + public function testViewsAreNotRecompiledIfWeDoNotWantThemRecompiled() { - return new CompilerEngine(m::mock(CompilerInterface::class)); + $engine = $this->getEngine(false); + $engine->getCompiler()->shouldReceive('getCompiledPath')->with(__DIR__.'/fixtures/foo.php')->andReturn(__DIR__.'/fixtures/basic.php'); + $engine->getCompiler()->shouldReceive('isExpired')->never(); + $engine->getCompiler()->shouldReceive('compile')->never(); + $results = $engine->get(__DIR__.'/fixtures/foo.php'); + + $this->assertSame('Hello World +', $results); + } + + protected function getEngine($checkExpiredViews = true) + { + return new CompilerEngine(m::mock(CompilerInterface::class), $checkExpiredViews); } }