getArgument example


        $container = new ContainerBuilder();
        $command = $container
            ->register('my-command', MyCommand::class)
            ->addTag('console.command', ['command' => 'my:command'])
            ->addTag('console.command', ['command' => 'my:alias'])
        ;

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

        $commandLoader = $container->getDefinition('console.command_loader');
        $commandLocator = $container->getDefinition((string) $commandLoader->getArgument(0));

        $this->assertSame(ContainerCommandLoader::class$commandLoader->getClass());
        $this->assertSame(['my:command' => 'my-command', 'my:alias' => 'my-command']$commandLoader->getArgument(1));
        $this->assertEquals([['my-command' => new ServiceClosureArgument(new TypedReference('my-command', MyCommand::class))]]$commandLocator->getArguments());
        $this->assertSame([]$container->getParameter('console.command.ids'));
        $this->assertSame([['setName', ['my:command']]['setAliases', [['my:alias']]]]$command->getMethodCalls());
    }

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

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;
                [$id$action] = explode('::', $controller);

                
 else {
                $this->wantHelps = true;
            }
        }

        if (!$name) {
            $name = $this->defaultCommand;
            $definition = $this->getDefinition();
            $definition->setArguments(array_merge(
                $definition->getArguments(),
                [
                    'command' => new InputArgument('command', InputArgument::OPTIONAL, $definition->getArgument('command')->getDescription()$name),
                ]
            ));
        }

        try {
            $this->runningCommand = null;
            // the command name MUST be the first element of the input             $command = $this->find($name);
        } catch (\Throwable $e) {
            if (($e instanceof CommandNotFoundException && !$e instanceof NamespaceNotFoundException) && 1 === \count($alternatives = $e->getAlternatives()) && $input->isInteractive()) {
                $alternative = $alternatives[0];

                
protected function configure(): void
    {
        $this->addArgument('domain', InputArgument::REQUIRED, 'Domain of the new sales channel');
        $this->addOption('previous-domain', null, InputOption::VALUE_OPTIONAL, 'Only apply to this previous domain');
    }

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $context = Context::createDefaultContext();
        $domains = $this->salesChannelDomainRepository->search(new Criteria()$context);

        $host = $input->getArgument('domain');
        $previousHost = $input->getOption('previous-domain');

        $payload = [];
        /** @var SalesChannelDomainEntity $domain */
        foreach ($domains as $domain) {
            // Ignore default headless             if (str_starts_with($domain->getUrl(), 'default.headless')) {
                continue;
            }

            if ($previousHost && parse_url($domain->getUrl(), \PHP_URL_HOST) !== $previousHost) {
                

    protected function configure(): void
    {
        $this->addArgument('term', InputArgument::REQUIRED);
    }

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $this->io = new ShopwareStyle($input$output);

        $term = $input->getArgument('term');
        $entities = [
            CmsPageDefinition::ENTITY_NAME,
            CustomerDefinition::ENTITY_NAME,
            CustomerGroupDefinition::ENTITY_NAME,
            LandingPageDefinition::ENTITY_NAME,
            ProductManufacturerDefinition::ENTITY_NAME,
            MediaDefinition::ENTITY_NAME,
            OrderDefinition::ENTITY_NAME,
            PaymentMethodDefinition::ENTITY_NAME,
            ProductDefinition::ENTITY_NAME,
            PromotionDefinition::ENTITY_NAME,
            
$this->process($container);

        $configurator = $container->getDefinition('sibling')->getConfigurator();
        $this->assertSame('Symfony\Component\DependencyInjection\Definition', $configurator[0]::class);
        $this->assertSame('parentClass', $configurator[0]->getClass());

        $factory = $container->getDefinition('sibling')->getFactory();
        $this->assertSame('Symfony\Component\DependencyInjection\Definition', $factory[0]::class);
        $this->assertSame('parentClass', $factory[0]->getClass());

        $argument = $container->getDefinition('sibling')->getArgument(0);
        $this->assertSame('Symfony\Component\DependencyInjection\Definition', $argument::class);
        $this->assertSame('parentClass', $argument->getClass());

        $properties = $container->getDefinition('sibling')->getProperties();
        $this->assertSame('Symfony\Component\DependencyInjection\Definition', $properties['prop']::class);
        $this->assertSame('parentClass', $properties['prop']->getClass());

        $methodCalls = $container->getDefinition('sibling')->getMethodCalls();
        $this->assertSame('Symfony\Component\DependencyInjection\Definition', $methodCalls[0][1][0]::class);
        $this->assertSame('parentClass', $methodCalls[0][1][0]->getClass());
    }

    
public function testValidContentRenderer()
    {
        $builder = new ContainerBuilder();
        $fragmentHandlerDefinition = $builder->register('fragment.handler')
            ->addArgument(null);
        $builder->register('my_content_renderer', 'Symfony\Component\HttpKernel\Tests\DependencyInjection\RendererService')
            ->addTag('kernel.fragment_renderer', ['alias' => 'foo']);

        $pass = new FragmentRendererPass();
        $pass->process($builder);

        $serviceLocatorDefinition = $builder->getDefinition((string) $fragmentHandlerDefinition->getArgument(0));
        $this->assertSame(ServiceLocator::class$serviceLocatorDefinition->getClass());
        $this->assertEquals(['foo' => new ServiceClosureArgument(new Reference('my_content_renderer'))]$serviceLocatorDefinition->getArgument(0));
    }
}

class RendererService implements FragmentRendererInterface
{
    public function render($uri, Request $request = null, array $options = []): Response
    {
    }

    


    public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
    {
        if ($input->mustSuggestArgumentValuesFor('provider')) {
            $suggestions->suggestValues($this->providers->keys());

            return;
        }

        if ($input->mustSuggestOptionValuesFor('domains')) {
            $provider = $this->providers->get($input->getArgument('provider'));

            if ($provider && method_exists($provider, 'getDomains')) {
                $domains = $provider->getDomains();
                $suggestions->suggestValues($domains);
            }

            return;
        }

        if ($input->mustSuggestOptionValuesFor('locales')) {
            $suggestions->suggestValues($this->enabledLocales);
        }
The <info>%command.name%</info> deletes an item from a given cache pool. %command.full_name% <pool> <key> EOF
            )
        ;
    }

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $io = new SymfonyStyle($input$output);
        $pool = $input->getArgument('pool');
        $key = $input->getArgument('key');
        $cachePool = $this->poolClearer->getPool($pool);

        if (!$cachePool->hasItem($key)) {
            $io->note(sprintf('Cache item "%s" does not exist in cache pool "%s".', $key$pool));

            return 0;
        }

        if (!$cachePool->deleteItem($key)) {
            throw new \Exception(sprintf('Cache item "%s" could not be deleted.', $key));
        }
EOT
            )
        ;
    }

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $io = new SymfonyStyle($input$output);

        $packageList = $input->getArgument('packages');
        $this->importMapManager->remove($packageList);

        if (1 === \count($packageList)) {
            $io->success(sprintf('Removed "%s" from importmap.php.', $packageList[0]));
        } else {
            $io->success(sprintf('Removed %d items from importmap.php.', \count($packageList)));
        }

        return Command::SUCCESS;
    }
}
EOF
            )
        ;
    }

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $io = new SymfonyStyle($input$output);
        $io->title('Messenger');

        $mapping = $this->mapping;
        if ($bus = $input->getArgument('bus')) {
            if (!isset($mapping[$bus])) {
                throw new RuntimeException(sprintf('Bus "%s" does not exist. Known buses are "%s".', $busimplode('", "', array_keys($this->mapping))));
            }
            $mapping = [$bus => $mapping[$bus]];
        }

        foreach ($mapping as $bus => $handlersByMessage) {
            $io->section($bus);

            $tableRows = [];
            foreach ($handlersByMessage as $message => $handlers) {
                


    /** * @param PropertyDefinitions $propertyDefinitions * * @return array<string, string> */
    private function gatherDetails(array $propertyDefinitions, ShopwareStyle $io, InputInterface $input): array
    {
        return array_map(
            function Darray $property) use ($io$input) {
                if ($input->getArgument($property['name']) !== null) {
                    return $input->getArgument($property['name']);
                }

                $question = new Question($property['prompt'] . ': ', $property['default']);
                $question->setValidator($property['validator'] ?? null);
                $question->setMaxAttempts(2);

                return $io->askQuestion($question);
            },
            $propertyDefinitions
        );
    }


        foreach ($container->getParameter('security.firewalls') as $firewallName) {
            $firewallContextDefinition = $container->getDefinition('security.firewall.map.context.'.$firewallName);
            $this->sortFirewallContextListeners($firewallContextDefinition$container);
        }
    }

    private function sortFirewallContextListeners(Definition $definition, ContainerBuilder $container): void
    {
        /** @var IteratorArgument $listenerIteratorArgument */
        $listenerIteratorArgument = $definition->getArgument(0);
        $prioritiesByServiceId = $this->getListenerPriorities($listenerIteratorArgument$container);

        $listeners = $listenerIteratorArgument->getValues();
        usort($listenersfn (Reference $a, Reference $b) => $prioritiesByServiceId[(string) $b] <=> $prioritiesByServiceId[(string) $a]);

        $listenerIteratorArgument->setValues(array_values($listeners));
    }

    private function getListenerPriorities(IteratorArgument $listeners, ContainerBuilder $container): array
    {
        $priorities = [];

        
umask($old);
        }
        if (!is_writable($dir)) {
            $output->writeln('<error>Output dir ' . $input->getOption('file') . ' is not writable, aborting</error>');

            return 1;
        }

        /** @var Locale|null $locale */
        $locale = $this->container->get(\Shopware\Components\Model\ModelManager::class)
            ->getRepository(\Shopware\Models\Shop\Locale::class)
            ->findOneByLocale($input->getArgument('locale'));
        if (!$locale) {
            $output->writeln('<error>Provided locale not found</error>');

            return 1;
        }

        $this->exportFormLabels($output$locale$dir);

        $this->exportElementLabels($output$locale$dir);

        return 0;
    }
protected function configure(): void
    {
        $this->addArgument('strategy', InputArgument::OPTIONAL, 'The strategy that should be applied');
    }

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $io = new ShopwareStyle($input$output);

        $availableStrategies = $this->appUrlChangeResolver->getAvailableStrategies();
        $strategy = $input->getArgument('strategy');

        if ($strategy === null || !\array_key_exists($strategy$availableStrategies)) {
            if ($strategy !== null) {
                $io->note(sprintf('Strategy with name: "%s" not found.', $strategy));
            }

            $strategy = $io->choice(
                'Choose what strategy should be applied, to resolve the app url change?',
                $availableStrategies
            );
        }

        
Home | Imprint | This part of the site doesn't use cookies.