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
38 changes: 37 additions & 1 deletion src/Illuminate/View/Compilers/BladeCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Illuminate\View\Compilers;

use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use InvalidArgumentException;
Expand Down Expand Up @@ -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.
*
Expand All @@ -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);
}
}
Expand Down Expand Up @@ -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()} */";
}
}
2 changes: 1 addition & 1 deletion src/Illuminate/View/ViewServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']
);
});

Expand Down
8 changes: 8 additions & 0 deletions tests/View/ViewBladeCompilerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down