Skip to content
Closed
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
2 changes: 1 addition & 1 deletion src/Illuminate/Support/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ protected function loadViewsFrom($path, $namespace)
}
}

$view->addNamespace($namespace, $path);
$view->addNamespace($namespace, realpath($path) ?: $path);
});
}

Expand Down
13 changes: 11 additions & 2 deletions src/Illuminate/View/Engines/CompilerEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,27 @@ class CompilerEngine extends PhpEngine
*/
protected $compiledOrNotExpired = [];

/**
* Flag to check expired views.
*
* @var bool
*/
protected $checkExpiredViews = true;

/**
* Create a new compiler engine instance.
*
* @param \Illuminate\View\Compilers\CompilerInterface $compiler
* @param \Illuminate\Filesystem\Filesystem|null $files
* @param bool $checkExpiredViews
* @return void
*/
public function __construct(CompilerInterface $compiler, Filesystem $files = null)
public function __construct(CompilerInterface $compiler, Filesystem $files = null, $checkExpiredViews = true)
{
parent::__construct($files ?: new Filesystem);

$this->compiler = $compiler;
$this->checkExpiredViews = $checkExpiredViews;
}

/**
Expand All @@ -58,7 +67,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 (! isset($this->compiledOrNotExpired[$path]) && $this->compiler->isExpired($path)) {
if ($this->checkExpiredViews && ! isset($this->compiledOrNotExpired[$path]) && $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 @@ -161,7 +161,7 @@ public function registerPhpEngine($resolver)
public function registerBladeEngine($resolver)
{
$resolver->register('blade', function () {
$compiler = new CompilerEngine($this->app['blade.compiler'], $this->app['files']);
$compiler = new CompilerEngine($this->app['blade.compiler'], $this->app['files'], $this->app['config']['view.check_compiled'] ?? true);

$this->app->terminating(static function () use ($compiler) {
$compiler->forgetCompiledOrNotExpired();
Expand Down
16 changes: 14 additions & 2 deletions tests/View/ViewCompilerEngineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,20 @@ public function testThatViewsAreNotAskTwiceIfTheyAreExpired()
$engine->get(__DIR__.'/fixtures/foo.php');
}

protected function getEngine()
public function testViewsAreNotRecompiledIfWeDoNotWantThemRecompiled()
{
return new CompilerEngine(m::mock(CompilerInterface::class), new Filesystem);
$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), new Filesystem, $checkExpiredViews);
}
}