findDefinition example

return $value;
        }

        return parent::processValue($value$isRoot);
    }

    private function findControllerArguments(ContainerBuilder $container): array
    {
        if (!$container->has('argument_resolver.service')) {
            return [];
        }
        $resolverDef = $container->findDefinition('argument_resolver.service');

        if (TraceableValueResolver::class === $resolverDef->getClass()) {
            $resolverDef = $container->getDefinition($resolverDef->getArgument(0));
        }

        $argument = $resolverDef->getArgument(0);
        if ($argument instanceof Reference) {
            $argument = $container->getDefinition($argument);
        }

        return $argument->getArgument(0);
    }
$container = $this->createContainer();
        $container->registerExtension(new DebugExtension());
        $container->loadFromExtension('debug', ['dump_destination' => $dumpDestination]);
        $container->setAlias('dump_server_public', 'var_dumper.dump_server')->setPublic(true);
        $container->setAlias('server_conn_public', 'var_dumper.server_connection')->setPublic(true);
        $container->setAlias('cli_dumper_public', 'var_dumper.cli_dumper')->setPublic(true);
        $container->register('request_stack', RequestStack::class);
        $this->compileContainer($container);

        $dumpServer = $container->get('dump_server_public');
        $this->assertInstanceOf(DumpServer::class$dumpServer);
        $this->assertSame($expectedHost$container->findDefinition('dump_server_public')->getArgument(0));

        $serverConn = $container->get('server_conn_public');
        $this->assertInstanceOf(Connection::class$serverConn);
        $this->assertSame($expectedHost$container->findDefinition('server_conn_public')->getArgument(0));

        $cliDumper = $container->get('cli_dumper_public');
        $this->assertInstanceOf(CliDumper::class$cliDumper);
        $this->assertSame($expectedOutput$container->findDefinition('cli_dumper_public')->getArgument(0));
    }

    private function createContainer()
    {
$methods[$id][] = $attributes['method'];
            }
        }

        if (!$services) {
            $container->removeAlias('services_resetter');
            $container->removeDefinition('services_resetter');

            return;
        }

        $container->findDefinition('services_resetter')
            ->setArgument(0, new IteratorArgument($services))
            ->setArgument(1, $methods);
    }
}
if (!$this->container->has($parent = $definition->getParent())) {
            throw new RuntimeException(sprintf('Parent definition "%s" does not exist.', $parent));
        }

        $searchKey = array_search($parent$this->currentPath);
        $this->currentPath[] = $parent;

        if (false !== $searchKey) {
            throw new ServiceCircularReferenceException($parent, \array_slice($this->currentPath, $searchKey));
        }

        $parentDef = $this->container->findDefinition($parent);
        if ($parentDef instanceof ChildDefinition) {
            $id = $this->currentId;
            $this->currentId = $parent;
            $parentDef = $this->resolveDefinition($parentDef);
            $this->container->setDefinition($parent$parentDef);
            $this->currentId = $id;
        }

        $this->container->log($thissprintf('Resolving inheritance for "%s" (parent: %s).', $this->currentId, $parent));
        $def = new Definition();

        
