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
18 changes: 14 additions & 4 deletions src/Illuminate/View/Compilers/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,51 @@
namespace Illuminate\View\Compilers;

use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Str;
use InvalidArgumentException;

abstract class Compiler
{
/**
* The Filesystem instance.
* The filesystem instance.
*
* @var \Illuminate\Filesystem\Filesystem
*/
protected $files;

/**
* Get the cache path for the compiled views.
* The cache path for the compiled views.
*
* @var string
*/
protected $cachePath;

/**
* The base path that should be removed from paths before hashing.
*
* @var string
*/
protected $basePath;

/**
* Create a new compiler instance.
*
* @param \Illuminate\Filesystem\Filesystem $files
* @param string $cachePath
* @param string $basePath
* @return void
*
* @throws \InvalidArgumentException
*/
public function __construct(Filesystem $files, $cachePath)
public function __construct(Filesystem $files, $cachePath, $basePath = '')
{
if (! $cachePath) {
throw new InvalidArgumentException('Please provide a valid cache path.');
}

$this->files = $files;
$this->cachePath = $cachePath;
$this->basePath = $basePath;
}

/**
Expand All @@ -48,7 +58,7 @@ public function __construct(Filesystem $files, $cachePath)
*/
public function getCompiledPath($path)
{
return $this->cachePath.'/'.sha1($path).'.php';
return $this->cachePath.'/'.sha1(Str::after($path, $this->basePath)).'.php';
}

/**
Expand Down
6 changes: 5 additions & 1 deletion src/Illuminate/View/ViewServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ public function registerViewFinder()
public function registerBladeCompiler()
{
$this->app->singleton('blade.compiler', function ($app) {
return tap(new BladeCompiler($app['files'], $app['config']['view.compiled']), function ($blade) {
return tap(new BladeCompiler(
$app['files'],
$app['config']['view.compiled'],
$app['config']->get('view.relative_hash', false) ? $app->basePath() : '',
), function ($blade) {
$blade->component('dynamic-component', DynamicComponent::class);
});
});
Expand Down