Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide a polyfill for proxy-manager
- Loading branch information
Showing
5 changed files
with
86 additions
and
2 deletions.
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
69 changes: 69 additions & 0 deletions
69
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,69 @@ | ||
<?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 ReflectionMethod; | ||
use Symfony\Component\Debug\DebugClassLoader; | ||
|
||
if (class_exists(\ProxyManager\Version::class) && \version_compare(\ProxyManager\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 | ||
*/ | ||
final class ProxiedMethodReturnExpression | ||
{ | ||
public static function generate(string $returnedValueExpression, ?ReflectionMethod $originalMethod) : string | ||
{ | ||
$originalReturnType = $originalMethod === null | ||
? null | ||
: $originalMethod->getReturnType(); | ||
$originalReturnTypeName = $originalReturnType === null | ||
? null | ||
: $originalReturnType->getName(); | ||
if ($originalReturnTypeName === 'void') { | ||
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 DebugClassLoader) { | ||
return $getComposerClassLoader($functionLoader->getClassLoader()); | ||
} | ||
}; | ||
|
||
$classLoader = null; | ||
while($classLoader === null && count($functions = spl_autoload_functions()) > 0) { | ||
$classLoader = $getComposerClassLoader(\array_shift($functions)); | ||
} | ||
|
||
if (null === $classLoader) { | ||
throw new \RuntimeException('Unable to find a class loader for "%s"'); | ||
} | ||
|
||
$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