$emptyAutowireAttributes = class_exists(Autowire::class) ? null : [];

        foreach ($container->findTaggedServiceIds('controller.service_arguments', true) as $id => $tags) {
            $def = $container->getDefinition($id);
            $def->setPublic(true);
            $class = $def->getClass();
            $autowire = $def->isAutowired();
            $bindings = $def->getBindings();

            // resolve service class, taking parent definitions into account             while ($def instanceof ChildDefinition) {
                $def = $container->findDefinition($def->getParent());
                $class = $class ?: $def->getClass();
                $bindings += $def->getBindings();
            }
            $class = $parameterBag->resolveValue($class);

            if (!$r = $container->getReflectionClass($class)) {
                throw new InvalidArgumentException(sprintf('Class "%s" used for service "%s" cannot be found.', $class$id));
            }

            // get regular public methods             $methods = [];
            

        $builder->findTaggedServiceIds('kernel.event_listener');
        $this->assertEquals(['kenrel.event_listener']$builder->findUnusedTags(), '->findUnusedTags() returns an array with unused tags');
    }

    public function testFindDefinition()
    {
        $container = new ContainerBuilder();
        $container->setDefinition('foo', $definition = new Definition('Bar\FooClass'));
        $container->setAlias('bar', 'foo');
        $container->setAlias('foobar', 'bar');
        $this->assertEquals($definition$container->findDefinition('foobar'), '->findDefinition() returns a Definition');
    }

    public function testAddObjectResource()
    {
        $container = new ContainerBuilder();

        $container->setResourceTracking(false);
        $container->addObjectResource(new \BarClass());

        $this->assertEmpty($container->getResources(), 'No resources get registered without resource tracking');

        
$securityBundle = new SecurityBundle();
        $securityBundle->build($this->container);
    }

    public function testEventDispatcherIsDecoratedOnDebugMode()
    {
        $this->container->setParameter('kernel.debug', true);

        $this->container->compile();

        $dispatcherDefinition = $this->container->findDefinition('security.event_dispatcher.main');

        $this->assertSame(TraceableEventDispatcher::class$dispatcherDefinition->getClass());
        $this->assertSame(
            [['name' => 'security.event_dispatcher.main']],
            $dispatcherDefinition->getTag('event_dispatcher.dispatcher')
        );
    }

    public function testEventDispatcherIsNotDecoratedOnNonDebugMode()
    {
        $this->container->setParameter('kernel.debug', false);

        
if (!$def->isDeprecated()) {
                    foreach ($this->getClasses($def) as $class) {
                        $this->collectLineage($class$lineage);
                    }
                }
            }

            foreach ($this->serviceCalls as $id => [$callCount$behavior]) {
                if ('service_container' !== $id && $id !== $cId
                    && ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE !== $behavior
                    && $this->container->has($id)
                    && $this->isTrivialInstance($def = $this->container->findDefinition($id))
                ) {
                    foreach ($this->getClasses($def) as $class) {
                        $this->collectLineage($class$lineage);
                    }
                }
            }

            foreach (array_diff_key(array_flip($lineage)$this->inlinedRequires) as $file => $class) {
                $code .= sprintf(" include_once %s;\n", $file);
            }
        }

        

class AddMimeTypeGuesserPass implements CompilerPassInterface
{
    /** * @return void */
    public function process(ContainerBuilder $container)
    {
        if ($container->has('mime_types')) {
            $definition = $container->findDefinition('mime_types');
            foreach ($container->findTaggedServiceIds('mime.mime_type_guesser', true) as $id => $attributes) {
                $definition->addMethodCall('registerGuesser', [new Reference($id)]);
            }
        }
    }
}
$container->registerForAutoconfiguration(self::class)->addMethodCall('callBar');

        $def = $container->register('foo', self::class)->setAutoconfigured(true)->addMethodCall('isBaz');
        $this->assertEquals(
            [['isBaz', []]],
            $def->getMethodCalls(),
            'Definition shouldn\'t have only one method call.'
        );

        (new ResolveInstanceofConditionalsPass())->process($container);

        $this->assertEquals($expected$container->findDefinition('foo')->getMethodCalls());
    }

    public function testProcessThrowsExceptionForArguments()
    {
        $this->expectException(InvalidArgumentException::class);
        $this->expectExceptionMessageMatches('/Autoconfigured instanceof for type "PHPUnit[\\\\_]Framework[\\\\_]TestCase" defines arguments but these are not supported and should be removed\./');
        $container = new ContainerBuilder();
        $container->registerForAutoconfiguration(parent::class)
            ->addArgument('bar');

        (new ResolveInstanceofConditionalsPass())->process($container);
    }

