8000 [DI] fix perf issue with lazy autowire error messages by nicolas-grekas · Pull Request #32715 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[DI] fix perf issue with lazy autowire error messages #32715

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

Merged
merged 1 commit into from
Jul 26, 2019
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
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class AutowirePass extends AbstractRecursivePass
private $getPreviousValue;
private $decoratedMethodIndex;
private $decoratedMethodArgumentIndex;
private $typesClone;

public function __construct(bool $throwOnAutowireException = true)
{
Expand All @@ -49,16 +50,16 @@ public function __construct(bool $throwOnAutowireException = true)
public function process(ContainerBuilder $container)
{
try {
$this->typesClone = clone $this;
parent::process($container);
} finally {
$this->types = null;
$this->ambiguousServiceTypes = null;
$this->decoratedClass = null;
$this->decoratedId = null;
$this->methodCalls = null;
$this->getPreviousValue = null;
$this->decoratedMethodIndex = null;
$this->decoratedMethodArgumentIndex = null;
$this->typesClone = null;
}
}

Expand Down Expand Up @@ -375,20 +376,22 @@ private function set(string $type, string $id)

private function createTypeNotFoundMessageCallback(TypedReference $reference, $label)
{
$container = new ContainerBuilder($this->container->getParameterBag());
$container->setAliases($this->container->getAliases());
$container->setDefinitions($this->container->getDefinitions());
$container->setResourceTracking(false);
if (null === $this->typesClone->container) {
Copy link
Member

Choose a reason for hiding this comment

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

the container property should be declared as a private property of the class. We don't want to make it a dynamic public property.

8000
Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

ah, I missed the fact it was an inherited property. All good then.

$this->typesClone->container = new ContainerBuilder($this->container->getParameterBag());
$this->typesClone->container->setAliases($this->container->getAliases());
$this->typesClone->container->setDefinitions($this->container->getDefinitions());
$this->typesClone->container->setResourceTracking(false);
}
$currentId = $this->currentId;

return function () use ($container, $reference, $label, $currentId) {
return $this->createTypeNotFoundMessage($container, $reference, $label, $currentId);
};
return (function () use ($reference, $label, $currentId) {
return $this->createTypeNotFoundMessage($reference, $label, $currentId);
})->bindTo($this->typesClone);
}

private function createTypeNotFoundMessage(ContainerBuilder $container, TypedReference $reference, $label, string $currentId)
private function createTypeNotFoundMessage(TypedReference $reference, $label, string $currentId)
{
if (!$r = $container->getReflectionClass($type = $reference->getType(), false)) {
if (!$r = $this->container->getReflectionClass($type = $reference->getType(), false)) {
// either $type does not exist or a parent class does not exist
try {
$resource = new ClassExistenceResource($type, false);
Expand All @@ -401,8 +404,8 @@ private function createTypeNotFoundMessage(ContainerBuilder $container, TypedRef

$message = sprintf('has type "%s" but this class %s.', $type, $parentMsg ? sprintf('is missing a parent class (%s)', $parentMsg) : 'was not found');
} else {
$alternatives = $this->createTypeAlternatives($container, $reference);
$message = $container->has($type) ? 'this service is abstract' : 'no such service exists';
$alternatives = $this->createTypeAlternatives($this->container, $reference);
$message = $this->container->has($type) ? 'this service is abstract' : 'no such service exists';
$message = sprintf('references %s "%s" but %s.%s', $r->isInterface() ? 'interface' : 'class', $type, $message, $alternatives);

if ($r->isInterface() && !$alternatives) {
Expand Down
0