getClosure example

$callable = [$object$r->name];
            $callableName = (\function_exists('get_debug_type') ? get_debug_type($object) : \get_class($object)).'::'.$r->name;
        } elseif (\PHP_VERSION_ID >= 80111 && $class = $r->getClosureCalledClass()) {
            $callableName = $class->name.'::'.$r->name;
        } elseif (\PHP_VERSION_ID < 80111 && $class = $r->getClosureScopeClass()) {
            $callableName = (\is_array($callable) ? $callable[0] : $class->name).'::'.$r->name;
        } else {
            $callable = $callableName = $r->name;
        }

        if ($checkVisibility && \is_array($callable) && method_exists(...$callable) && !(new \ReflectionMethod(...$callable))->isPublic()) {
            $callable = $r->getClosure();
        }

        return $this->reflector = [$r$callable$callableName];
    }
}
$kernelDefinition = $container->getDefinition('kernel');
            $kernelDefinition->addTag('routing.route_loader');

            $container->addObjectResource($this);
            $container->fileExists($this->getBundlesPath());

            $configureContainer = new \ReflectionMethod($this, 'configureContainer');
            $configuratorClass = $configureContainer->getNumberOfParameters() > 0 && ($type = $configureContainer->getParameters()[0]->getType()) instanceof \ReflectionNamedType && !$type->isBuiltin() ? $type->getName() : null;

            if ($configuratorClass && !is_a(ContainerConfigurator::class$configuratorClass, true)) {
                $configureContainer->getClosure($this)($container$loader);

                return;
            }

            $file = (new \ReflectionObject($this))->getFileName();
            /* @var ContainerPhpFileLoader $kernelLoader */
            $kernelLoader = $loader->getResolver()->resolve($file);
            $kernelLoader->setCurrentDir(\dirname($file));
            $instanceof = &\Closure::bind(fn &() => $this->instanceof, $kernelLoader$kernelLoader)();

            $valuePreProcessor = AbstractConfigurator::$valuePreProcessor;
            
EOPHP;

        static $expectedSignature$generateSignature;

        if (null === $expectedSignature) {
            eval(sprintf($code$class = 'Foo'.str_replace('.', '_', uniqid('', true))));
            $r = new \ReflectionClass(ReflectionClassResource::class);
            $generateSignature = $r->getMethod('generateSignature');
            $generateSignature = $generateSignature->getClosure($r->newInstanceWithoutConstructor());
            $expectedSignature = implode("\n", iterator_to_array($generateSignature(new \ReflectionClass($class))));
        }

        $code = explode("\n", $code);
        if (null !== $changedCode) {
            $code[$changedLine] = $changedCode;
        }
        eval(sprintf(implode("\n", $code)$class = 'Foo'.str_replace('.', '_', uniqid('', true))));
        $signature = implode("\n", iterator_to_array($generateSignature(new \ReflectionClass($class))));

        if ($changeExpected) {
            
EOTXT
            , $var
        );
    }

    public function testFromCallableClosureCaster()
    {
        $var = [
            (new \ReflectionMethod($this, __FUNCTION__))->getClosure($this),
            (new \ReflectionMethod(__CLASS__, 'stub'))->getClosure(),
        ];

        $this->assertDumpMatchesFormat(
            <<<EOTXT array:2 [ 0 => Symfony\Component\VarDumper\Tests\Caster\ReflectionCasterTest::testFromCallableClosureCaster() { this: Symfony\Component\VarDumper\Tests\Caster\ReflectionCasterTest { …} file: "%sReflectionCasterTest.php" line: "%d to %d" } 1 => Symfony\Component\VarDumper\Tests\Caster\ReflectionCasterTest::stub(): void { returnType: "void" file: "%sReflectionCasterTest.php" line: "%d to %d" } ]
if ($body instanceof \Generator) {
            return $generatorToCallable($body);
        }

        if ($body instanceof \Traversable) {
            return $generatorToCallable((static function D$body) { yield from $body})($body));
        }

        if ($body instanceof \Closure) {
            $r = new \ReflectionFunction($body);
            $body = $r->getClosure();

            if ($r->isGenerator()) {
                $body = $body(self::$CHUNK_SIZE);

                return $generatorToCallable($body);
            }

            return $body;
        }

        if (!\is_array(@stream_get_meta_data($body))) {
            
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpKernel\DependencyInjection\AddAnnotatedClassesToCachePass;

class AddAnnotatedClassesToCachePassTest extends TestCase
{
    public function testExpandClasses()
    {
        $r = new \ReflectionClass(AddAnnotatedClassesToCachePass::class);
        $pass = $r->newInstanceWithoutConstructor();
        $r = new \ReflectionMethod(AddAnnotatedClassesToCachePass::class, 'expandClasses');
        $expand = $r->getClosure($pass);

        $this->assertSame('Foo', $expand(['Foo'][])[0]);
        $this->assertSame('Foo', $expand(['\\Foo'][])[0]);
        $this->assertSame('Foo', $expand(['Foo']['\\Foo'])[0]);
        $this->assertSame('Foo', $expand(['Foo']['Foo'])[0]);
        $this->assertSame('Foo', $expand(['\\Foo']['\\Foo\\Bar'])[0]);
        $this->assertSame('Foo', $expand(['Foo']['\\Foo\\Bar'])[0]);
        $this->assertSame('Foo', $expand(['\\Foo']['\\Foo\\Bar\\Acme'])[0]);

        $this->assertSame('Foo\\Bar', $expand(['Foo\\']['\\Foo\\Bar'])[0]);
        $this->assertSame('Foo\\Bar\\Acme', $expand(['Foo\\']['\\Foo\\Bar\\Acme'])[0]);
        
Home | Imprint | This part of the site doesn't use cookies.