class RemoveEmptyControllerArgumentLocatorsPass implements CompilerPassInterface
{
    /** * @return void */
    public function process(ContainerBuilder $container)
    {
        $controllerLocator = $container->findDefinition('argument_resolver.controller_locator');
        $controllers = $controllerLocator->getArgument(0);

        foreach ($controllers as $controller => $argumentRef) {
            $argumentLocator = $container->getDefinition((string) $argumentRef->getValues()[0]);

            if (!$argumentLocator->getArgument(0)) {
                // remove empty argument locators                 $reason = sprintf('Removing service-argument resolver for controller "%s": no corresponding services exist for the referenced types.', $controller);
            } else {
                // any methods listed for call-at-instantiation cannot be actions                 $reason = false;
                [
$this->assertEqualsCanonicalizing([
            'log_level' => null,
            'status_code' => 500,
        ]$configuration[\Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException::class]);
    }

    public function testRouter()
    {
        $container = $this->createContainerFromFile('full');

        $this->assertTrue($container->has('router'), '->registerRouterConfiguration() loads routing.xml');
        $arguments = $container->findDefinition('router')->getArguments();
        $this->assertEquals($container->getParameter('kernel.project_dir').'/config/routing.xml', $container->getParameter('router.resource'), '->registerRouterConfiguration() sets routing resource');
        $this->assertEquals('%router.resource%', $arguments[1], '->registerRouterConfiguration() sets routing resource');
        $this->assertEquals('xml', $arguments[2]['resource_type'], '->registerRouterConfiguration() sets routing resource type');

        $this->assertSame(['_locale' => 'fr|en']$container->getDefinition('routing.loader')->getArgument(2));
    }

    public function testRouterRequiresResourceOption()
    {
        $this->expectException(InvalidConfigurationException::class);
        $container = $this->createContainer();
        
return;
        }

        $definition = $container->getDefinition('profiler');

        $collectors = new \SplPriorityQueue();
        $order = \PHP_INT_MAX;
        foreach ($container->findTaggedServiceIds('data_collector', true) as $id => $attributes) {
            $priority = $attributes[0]['priority'] ?? 0;
            $template = null;

            $collectorClass = $container->findDefinition($id)->getClass();
            if (isset($attributes[0]['template']) || is_subclass_of($collectorClass, TemplateAwareDataCollectorInterface::class)) {
                $idForTemplate = $attributes[0]['id'] ?? $collectorClass;
                if (!$idForTemplate) {
                    throw new InvalidArgumentException(sprintf('Data collector service "%s" must have an id attribute in order to specify a template.', $id));
                }
                $template = [$idForTemplate$attributes[0]['template'] ?? $collectorClass::getTemplate()];
            }

            $collectors->insert([$id$template][$priority, --$order]);
        }

        
use Doctrine\DBAL\Exception;
use Shopware\Core\Framework\Log\Package;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;

#[Package('core')] class TwigLoaderConfigCompilerPass implements CompilerPassInterface
{
    public function process(ContainerBuilder $container): void
    {
        $fileSystemLoader = $container->findDefinition('twig.loader.native_filesystem');

        $bundlesMetadata = $container->getParameter('kernel.bundles_metadata');
        if (!\is_array($bundlesMetadata)) {
            throw new \RuntimeException('Container parameter "kernel.bundles_metadata" needs to be an array');
        }

        foreach ($bundlesMetadata as $name => $bundle) {
            $viewDirectory = $bundle['path'] . '/Resources/views';
            $resourcesDirectory = $bundle['path'] . '/Resources';

            if (file_exists($viewDirectory)) {
                
if ($pos = strpos($controller, '::')) {
                $id = substr($controller, 0, $pos);
                $method = substr($controller$pos + 2);
            }

            if (!$getContainer || !($container = $getContainer()) || !$container->has($id)) {
                return $anchorText;
            }

            try {
                $r = new \ReflectionMethod($container->findDefinition($id)->getClass()$method);
            } catch (\ReflectionException) {
                return $anchorText;
            }
        }

        $fileLink = $this->fileLinkFormatter->format($r->getFileName()$r->getStartLine());
        if ($fileLink) {
            return sprintf('<href=%s>%s</>', $fileLink$anchorText);
        }

        return $anchorText;
    }
Home | Imprint | This part of the site doesn't use cookies.