Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[10.x] Fixes view engine resolvers leaking memory #51450

Merged
merged 1 commit into from
May 17, 2024
Merged
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
13 changes: 9 additions & 4 deletions src/Illuminate/View/ViewServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public function registerEngineResolver()
public function registerFileEngine($resolver)
{
$resolver->register('file', function () {
return new FileEngine($this->app['files']);
return new FileEngine(app()->make('files'));
});
}

Expand All @@ -148,7 +148,7 @@ public function registerFileEngine($resolver)
public function registerPhpEngine($resolver)
{
$resolver->register('php', function () {
return new PhpEngine($this->app['files']);
return new PhpEngine(app()->make('files'));
});
}

Expand All @@ -161,9 +161,14 @@ public function registerPhpEngine($resolver)
public function registerBladeEngine($resolver)
{
$resolver->register('blade', function () {
$compiler = new CompilerEngine($this->app['blade.compiler'], $this->app['files']);
$app = app();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@driesvints @nunomaduro

As the app() helper is pulled from the Foundation component, doesn't the View component's composer.json file need to be updated to account for that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One option is to call Container::getInstance() as the app() helper basically does only that, and the Container component is already required by the view component.

For the other usage, Container::getInstance()->make($dependency) can be used.

function app($abstract = null, array $parameters = [])
{
if (is_null($abstract)) {
return Container::getInstance();
}
return Container::getInstance()->make($abstract, $parameters);
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


$this->app->terminating(static function () use ($compiler) {
$compiler = new CompilerEngine(
$app->make('blade.compiler'),
$app->make('files'),
);

$app->terminating(static function () use ($compiler) {
$compiler->forgetCompiledOrNotExpired();
});

Expand Down