setArguments example

class TranslatorPassTest extends TestCase
{
    public function testValidCollector()
    {
        $loader = (new Definition())
            ->addTag('translation.loader', ['alias' => 'xliff', 'legacy-alias' => 'xlf']);

        $reader = new Definition();

        $translator = (new Definition())
            ->setArguments([null, null, null, null]);

        $container = new ContainerBuilder();
        $container->setDefinition('translator.default', $translator);
        $container->setDefinition('translation.reader', $reader);
        $container->setDefinition('translation.xliff_loader', $loader);

        $pass = new TranslatorPass();
        $pass->process($container);

        $expectedReader = (new Definition())
            ->addMethodCall('addLoader', ['xliff', new Reference('translation.xliff_loader')])
            
if (\is_string($callable) && 1 === substr_count($callable, ':')) {
            $parts = explode(':', $callable);

            throw new InvalidArgumentException(sprintf('Invalid callable "%s": the "service:method" notation is not available when using PHP-based DI configuration. Use "[service(\'%s\'), \'%s\']" instead.', $callable$parts[0]$parts[1]));
        }

        if ($callable instanceof Expression) {
            $callable = '@='.$callable;
        }

        $this->definition->setArguments([static::processValue($callable, true)]);

        if ('Closure' !== ($this->definition->getClass() ?? 'Closure')) {
            $this->definition->setLazy(true);
        } else {
            $this->definition->setClass('Closure');
        }

        return new FromCallableConfigurator($this$this->definition);
    }
}
return $this->container;
    }

    /** * Overridden so that the application doesn't expect the command * name to be the first argument. */
    public function getDefinition()
    {
        $inputDefinition = parent::getDefinition();
        // clear out the normal first argument, which is the command name         $inputDefinition->setArguments();

        return $inputDefinition;
    }

    /** * Gets the name of the command based on input. * * @param InputInterface $input The input interface * * @return string The command name */
    
public function testSomeSpecificArgumentsAreSet()
    {
        $container = new ContainerBuilder();

        $container->register('foo', Foo::class);
        $container->register(A::class);
        $container->register(Dunglas::class);
        $container->register('multiple', MultipleArguments::class)
            ->setAutowired(true)
            // set the 2nd (index 1) argument only: autowire the first and third             // args are: A, Foo, Dunglas             ->setArguments([
                1 => new Reference('foo'),
                3 => ['bar'],
            ]);

        (new ResolveClassPass())->process($container);
        (new AutowirePass())->process($container);

        $definition = $container->getDefinition('multiple');
        $this->assertEquals(
            [
                new TypedReference(A::class, A::class),
                


    public function testChainAdapterPool()
    {
        $container = new ContainerBuilder();
        $container->setParameter('kernel.container_class', 'app');
        $container->setParameter('kernel.project_dir', 'foo');

        $container->register('cache.adapter.array', ArrayAdapter::class)
            ->addTag('cache.pool');
        $container->register('cache.adapter.apcu', ApcuAdapter::class)
            ->setArguments([null, 0, null])
            ->addTag('cache.pool');
        $container->register('cache.chain', ChainAdapter::class)
            ->addArgument(['cache.adapter.array', 'cache.adapter.apcu'])
            ->addTag('cache.pool');
        $container->setDefinition('cache.app', new ChildDefinition('cache.chain'))
            ->addTag('cache.pool');
        $container->setDefinition('doctrine.result_cache_pool', new ChildDefinition('cache.app'))
            ->addTag('cache.pool');

        $this->cachePoolPass->process($container);

        
if ($bundle instanceof Bundle) {
                $bundleMap[$bundle->getName()] = $bundle->getPath();
            }
        }

        $arguments = $assetService->getArguments();
        array_unshift($argumentsnew Reference('shopware.asset.asset.version_strategy'));
        array_unshift($argumentsnew Reference('shopware.asset.asset_without_versioning'));
        array_unshift($arguments$bundleMap);

        $assetService->setArguments(
            $arguments
        );
    }
}
if (\is_string($callable) && 1 === substr_count($callable, ':')) {
            $parts = explode(':', $callable);

            throw new InvalidArgumentException(sprintf('Invalid callable "%s": the "service:method" notation is not available when using PHP-based DI configuration. Use "[service(\'%s\'), \'%s\']" instead.', $callable$parts[0]$parts[1]));
        }

        if ($callable instanceof Expression) {
            $callable = '@='.$callable;
        }

        $this->definition->setArguments([static::processValue($callable, true)]);

        if ('Closure' !== ($this->definition->getClass() ?? 'Closure')) {
            $this->definition->setLazy(true);
        } else {
            $this->definition->setClass('Closure');
        }

        return new FromCallableConfigurator($this$this->definition);
    }
}
$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();

        // merge in parent definition         // purposely ignored attributes: abstract, shared, tags, autoconfigured         $def->setClass($parentDef->getClass());
        $def->setArguments($parentDef->getArguments());
        $def->setMethodCalls($parentDef->getMethodCalls());
        $def->setProperties($parentDef->getProperties());
        if ($parentDef->isDeprecated()) {
            $deprecation = $parentDef->getDeprecation('%service_id%');
            $def->setDeprecated($deprecation['package']$deprecation['version']$deprecation['message']);
        }
        $def->setFactory($parentDef->getFactory());
        $def->setConfigurator($parentDef->getConfigurator());
        $def->setFile($parentDef->getFile());
        $def->setPublic($parentDef->isPublic());
        $def->setLazy($parentDef->isLazy());
        
