Skip to content

Commit

Permalink
Avoid resolving view when retrieving the previous compiler (Resolves #…
Browse files Browse the repository at this point in the history
  • Loading branch information
srmklive committed Feb 10, 2022
1 parent 678b959 commit b23349b
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/HTMLMinServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
*/
class HTMLMinServiceProvider extends ServiceProvider
{
/**
* @var \Illuminate\View\Compilers\CompilerInterface|null
*/
protected $previousCompiler;

/**
* Boot the service provider.
*
Expand Down Expand Up @@ -164,18 +169,22 @@ protected function registerBladeMinifier()
*/
protected function registerMinifyCompiler()
{
$previousCompiler = $this->app->make('view')
->getEngineResolver()
->resolve('blade')
->getCompiler();
if (method_exists($this, 'callAfterResolving')) {
$this->callAfterResolving('view', function () {
$this->previousCompiler = $this->app->make('view')
->getEngineResolver()
->resolve('blade')
->getCompiler();
});
}

$this->app->singleton('htmlmin.compiler', function (Container $app) use ($previousCompiler) {
$this->app->singleton('htmlmin.compiler', function (Container $app) {
$blade = $app['htmlmin.blade'];
$files = $app['files'];
$storagePath = $app->config->get('view.compiled');
$ignoredPaths = $app->config->get('htmlmin.ignore', []);

return new MinifyCompiler($blade, $files, $storagePath, $ignoredPaths, $previousCompiler);
return new MinifyCompiler($blade, $files, $storagePath, $ignoredPaths, $this->previousCompiler);
});

$this->app->alias('htmlmin.compiler', MinifyCompiler::class);
Expand Down

0 comments on commit b23349b

Please sign in to comment.