Skip to content

Commit

Permalink
bug #37144 [DI] Add check around class_alias for generated proxy clas…
Browse files Browse the repository at this point in the history
…ses (enumag)

This PR was merged into the 5.1 branch.

Discussion
----------

[DI] Add check around class_alias for generated proxy classes

| Q             | A
| ------------- | ---
| Branch?       | 5.1
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | nofiles -->
| Tickets       | Fix #37059
| License       | MIT
| Doc PR        |

Here is the [requested](#37059 (comment)) fix.

I'd like to note that I consider this kind of a workaround. I don't know why the issue only started to appear with Symfony 5.1 and not before. There might be some other problem hidden somewhere else.

Commits
-------

c8b7459 Add class_alias for generated proxy classes
  • Loading branch information
nicolas-grekas committed Jun 9, 2020
2 parents 9e1a8f0 + c8b7459 commit 6d6d989
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Expand Up @@ -567,7 +567,7 @@ private function generateProxyClasses(): array
$proxyClass = explode(' ', $this->inlineRequires ? substr($proxyCode, \strlen($code)) : $proxyCode, 3)[1];

if ($this->asFiles || $this->namespace) {
$proxyCode .= "\n\\class_alias(__NAMESPACE__.'\\\\$proxyClass', '$proxyClass', false);\n";
$proxyCode .= "\nif (!\\class_exists('$proxyClass', false)) {\n \\class_alias(__NAMESPACE__.'\\\\$proxyClass', '$proxyClass', false);\n}\n";
}

$proxyClasses[$proxyClass.'.php'] = $proxyCode;
Expand Down Expand Up @@ -1086,7 +1086,7 @@ private function addNewInstance(Definition $definition, string $return = '', str
// If the class is a string we can optimize away
if (0 === strpos($class, "'") && false === strpos($class, '$')) {
if ("''" === $class) {
throw new RuntimeException(sprintf('Cannot dump definition: %s service is defined to be created by a factory but is missing the service reference, did you forget to define the factory service id or class?', $id ? 'The "'.$id.'"' : 'inline'));
throw new RuntimeException(sprintf('Cannot dump definition: "%s" service is defined to be created by a factory but is missing the service reference, did you forget to define the factory service id or class?', $id ? 'The "'.$id.'"' : 'inline'));
}

return $return.sprintf('%s::%s(%s)', $this->dumpLiteralClass($class), $callable[1], $arguments ? implode(', ', $arguments) : '').$tail;
Expand Down
Expand Up @@ -160,7 +160,9 @@ class FooClass_%s extends \Bar\FooClass implements \ProxyManager\Proxy\VirtualPr
%A
}

\class_alias(__NAMESPACE__.'\\FooClass_%s', 'FooClass_%s', false);
if (!\class_exists('FooClass_%s', false)) {
\class_alias(__NAMESPACE__.'\\FooClass_%s', 'FooClass_%s', false);
}

[ProjectServiceContainer.preload.php] => <?php

Expand Down

0 comments on commit 6d6d989

Please sign in to comment.