diff --git a/src/Illuminate/View/Compilers/BladeCompiler.php b/src/Illuminate/View/Compilers/BladeCompiler.php index ddbfd912c2ae..a834ee6e4ae7 100644 --- a/src/Illuminate/View/Compilers/BladeCompiler.php +++ b/src/Illuminate/View/Compilers/BladeCompiler.php @@ -2,6 +2,7 @@ namespace Illuminate\View\Compilers; +use Illuminate\Filesystem\Filesystem; use Illuminate\Support\Arr; use Illuminate\Support\Str; use InvalidArgumentException; @@ -105,6 +106,29 @@ class BladeCompiler extends Compiler implements CompilerInterface */ protected $rawBlocks = []; + /** + * Provide debug info in the compiled views. + * + * @var boolean + */ + protected $debugInfo; + + /** + * Create a new compiler instance. + * + * @param Filesystem $files + * @param string $cachePath + * @param boolean $debugInfo + * @return void + * + * @throws \InvalidArgumentException + */ + public function __construct(Filesystem $files, $cachePath, $debugInfo = false) + { + parent::__construct($files, $cachePath); + $this->debugInfo = $debugInfo; + } + /** * Compile the view at the given path. * @@ -119,7 +143,9 @@ public function compile($path = null) if (! is_null($this->cachePath)) { $contents = $this->compileString($this->files->get($this->getPath())); - + if ($this->debugInfo) { + $contents .= $this->generateDebugInfo(); + } $this->files->put($this->getCompiledPath($this->getPath()), $contents); } } @@ -521,4 +547,14 @@ public function withoutDoubleEncoding() { $this->setEchoFormat('e(%s, false)'); } + + /** + * Generate debug info for the file. + * + * @return string + */ + protected function generateDebugInfo() + { + return "\n /* {$this->getPath()} */"; + } } diff --git a/src/Illuminate/View/ViewServiceProvider.php b/src/Illuminate/View/ViewServiceProvider.php index fa88136a71b8..9565c9ff0853 100755 --- a/src/Illuminate/View/ViewServiceProvider.php +++ b/src/Illuminate/View/ViewServiceProvider.php @@ -138,7 +138,7 @@ public function registerBladeEngine($resolver) // instance to pass into the engine so it can compile the views properly. $this->app->singleton('blade.compiler', function () { return new BladeCompiler( - $this->app['files'], $this->app['config']['view.compiled'] + $this->app['files'], $this->app['config']['view.compiled'], $this->app['config']['view.debugInfo'] ); }); diff --git a/tests/View/ViewBladeCompilerTest.php b/tests/View/ViewBladeCompilerTest.php index 76333d743706..ed4fa04a26e4 100644 --- a/tests/View/ViewBladeCompilerTest.php +++ b/tests/View/ViewBladeCompilerTest.php @@ -93,6 +93,14 @@ public function testRawTagsCanBeSetToLegacyValues() }}')); } + public function testIncludeDebugInfo() + { + $compiler = new BladeCompiler($files = $this->getFiles(), __DIR__, true); + $files->shouldReceive('get')->once()->with('foo')->andReturn('Hello World'); + $files->shouldReceive('put')->once()->with(__DIR__.'/'.sha1('foo').'.php', "Hello World\n /* foo */"); + $compiler->compile('foo'); + } + protected function getFiles() { return m::mock(Filesystem::class);