Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug #32992 [ProxyManagerBridge] Polyfill for unmaintained version (jd…
…erusse) This PR was squashed before being merged into the 3.4 branch (closes #32992). Discussion ---------- [ProxyManagerBridge] Polyfill for unmaintained version | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #32844 | License | MIT | Doc PR | NA The current implementation of proxy-manager triggers a PHP 7.4 deprecation `ReflectionType::__toString`, and the patch won't be applied to a version prior to 2.5 (see Ocramius/ProxyManager#484) will older version of proxy-manager (2.1 to 2.4 are also compatible with php 7.4). This PR fixes the implementation of `ProxiedMethodReturnExpression` for version prior to 2.5 Commits ------- 33f722d [ProxyManagerBridge] Polyfill for unmaintained version
- Loading branch information
Showing
5 changed files
with
95 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
src/Symfony/Bridge/ProxyManager/Legacy/ProxiedMethodReturnExpression.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters