Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/Illuminate/View/Engines/CompilerEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/View/ViewServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
}
16 changes: 14 additions & 2 deletions tests/View/ViewCompilerEngineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}