$container->getDefinition('exception_listener')->replaceArgument(3, $config['exceptions']);

        if ($this->readConfigEnabled('serializer', $container$config['serializer'])) {
            if (!class_exists(Serializer::class)) {
                throw new LogicException('Serializer support cannot be enabled as the Serializer component is not installed. Try running "composer require symfony/serializer-pack".');
            }

            $this->registerSerializerConfiguration($config['serializer']$container$loader);
        } else {
            $container->getDefinition('argument_resolver.request_payload')
                ->setArguments([])
                ->addError('You can neither use "#[MapRequestPayload]" nor "#[MapQueryString]" since the Serializer component is not '
                    .(class_exists(Serializer::class) ? 'enabled. Try setting "framework.serializer.enabled" to true.' : 'installed. Try running "composer require symfony/serializer-pack".')
                )
                ->addTag('container.error')
                ->clearTag('kernel.event_subscriber');

            $container->removeDefinition('console.command.serializer_debug');
        }

        if ($propertyInfoEnabled) {
            $this->registerPropertyInfoConfiguration($container$loader);
        }
class NormalInstallerServiceProvider implements ServiceProviderInterface {

  /** * {@inheritdoc} */
  public function register(ContainerBuilder $container) {
    // Replace cache services with in-memory implementations. The results in     // less queries to set caches which will only be cleared on the next module     // install.     $definition = $container->getDefinition('cache_factory');
    $definition->setClass(MemoryBackendFactory::class);
    $definition->setArguments([]);
    $definition->setMethodCalls([]);

    // Replace lock service with no-op implementation as Drupal installation can     // only occur in a single thread and the site should not be publicly     // available.     $container
      ->register('lock', NullLockBackend::class);

    // Remove the cache tags invalidator tag from the cache tags storage, so     // that we don't call it when cache tags are invalidated in the installer.     $container->getDefinition('cache_tags.invalidator.checksum')
      
if (!$name) {
                $name = 'help';
                $input = new ArrayInput(['command_name' => $this->defaultCommand]);
            } 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);
        }

    public function testDumpHandlesDefaultAttribute($class$expectedFile)
    {
        $container = new ContainerBuilder();
        $container
            ->register('foo', $class)
            ->setPublic(true)
            ->setAutowired(true)
            ->setArguments([2 => true]);

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

        $dumper = new YamlDumper($container);

        $this->assertSame(file_get_contents(self::$fixturesPath.'/yaml/'.$expectedFile)$dumper->dump());
    }

    public static function provideDefaultClasses()
    {
        yield [FooClassWithDefaultArrayAttribute::class, 'services_with_default_array.yml'];
        
// shopware.increment.gateway.mysql is fallback gateway if custom gateway is not set         $fallback = sprintf('shopware.increment.gateway.%s', $type);

        $active = sprintf('shopware.increment.%s.gateway.%s', $pool$type);

        switch ($type) {
            case 'array':
            case 'mysql':
                $referenceDefinition = $container->getDefinition($fallback);

                $definition = new Definition($referenceDefinition->getClass());
                $definition->setArguments($referenceDefinition->getArguments());
                $definition->setTags($referenceDefinition->getTags());

                $container->setDefinition($active$definition);

                return $active;
            case 'redis':
                $definition = new Definition('Redis');

                if (!\array_key_exists('url', $config)) {
                    return $active;
                }

                
      // installed, so we prevent it from being registered to the path processor       // manager. We do this by removing the tags that the compiler pass looks       // for. This means that the URL generator can safely be used within tests.       $container->getDefinition('path_alias.path_processor')
        ->clearTag('path_processor_inbound')
        ->clearTag('path_processor_outbound');
    }

    // Relax the password hashing cost in tests to avoid performance issues.     if ($container->hasDefinition('password')) {
      $container->getDefinition('password')
        ->setArguments([PASSWORD_BCRYPT, ['cost' => 4]]);
    }

    // Add the on demand rebuild route provider service.     $route_provider_service_name = 'router.route_provider';
    // While $container->get() does a recursive resolve, getDefinition() does     // not, so do it ourselves.     $id = $route_provider_service_name;
    while ($container->hasAlias($id)) {
      $id = (string) $container->getAlias($id);
    }
    $definition = $container->getDefinition($id);
    
/** * {@inheritdoc} */
  public function attachTo(ViewExecutable $clone$display_id, array &$build) {
    $displays = $this->getOption('displays');
    if (empty($displays[$display_id])) {
      return;
    }

    // Defer to the feed style; it may put in meta information, and/or     // attach a feed icon.     $clone->setArguments($this->view->args);
    $clone->setDisplay($this->display['id']);
    $clone->buildTitle();
    if ($plugin = $clone->display_handler->getPlugin('style')) {
      $plugin->attachTo($build$display_id$clone->getUrl()$clone->getTitle());
      foreach ($clone->feedIcons as $feed_icon) {
        $this->view->feedIcons[] = $feed_icon;
      }
    }

    // Clean up.     $clone->destroy();
    
Home | Imprint | This part of the site doesn't use cookies.