-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[ProxyManagerBridge] Polyfill for unmaintained version #32992
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace ProxyManager\Generator\Util; | ||
|
||
use Composer\Autoload\ClassLoader; | ||
use ProxyManager\Version; | ||
|
||
if (class_exists(Version::class) && version_compare(\defined(Version::class.'::VERSION') ? Version::VERSION : Version::getVersion(), '2.5', '<')) { | ||
/** | ||
* Utility class to generate return expressions in method, given a method signature. | ||
* | ||
* This is required since return expressions may be forbidden by the method signature (void). | ||
* | ||
* @author Marco Pivetta <ocramius@gmail.com> | ||
* @license MIT | ||
* | ||
* @see https://github.com/Ocramius/ProxyManager | ||
*/ | ||
final class ProxiedMethodReturnExpression | ||
{ | ||
public static function generate(string $returnedValueExpression, ?\ReflectionMethod $originalMethod): string | ||
{ | ||
$originalReturnType = null === $originalMethod ? null : $originalMethod->getReturnType(); | ||
|
||
$originalReturnTypeName = null === $originalReturnType ? null : $originalReturnType->getName(); | ||
|
||
if ('void' === $originalReturnTypeName) { | ||
return $returnedValueExpression.";\nreturn;"; | ||
} | ||
|
||
return 'return '.$returnedValueExpression.';'; | ||
} | ||
} | ||
} else { | ||
// Fallback to the original class by unregistering this file from composer class loader | ||
$getComposerClassLoader = static function ($functionLoader) use (&$getComposerClassLoader) { | ||
if (\is_array($functionLoader)) { | ||
$functionLoader = $functionLoader[0]; | ||
} | ||
if (!\is_object($functionLoader)) { | ||
return; | ||
} | ||
if ($functionLoader instanceof ClassLoader) { | ||
return $functionLoader; | ||
} | ||
if ($functionLoader instanceof \Symfony\Component\Debug\DebugClassLoader) { | ||
return $getComposerClassLoader($functionLoader->getClassLoader()); | ||
} | ||
if ($functionLoader instanceof \Symfony\Component\ErrorHandler\DebugClassLoader) { | ||
return $getComposerClassLoader($functionLoader->getClassLoader()); | ||
} | ||
}; | ||
|
||
$classLoader = null; | ||
$functions = spl_autoload_functions(); | ||
while (null === $classLoader && $functions) { | ||
$classLoader = $getComposerClassLoader(array_shift($functions)); | ||
} | ||
$getComposerClassLoader = null; | ||
|
||
if (null !== $classLoader) { | ||
$classLoader->addClassMap([ProxiedMethodReturnExpression::class => null]); | ||
$classLoader->loadClass(ProxiedMethodReturnExpression::class); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. modifying the configuration of the main composer autoloader at runtime is a very bad idea: it cancels optimizations performed by @nicolas-grekas to ensure that the whole composer config stays in shared memory (as it triggers copy-on-write on the classmap). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This happens only when a proxy is dumped, which doesn't happen at runtime, so the performance consideration is not an issue actually. |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
}, | ||
"autoload": { | ||
"psr-4": { "Symfony\\Bridge\\ProxyManager\\": "" }, | ||
"classmap": [ "Legacy/ProxiedMethodReturnExpression.php" ], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't this be ported in the main composer file ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh right, didn't see. 👍 |
||
"exclude-from-classmap": [ | ||
"/Tests/" | ||
] | ||
|
Uh oh!
There was an error while loading. Please reload this page.