Skip to content

Commit

Permalink
fix(coroutines): container modifier load method override fix for gene…
Browse files Browse the repository at this point in the history
…rated production service container
  • Loading branch information
Rastusik committed Feb 6, 2023
1 parent 62afa05 commit 522e5ba
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/Bridge/Symfony/Container/ContainerModifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace K911\Swoole\Bridge\Symfony\Container;

use Symfony\Component\DependencyInjection\Container;
use ZEngine\Reflection\ReflectionClass;

final class ContainerModifier
Expand Down Expand Up @@ -73,6 +74,36 @@ private static function overrideCreateProxy(BlockingContainer $container, Reflec
}

private static function overrideLoad(BlockingContainer $container, ReflectionClass $reflContainer): void
{
$loadRefl = $reflContainer->getMethod('load');

if (Container::class == $loadRefl->getDeclaringClass()->getName()) {
self::overrideOriginalContainerLoad($container, $reflContainer);

return;
}

self::overrideGeneratedLoad($container, $reflContainer);
}

private static function overrideOriginalContainerLoad(BlockingContainer $container, ReflectionClass $reflContainer): void
{
$loadRefl = $reflContainer->getMethod('load');
$reflContainer->addMethod('loadOriginal', $loadRefl->getClosure($container));
$loadRefl->redefine(function (string $file) {
$lock = self::$locking->acquire($file);

try {
$return = $this->loadOriginal($file);
} finally {
$lock->release();
}

return $return;
});
}

private static function overrideGeneratedLoad(BlockingContainer $container, ReflectionClass $reflContainer): void
{
$loadRefl = $reflContainer->getMethod('load');
$reflContainer->addMethod('loadOriginal', $loadRefl->getClosure($container));
Expand Down

0 comments on commit 522e5ba

Please sign in to comment.