diff --git a/.gitignore b/.gitignore index ca5eb70c..e83e64e5 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,5 @@ mutagen.yml.lock tests/Fixtures/Symfony/app/data/* docker-compose.override.yml Dockerfile.override +ext +!ext/.gitignore diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 02556b23..c02d9564 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -9,6 +9,7 @@ 'tests/Unit/Server/Php8', 'vendor', 'hack', + 'ext', ]); $config = new PhpCsFixer\Config(); diff --git a/src/Bridge/Symfony/Bundle/DependencyInjection/CompilerPass/StatefulServices/NonSharedSvcPoolConfigurator.php b/src/Bridge/Symfony/Bundle/DependencyInjection/CompilerPass/StatefulServices/NonSharedSvcPoolConfigurator.php index c1f22f00..070ed814 100644 --- a/src/Bridge/Symfony/Bundle/DependencyInjection/CompilerPass/StatefulServices/NonSharedSvcPoolConfigurator.php +++ b/src/Bridge/Symfony/Bundle/DependencyInjection/CompilerPass/StatefulServices/NonSharedSvcPoolConfigurator.php @@ -13,6 +13,9 @@ public function __construct(private ServicePoolContainer $container) { } + /** + * @param BaseServicePool $servicePool + */ public function configure(BaseServicePool $servicePool): void { $this->container->addPool($servicePool); diff --git a/src/Bridge/Symfony/Bundle/Resources/config/services.yaml b/src/Bridge/Symfony/Bundle/Resources/config/services.yaml index d5ffec4d..6bf687e5 100644 --- a/src/Bridge/Symfony/Bundle/Resources/config/services.yaml +++ b/src/Bridge/Symfony/Bundle/Resources/config/services.yaml @@ -231,7 +231,7 @@ services: K911\Swoole\Bridge\Symfony\Container\Proxy\Instantiator: arguments: - $proxyFactory: '@swoole_bundle.service_proxy_factory' + $proxyGenerator: '@K911\Swoole\Bridge\Symfony\Container\Proxy\Generator' K911\Swoole\Bridge\Symfony\Container\Proxy\UnmanagedFactoryInstantiator: arguments: @@ -244,8 +244,7 @@ services: swoole_bundle.filesystem: class: 'Symfony\Component\Filesystem\Filesystem' - swoole_bundle.service_proxy_factory: - class: 'ProxyManager\Factory\LazyLoadingValueHolderFactory' + K911\Swoole\Bridge\Symfony\Container\Proxy\Generator: arguments: $configuration: '@swoole_bundle.service_proxy_configuration' diff --git a/src/Bridge/Symfony/Container/Proxy/ContextualProxy.php b/src/Bridge/Symfony/Container/Proxy/ContextualProxy.php new file mode 100644 index 00000000..c887a82c --- /dev/null +++ b/src/Bridge/Symfony/Container/Proxy/ContextualProxy.php @@ -0,0 +1,25 @@ + + */ + public function getServicePool(): ServicePool; + + /** + * @param ServicePool $servicePool + * + * @return ContextualProxy&RealObjectType + */ + public static function staticProxyConstructor(ServicePool $servicePool): object; +} diff --git a/src/Bridge/Symfony/Container/Proxy/Generation/ContextualAccessForwarderFactory.php b/src/Bridge/Symfony/Container/Proxy/Generation/ContextualAccessForwarderFactory.php new file mode 100644 index 00000000..f2357f88 --- /dev/null +++ b/src/Bridge/Symfony/Container/Proxy/Generation/ContextualAccessForwarderFactory.php @@ -0,0 +1,53 @@ +generator = new ContextualAccessForwarderGenerator(new MethodForwarderBuilder()); + } + + /** + * @template RealObjectType of object + * + * @param ServicePool $servicePool + * @param class-string $serviceClass + * + * @throws InvalidSignatureException + * @throws MissingSignatureException + * @throws \OutOfBoundsException + * + * @return ContextualProxy&RealObjectType + */ + public function createProxy(ServicePool $servicePool, string $serviceClass) + { + /** @var class-string&RealObjectType> $proxyClassName */ + $proxyClassName = $this->generateProxy($serviceClass); + + return $proxyClassName::staticProxyConstructor($servicePool); + } + + protected function getGenerator(): ProxyGeneratorInterface + { + return $this->generator; + } +} diff --git a/src/Bridge/Symfony/Container/Proxy/Generation/ContextualAccessForwarderGenerator.php b/src/Bridge/Symfony/Container/Proxy/Generation/ContextualAccessForwarderGenerator.php new file mode 100644 index 00000000..522c609f --- /dev/null +++ b/src/Bridge/Symfony/Container/Proxy/Generation/ContextualAccessForwarderGenerator.php @@ -0,0 +1,80 @@ + $originalClass + * + * @throws \InvalidArgumentException + * @throws InvalidProxiedClassException + */ + public function generate(\ReflectionClass $originalClass, ClassGenerator $classGenerator): void + { + CanProxyAssertion::assertClassCanBeProxied($originalClass); + + $interfaces = [ + ContextualProxy::class, + ]; + + if ($originalClass->isInterface()) { + $interfaces[] = $originalClass->getName(); + } + + if (!$originalClass->isInterface()) { + $classGenerator->setExtendedClass($originalClass->getName()); + } + + $publicProperties = new PublicPropertiesMap(Properties::fromReflectionClass($originalClass)); + $classGenerator->setImplementedInterfaces($interfaces); + $classGenerator->addPropertyFromGenerator($servicePoolProperty = new ServicePoolProperty()); + $classGenerator->addPropertyFromGenerator($publicProperties); + $closure = static function (MethodGenerator $generatedMethod) use ($originalClass, $classGenerator): void { + ClassGeneratorUtils::addMethodIfNotFinal($originalClass, $classGenerator, $generatedMethod); + }; + + array_map( + $closure, + array_merge( + array_map( + $this->forwarderBuilder->buildMethodInterceptor($servicePoolProperty), + ProxiedMethodsFilter::getProxiedMethods($originalClass) + ), + [ + new StaticProxyConstructor($servicePoolProperty, Properties::fromReflectionClass($originalClass)), + new GetWrappedServicePoolValue($servicePoolProperty), + new MagicGet($originalClass, $servicePoolProperty, $publicProperties), + new MagicSet($originalClass, $servicePoolProperty, $publicProperties), + ] + ) + ); + } +} diff --git a/src/Bridge/Symfony/Container/Proxy/Generation/MethodForwarderBuilder.php b/src/Bridge/Symfony/Container/Proxy/Generation/MethodForwarderBuilder.php new file mode 100644 index 00000000..0eac80f2 --- /dev/null +++ b/src/Bridge/Symfony/Container/Proxy/Generation/MethodForwarderBuilder.php @@ -0,0 +1,22 @@ +getDeclaringClass()->getName(), $method->getName()), + $servicePoolHolderProperty + ); + }; + } +} diff --git a/src/Bridge/Symfony/Container/Proxy/Generation/MethodGenerator/ForwardedMethod.php b/src/Bridge/Symfony/Container/Proxy/Generation/MethodGenerator/ForwardedMethod.php new file mode 100644 index 00000000..e9999ddb --- /dev/null +++ b/src/Bridge/Symfony/Container/Proxy/Generation/MethodGenerator/ForwardedMethod.php @@ -0,0 +1,40 @@ +getParameters() as $parameter) { + $forwardedParams[] = ($parameter->isVariadic() ? '...' : '').'$'.$parameter->getName(); + } + + $method->setBody(MethodForwarderGenerator::createForwardedMethodBody( + $originalMethod->getName().'('.implode(', ', $forwardedParams).')', + $servicePoolHolderProperty, + $originalMethod + )); + + return $method; + } +} diff --git a/src/Bridge/Symfony/Container/Proxy/Generation/MethodGenerator/GetWrappedServicePoolValue.php b/src/Bridge/Symfony/Container/Proxy/Generation/MethodGenerator/GetWrappedServicePoolValue.php new file mode 100644 index 00000000..af70d167 --- /dev/null +++ b/src/Bridge/Symfony/Container/Proxy/Generation/MethodGenerator/GetWrappedServicePoolValue.php @@ -0,0 +1,29 @@ +setBody('return $this->'.$servicePoolHolderProperty->getName().';'); + $this->setReturnType(ServicePool::class); + } +} diff --git a/src/Bridge/Symfony/Container/Proxy/Generation/MethodGenerator/MagicGet.php b/src/Bridge/Symfony/Container/Proxy/Generation/MethodGenerator/MagicGet.php new file mode 100644 index 00000000..edd14ba9 --- /dev/null +++ b/src/Bridge/Symfony/Container/Proxy/Generation/MethodGenerator/MagicGet.php @@ -0,0 +1,60 @@ + $originalClass + * + * @throws \InvalidArgumentException + */ + public function __construct( + \ReflectionClass $originalClass, + PropertyGenerator $servicePoolProperty, + PublicPropertiesMap $publicProperties + ) { + parent::__construct($originalClass, '__get', [new ParameterGenerator('name')]); + + $hasParent = $originalClass->hasMethod('__get'); + + $servicePool = $servicePoolProperty->getName(); + $callParent = 'if (isset(self::$'.$publicProperties->getName()."[\$name])) {\n" + .' return $this->'.$servicePool.'->get()->$name;' + ."\n}\n\n"; + + if ($hasParent) { + $this->setBody( + $callParent.'return $this->'.$servicePool.'->get()->__get($name);' + ); + + return; + } + + $this->setBody( + $callParent.PublicScopeSimulator::getPublicAccessSimulationCode( + PublicScopeSimulator::OPERATION_GET, + 'name', + null, + new PropertyGenerator($servicePool.'->get()'), + null, + $originalClass + ) + ); + } +} diff --git a/src/Bridge/Symfony/Container/Proxy/Generation/MethodGenerator/MagicSet.php b/src/Bridge/Symfony/Container/Proxy/Generation/MethodGenerator/MagicSet.php new file mode 100644 index 00000000..94d39e39 --- /dev/null +++ b/src/Bridge/Symfony/Container/Proxy/Generation/MethodGenerator/MagicSet.php @@ -0,0 +1,61 @@ + $originalClass + * + * @throws \InvalidArgumentException + */ + public function __construct( + \ReflectionClass $originalClass, + PropertyGenerator $servicePoolProperty, + PublicPropertiesMap $publicProperties + ) { + parent::__construct( + $originalClass, + '__set', + [new ParameterGenerator('name'), new ParameterGenerator('value')] + ); + + $hasParent = $originalClass->hasMethod('__set'); + $servicePool = $servicePoolProperty->getName(); + $callParent = ''; + + if (!$publicProperties->isEmpty()) { + $callParent = 'if (isset(self::$'.$publicProperties->getName()."[\$name])) {\n" + .' return ($this->'.$servicePool.'->get()->$name = $value);' + ."\n}\n\n"; + } + + $callParent .= $hasParent + ? 'return $this->'.$servicePool.'->get()->__set($name, $value);' + : PublicScopeSimulator::getPublicAccessSimulationCode( + PublicScopeSimulator::OPERATION_SET, + 'name', + 'value', + new PropertyGenerator($servicePool.'->get()'), + null, + $originalClass + ); + + $this->setBody($callParent); + } +} diff --git a/src/Bridge/Symfony/Container/Proxy/Generation/MethodGenerator/StaticProxyConstructor.php b/src/Bridge/Symfony/Container/Proxy/Generation/MethodGenerator/StaticProxyConstructor.php new file mode 100644 index 00000000..cfb13a1a --- /dev/null +++ b/src/Bridge/Symfony/Container/Proxy/Generation/MethodGenerator/StaticProxyConstructor.php @@ -0,0 +1,46 @@ +omitDefaultValue(); + $this->setParameter($servicePoolParameter); + + $this->setDocBlock( + sprintf("Constructor for lazy initialization\n\n@param %s \$servicePool", ServicePool::class) + ); + $this->setBody( + 'static $reflection;'."\n\n" + .'$reflection = $reflection ?? new \ReflectionClass(__CLASS__);'."\n" + .'$instance = $reflection->newInstanceWithoutConstructor();'."\n\n" + .UnsetPropertiesGenerator::generateSnippet($properties, 'instance') + .'$instance->'.$servicePoolProperty->getName().' = $servicePool;'."\n\n" + .'return $instance;' + ); + $this->setReturnType('object'); + } +} diff --git a/src/Bridge/Symfony/Container/Proxy/Generation/MethodGenerator/Util/MethodForwarderGenerator.php b/src/Bridge/Symfony/Container/Proxy/Generation/MethodGenerator/Util/MethodForwarderGenerator.php new file mode 100644 index 00000000..2d2bb26d --- /dev/null +++ b/src/Bridge/Symfony/Container/Proxy/Generation/MethodGenerator/Util/MethodForwarderGenerator.php @@ -0,0 +1,39 @@ +{{$servicePoolHolderName}}->get(); + $returnValue = $wrapped->{{$forwardedMethodCall}}; + + {{$returnExpression}} + PHP; + + /** + * @param string $forwardedMethodCall the call to the proxied method + */ + public static function createForwardedMethodBody( + string $forwardedMethodCall, + PropertyGenerator $servicePoolHolder, + ?\ReflectionMethod $originalMethod + ): string { + $servicePoolHolderName = $servicePoolHolder->getName(); + $replacements = [ + '{{$servicePoolHolderName}}' => $servicePoolHolderName, + '{{$forwardedMethodCall}}' => $forwardedMethodCall, + '{{$returnExpression}}' => ProxiedMethodReturnExpression::generate('$returnValue', $originalMethod), + ]; + + return str_replace(array_keys($replacements), $replacements, self::TEMPLATE); + } +} diff --git a/src/Bridge/Symfony/Container/Proxy/Generation/PropertyGenerator/ServicePoolProperty.php b/src/Bridge/Symfony/Container/Proxy/Generation/PropertyGenerator/ServicePoolProperty.php new file mode 100644 index 00000000..737b4af1 --- /dev/null +++ b/src/Bridge/Symfony/Container/Proxy/Generation/PropertyGenerator/ServicePoolProperty.php @@ -0,0 +1,56 @@ +> + */ + private static ?\ReflectionClass $servicePoolReflection = null; + + /** + * Constructor. + * + * @throws InvalidArgumentException + */ + public function __construct() + { + parent::__construct(IdentifierSuffixer::getIdentifier('servicePool')); + + $docBlock = new DocBlockGenerator(); + + $docBlock->setWordWrap(false); + $docBlock->setLongDescription('@var \\'.self::getServicePoolReflection()->getName().' ServicePool holder'); + $this->setDocBlock($docBlock); + $this->setVisibility(self::VISIBILITY_PRIVATE); + $this->setType(TypeGenerator::fromTypeString(ServicePool::class)); + $this->omitDefaultValue(); + } + + /** + * @return \ReflectionClass> + */ + private static function getServicePoolReflection(): \ReflectionClass + { + if (null === self::$servicePoolReflection) { + /** @var \ReflectionClass> $reflection */ + $reflection = new \ReflectionClass(ServicePool::class); + self::$servicePoolReflection = $reflection; + } + + return self::$servicePoolReflection; + } +} diff --git a/src/Bridge/Symfony/Container/Proxy/Generator.php b/src/Bridge/Symfony/Container/Proxy/Generator.php new file mode 100644 index 00000000..a01ba8d9 --- /dev/null +++ b/src/Bridge/Symfony/Container/Proxy/Generator.php @@ -0,0 +1,77 @@ +&object>> + */ + private array $checkedClasses = []; + + public function __construct(Configuration $configuration) + { + parent::__construct($configuration); + } + + /** + * this override method activates the proxy manage class autoloader, which is kind of pain in the ass + * to activate in Symfony, since Symfony relies directly on Composer and it would be needed to register this + * autoloader with Composer autoloader initialization. + * + * @template RealObjectType of object + * + * @param class-string $className + * @param array $proxyOptions @codingStandardsIgnoreLine + * + * @return class-string&RealObjectType> + * + * @SuppressWarnings(PHPMD.StaticAccess) + */ + protected function generateProxy(string $className, array $proxyOptions = []): string + { + if (\array_key_exists($className, $this->checkedClasses)) { + /** @var class-string&RealObjectType> $generatedClassName */ + $generatedClassName = $this->checkedClasses[$className]; + \assert(is_a($generatedClassName, $className, true)); + + return $generatedClassName; + } + + $proxyParameters = [ + 'className' => $className, + 'factory' => self::class, + 'proxyManagerVersion' => Version::getVersion(), + 'proxyOptions' => $proxyOptions, + ]; + /** @var class-string&RealObjectType> $proxyClassName */ + $proxyClassName = $this + ->configuration + ->getClassNameInflector() + ->getProxyClassName($className, $proxyParameters) + ; + + if (class_exists($proxyClassName)) { + return $this->checkedClasses[$className] = $proxyClassName; + } + + $autoloader = $this->configuration->getProxyAutoloader(); + + if ($autoloader($proxyClassName)) { + return $this->checkedClasses[$className] = $proxyClassName; + } + + /** @var class-string&RealObjectType> $proxyClassName */ + $proxyClassName = parent::generateProxy($className, $proxyOptions); + + return $this->checkedClasses[$className] = $proxyClassName; + } +} diff --git a/src/Bridge/Symfony/Container/Proxy/Instantiator.php b/src/Bridge/Symfony/Container/Proxy/Instantiator.php index acd001f4..2779f5d3 100644 --- a/src/Bridge/Symfony/Container/Proxy/Instantiator.php +++ b/src/Bridge/Symfony/Container/Proxy/Instantiator.php @@ -4,50 +4,27 @@ namespace K911\Swoole\Bridge\Symfony\Container\Proxy; -use Closure; use K911\Swoole\Bridge\Symfony\Container\ServicePool\ServicePool; -use ProxyManager\Factory\LazyLoadingValueHolderFactory; -use ProxyManager\Proxy\LazyLoadingInterface; -use ProxyManager\Proxy\ValueHolderInterface; -use ProxyManager\Proxy\VirtualProxyInterface; final class Instantiator { - public function __construct(private LazyLoadingValueHolderFactory $proxyFactory) + public function __construct(private Generator $proxyGenerator) { } /** * @template RealObjectType of object * + * @param ServicePool $servicePool * @param class-string $wrappedSvcClass * - * @return RealObjectType + * @return ContextualProxy&RealObjectType */ public function newInstance(ServicePool $servicePool, string $wrappedSvcClass): object { - /** - * @var Closure( - * RealObjectType|null=, - * ValueHolderInterface&VirtualProxyInterface&RealObjectType=, - * string=, - * array=, - * Closure|null= - * ):bool $initializer - */ - $initializer = function ( - &$wrappedObject, - LazyLoadingInterface $proxy, - $method, - array $parameters, - &$initializer - ) use ($servicePool) { - // $initializer = null; // do not disable initialization - $wrappedObject = $servicePool->get(); // fill your object with values here - - return true; // confirm that initialization occurred correctly - }; - - return $this->proxyFactory->createProxy($wrappedSvcClass, $initializer); + return $this->proxyGenerator->createProxy( + $servicePool, + $wrappedSvcClass + ); } } diff --git a/src/Bridge/Symfony/Container/ServicePool/BaseServicePool.php b/src/Bridge/Symfony/Container/ServicePool/BaseServicePool.php index a9d3fe13..c8d8e138 100644 --- a/src/Bridge/Symfony/Container/ServicePool/BaseServicePool.php +++ b/src/Bridge/Symfony/Container/ServicePool/BaseServicePool.php @@ -9,6 +9,11 @@ use K911\Swoole\Component\Locking\Lock; use K911\Swoole\Component\Locking\Locking; +/** + * @template T of object + * + * @template-implements ServicePool + */ abstract class BaseServicePool implements ServicePool { private ?Lock $lock = null; @@ -16,12 +21,12 @@ abstract class BaseServicePool implements ServicePool private int $assignedCount = 0; /** - * @var array + * @var array */ private array $freePool = []; /** - * @var array + * @var array */ private array $assignedPool = []; @@ -34,6 +39,9 @@ public function __construct( ) { } + /** + * @return T + */ public function get(): object { $cId = $this->getCoroutineId(); @@ -82,6 +90,9 @@ public function releaseFromCoroutine(int $cId): void $this->unlockPool(); } + /** + * @return T + */ abstract protected function newServiceInstance(): object; private function getCoroutineId(): int diff --git a/src/Bridge/Symfony/Container/ServicePool/DiServicePool.php b/src/Bridge/Symfony/Container/ServicePool/DiServicePool.php index 61e720cd..0900d2c0 100644 --- a/src/Bridge/Symfony/Container/ServicePool/DiServicePool.php +++ b/src/Bridge/Symfony/Container/ServicePool/DiServicePool.php @@ -9,6 +9,11 @@ use K911\Swoole\Component\Locking\Locking; use Symfony\Component\DependencyInjection\Container; +/** + * @template T of object + * + * @template-extends BaseServicePool + */ final class DiServicePool extends BaseServicePool { public function __construct( @@ -22,8 +27,18 @@ public function __construct( parent::__construct($wrappedServiceId, $locking, $instancesLimit, $resetter, $stabilityChecker); } + /** + * @return T + */ protected function newServiceInstance(): object { - return $this->container->get($this->wrappedServiceId); + /** @var null|T $instance */ + $instance = $this->container->get($this->wrappedServiceId); + + if (null === $instance) { + throw new \RuntimeException(\sprintf('Service "%s" is not defined.', $this->wrappedServiceId)); + } + + return $instance; } } diff --git a/src/Bridge/Symfony/Container/ServicePool/ServicePool.php b/src/Bridge/Symfony/Container/ServicePool/ServicePool.php index efa678a7..74d9a512 100644 --- a/src/Bridge/Symfony/Container/ServicePool/ServicePool.php +++ b/src/Bridge/Symfony/Container/ServicePool/ServicePool.php @@ -4,8 +4,14 @@ namespace K911\Swoole\Bridge\Symfony\Container\ServicePool; +/** + * @template T of object + */ interface ServicePool { + /** + * @return T + */ public function get(): object; public function releaseFromCoroutine(int $cId): void; diff --git a/src/Bridge/Symfony/Container/ServicePool/ServicePoolContainer.php b/src/Bridge/Symfony/Container/ServicePool/ServicePoolContainer.php index 31b84e0c..88df7f7e 100644 --- a/src/Bridge/Symfony/Container/ServicePool/ServicePoolContainer.php +++ b/src/Bridge/Symfony/Container/ServicePool/ServicePoolContainer.php @@ -7,12 +7,15 @@ final class ServicePoolContainer { /** - * @param array $pools + * @param array> $pools */ public function __construct(private array $pools) { } + /** + * @param ServicePool $pool + */ public function addPool(ServicePool $pool): void { $this->pools[] = $pool; diff --git a/src/Bridge/Symfony/Container/ServicePool/UnmanagedFactoryServicePool.php b/src/Bridge/Symfony/Container/ServicePool/UnmanagedFactoryServicePool.php index 70c7ca9d..02a94f39 100644 --- a/src/Bridge/Symfony/Container/ServicePool/UnmanagedFactoryServicePool.php +++ b/src/Bridge/Symfony/Container/ServicePool/UnmanagedFactoryServicePool.php @@ -7,13 +7,21 @@ use K911\Swoole\Bridge\Symfony\Container\Resetter; use K911\Swoole\Component\Locking\Locking; +/** + * @template T of object + * + * @template-extends BaseServicePool + */ final class UnmanagedFactoryServicePool extends BaseServicePool { /** - * @var \Closure(): object + * @var \Closure(): T */ private \Closure $instantiator; + /** + * @param \Closure(): T $instantiator + */ public function __construct( \Closure $instantiator, string $lockingKey, @@ -26,6 +34,9 @@ public function __construct( parent::__construct($lockingKey, $locking, $instancesLimit, $resetter); } + /** + * @return T + */ protected function newServiceInstance(): object { $instantiator = $this->instantiator; diff --git a/tests/Fixtures/Symfony/TestBundle/Controller/SleepController.php b/tests/Fixtures/Symfony/TestBundle/Controller/SleepController.php index 26c32c51..faaf3ca7 100644 --- a/tests/Fixtures/Symfony/TestBundle/Controller/SleepController.php +++ b/tests/Fixtures/Symfony/TestBundle/Controller/SleepController.php @@ -5,6 +5,7 @@ namespace K911\Swoole\Tests\Fixtures\Symfony\TestBundle\Controller; use Doctrine\DBAL\Connection; +use K911\Swoole\Bridge\Symfony\Container\Proxy\ContextualProxy; use K911\Swoole\Bridge\Symfony\Container\ServicePool\BaseServicePool; use K911\Swoole\Bridge\Symfony\Container\ServicePool\ServicePoolContainer; use K911\Swoole\Tests\Fixtures\Symfony\TestBundle\Service\DefaultDummyService; @@ -14,7 +15,6 @@ use K911\Swoole\Tests\Fixtures\Symfony\TestBundle\Service\ShouldBeProxified2; use K911\Swoole\Tests\Fixtures\Symfony\TestBundle\Service\SleepingCounter; use K911\Swoole\Tests\Fixtures\Symfony\TestBundle\Service\SleepingCounterChecker; -use ProxyManager\Proxy\VirtualProxyInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; @@ -57,13 +57,11 @@ public function index() $check = $this->checker->wasChecked() ? 'true' : 'false'; $checks = $this->checker->getChecks(); /** @phpstan-ignore-next-line */ - $isProxified = $this->shouldBeProxified instanceof VirtualProxyInterface ? 'was' : 'WAS NOT'; + $isProxified = $this->shouldBeProxified instanceof ContextualProxy ? 'was' : 'WAS NOT'; /** @phpstan-ignore-next-line */ - $isProxified2 = $this->shouldBeProxified2 instanceof VirtualProxyInterface ? 'was' : 'WAS NOT'; + $isProxified2 = $this->shouldBeProxified2 instanceof ContextualProxy ? 'was' : 'WAS NOT'; /** @phpstan-ignore-next-line */ - $initializer = $this->shouldBeProxified2->getProxyInitializer(); - $rf = new \ReflectionFunction($initializer); - $servicePool = $rf->getStaticVariables()['servicePool']; + $servicePool = $this->shouldBeProxified2->getServicePool(); $rc = new \ReflectionClass(BaseServicePool::class); $limitProperty = $rc->getProperty('instancesLimit'); $limitProperty->setAccessible(true); @@ -71,7 +69,7 @@ public function index() $alwaysResetWorks = $this->shouldBeProxified->wasDummyReset(); $alwaysResetSafe = $this->shouldBeProxified->getSafeDummy(); /** @phpstan-ignore-next-line */ - $safeDummyIsProxy = $alwaysResetSafe instanceof VirtualProxyInterface ? 'IS' : 'is not'; + $safeDummyIsProxy = $alwaysResetSafe instanceof ContextualProxy ? 'IS' : 'is not'; $safeAlwaysResetWorks = $alwaysResetSafe->getWasReset(); $rc2 = new \ReflectionClass(DefaultDummyService::class); @@ -80,16 +78,12 @@ public function index() /** @phpstan-ignore-next-line */ $realDummyService = $this->dummyService->getDecorated(); $tmpRepo = $realDummyService->getTmpRepository(); - $isProxified3 = $tmpRepo instanceof VirtualProxyInterface ? 'was' : 'WAS NOT'; - $initializer2 = $tmpRepo->getProxyInitializer(); - $rf2 = new \ReflectionFunction($initializer2); - $connServicePool = $rf2->getStaticVariables()['servicePool']; + $isProxified3 = $tmpRepo instanceof ContextualProxy ? 'was' : 'WAS NOT'; + $connServicePool = $tmpRepo->getServicePool(); $limit2 = $limitProperty->getValue($connServicePool); /** @phpstan-ignore-next-line */ - $connInitializer = $this->connection->getProxyInitializer(); - $rf3 = new \ReflectionFunction($connInitializer); - $connServicePool = $rf3->getStaticVariables()['servicePool']; + $connServicePool = $this->connection->getServicePool(); $connlimit = $limitProperty->getValue($connServicePool); return new Response(