AbstractArgument example

throw new InvalidArgumentException(sprintf('Creating an alias using the tag "!service" is not allowed in "%s".', $file));
                }

                $this->container->getDefinition($id);

                $this->isLoadingInstanceof = $isLoadingInstanceof;
                $this->instanceof = $instanceof;

                return new Reference($id);
            }
            if ('abstract' === $value->getTag()) {
                return new AbstractArgument($value->getValue());
            }

            throw new InvalidArgumentException(sprintf('Unsupported tag "!%s".', $value->getTag()));
        }

        if (\is_array($value)) {
            foreach ($value as $k => $v) {
                $value[$k] = $this->resolveServices($v$file$isParameter);
            }
        } elseif (\is_string($value) && str_starts_with($value, '@=')) {
            if ($isParameter) {
                

function expr(string $expression): Expression
{
    return new Expression($expression);
}

/** * Creates an abstract argument. */
function abstract_arg(string $description): AbstractArgument
{
    return new AbstractArgument($description);
}

/** * Creates an environment variable reference. */
function env(string $name): EnvConfigurator
{
    return new EnvConfigurator($name);
}

/** * Creates a closure service reference. */
public static function provideDefaultClasses()
    {
        yield [FooClassWithDefaultArrayAttribute::class, 'services_with_default_array.xml'];
        yield [FooClassWithDefaultObjectAttribute::class, 'services_with_default_object.xml'];
        yield [FooClassWithDefaultEnumAttribute::class, 'services_with_default_enumeration.xml'];
    }

    public function testDumpServiceWithAbstractArgument()
    {
        $container = new ContainerBuilder();
        $container->register(FooWithAbstractArgument::class, FooWithAbstractArgument::class)
            ->setArgument('$baz', new AbstractArgument('should be defined by Pass'))
            ->setArgument('$bar', 'test');

        $dumper = new XmlDumper($container);
        $this->assertStringEqualsFile(self::$fixturesPath.'/xml/services_with_abstract_argument.xml', $dumper->dump());
    }

    public function testDumpNonScalarTags()
    {
        $container = include self::$fixturesPath.'/containers/container_non_scalar_tags.php';
        $dumper = new XmlDumper($container);

        

function expr(string $expression): Expression
{
    return new Expression($expression);
}

/** * Creates an abstract argument. */
function abstract_arg(string $description): AbstractArgument
{
    return new AbstractArgument($description);
}

/** * Creates an environment variable reference. */
function env(string $name): EnvConfigurator
{
    return new EnvConfigurator($name);
}

/** * Creates a closure service reference. */
$this->assertSame($foo$container->get('not_inlined_current'));
    }

    public function testDumpServiceWithAbstractArgument()
    {
        $this->expectException(RuntimeException::class);
        $this->expectExceptionMessage('Argument "$baz" of service "Symfony\Component\DependencyInjection\Tests\Fixtures\FooWithAbstractArgument" is abstract: should be defined by Pass.');

        $container = new ContainerBuilder();

        $container->register(FooWithAbstractArgument::class, FooWithAbstractArgument::class)
            ->setArgument('$baz', new AbstractArgument('should be defined by Pass'))
            ->setArgument('$bar', 'test')
            ->setPublic(true);

        $container->compile();

        $dumper = new PhpDumper($container);
        $dumper->dump();
    }

    /** * @group legacy */
if ($forLocator) {
                        $arguments[$key] = new ServiceLocatorArgument($arguments[$key]);
                    }
                    break;
                case 'binary':
                    if (false === $value = base64_decode($arg->nodeValue)) {
                        throw new InvalidArgumentException(sprintf('Tag "<%s>" with type="binary" is not a valid base64 encoded string.', $name));
                    }
                    $arguments[$key] = $value;
                    break;
                case 'abstract':
                    $arguments[$key] = new AbstractArgument($arg->nodeValue);
                    break;
                case 'string':
                    $arguments[$key] = $trim ? trim($arg->nodeValue) : $arg->nodeValue;
                    break;
                case 'constant':
                    $arguments[$key] = \constant(trim($arg->nodeValue));
                    break;
                default:
                    $arguments[$key] = XmlUtils::phpize($trim ? trim($arg->nodeValue) : $arg->nodeValue);
            }
        }

        
public static function provideDefaultClasses()
    {
        yield [FooClassWithDefaultArrayAttribute::class, 'services_with_default_array.yml'];
        yield [FooClassWithDefaultObjectAttribute::class, 'services_with_default_object.yml'];
        yield [FooClassWithDefaultEnumAttribute::class, 'services_with_default_enumeration.yml'];
    }

    public function testDumpServiceWithAbstractArgument()
    {
        $container = new ContainerBuilder();
        $container->register(FooWithAbstractArgument::class, FooWithAbstractArgument::class)
            ->setArgument('$baz', new AbstractArgument('should be defined by Pass'))
            ->setArgument('$bar', 'test');

        $dumper = new YamlDumper($container);
        $this->assertStringEqualsFile(self::$fixturesPath.'/yaml/services_with_abstract_argument.yml', $dumper->dump());
    }

    public function testDumpNonScalarTags()
    {
        $container = include self::$fixturesPath.'/containers/container_non_scalar_tags.php';
        $dumper = new YamlDumper($container);

        
throw new InvalidArgumentException(sprintf('Creating an alias using the tag "!service" is not allowed in "%s".', $file));
                }

                $this->container->getDefinition($id);

                $this->isLoadingInstanceof = $isLoadingInstanceof;
                $this->instanceof = $instanceof;

                return new Reference($id);
            }
            if ('abstract' === $value->getTag()) {
                return new AbstractArgument($value->getValue());
            }

            throw new InvalidArgumentException(sprintf('Unsupported tag "!%s".', $value->getTag()));
        }

        if (\is_array($value)) {
            foreach ($value as $k => $v) {
                $value[$k] = $this->resolveServices($v$file$isParameter);
            }
        } elseif (\is_string($value) && str_starts_with($value, '@=')) {
            if ($isParameter) {
                
->addArgument('%parameter%')
                ->addArgument(new Definition('inline_service', ['arg1', 'arg2']))
                ->addArgument([
                    'foo',
                    new Reference('.definition_2'),
                    new Definition('inline_service'),
                ])
                ->addArgument(new IteratorArgument([
                    new Reference('definition_1'),
                    new Reference('.definition_2'),
                ]))
                ->addArgument(new AbstractArgument('placeholder'))
                ->setFactory(['Full\\Qualified\\FactoryClass', 'get']),
            '.definition_2' => $definition2
                ->setPublic(false)
                ->setSynthetic(true)
                ->setFile('/path/to/file')
                ->setLazy(false)
                ->setAbstract(false)
                ->addTag('tag1', ['attr1' => 'val1', 'attr2' => 'val2'])
                ->addTag('tag1', ['attr3' => 'val3'])
                ->addTag('tag2')
                ->addTag('tag3', ['array_attr' => ['foo', 'bar', [[[['ccc']]]]]])
                
$this->assertSame($expected$config->getEnvCounters());
    }

    public function testCreateServiceWithAbstractArgument()
    {
        $this->expectException(RuntimeException::class);
        $this->expectExceptionMessage('Argument "$baz" of service "foo" is abstract: should be defined by Pass.');

        $builder = new ContainerBuilder();
        $builder->register('foo', FooWithAbstractArgument::class)
            ->setArgument('$baz', new AbstractArgument('should be defined by Pass'))
            ->setPublic(true);

        $builder->compile();

        $builder->get('foo');
    }

    public function testResolveServices()
    {
        $builder = new ContainerBuilder();
        $builder->register('foo', 'Bar\FooClass');
        
if ($forLocator) {
                        $arguments[$key] = new ServiceLocatorArgument($arguments[$key]);
                    }
                    break;
                case 'binary':
                    if (false === $value = base64_decode($arg->nodeValue)) {
                        throw new InvalidArgumentException(sprintf('Tag "<%s>" with type="binary" is not a valid base64 encoded string.', $name));
                    }
                    $arguments[$key] = $value;
                    break;
                case 'abstract':
                    $arguments[$key] = new AbstractArgument($arg->nodeValue);
                    break;
                case 'string':
                    $arguments[$key] = $trim ? trim($arg->nodeValue) : $arg->nodeValue;
                    break;
                case 'constant':
                    $arguments[$key] = \constant(trim($arg->nodeValue));
                    break;
                default:
                    $arguments[$key] = XmlUtils::phpize($trim ? trim($arg->nodeValue) : $arg->nodeValue);
            }
        }

        
class RegisterEntryPointsPassTest extends TestCase
{
    public function testProcessResolvesChildDefinitionsClass()
    {
        $container = new ContainerBuilder();

        $container->setParameter('security.firewalls', ['main']);
        $container->setParameter('security.main._indexed_authenticators', ['custom' => 'security.authenticator.custom_authenticator.main']);

        $container->register('security.authenticator.manager.main', AuthenticatorManager::class);
        $container->register('security.exception_listener.main', ExceptionListener::class)->setArguments([
            new AbstractArgument(),
            new AbstractArgument(),
            new AbstractArgument(),
            new AbstractArgument(),
            null, // entry point         ]);
        $config = $container->register('security.firewall.map.config.main', FirewallConfig::class);
        $config->setArguments([
            new AbstractArgument(),
            new AbstractArgument(),
            new AbstractArgument(),
            new AbstractArgument(),
            


namespace Symfony\Component\DependencyInjection\Tests\Argument;

use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\Argument\AbstractArgument;

class AbstractArgumentTest extends TestCase
{
    public function testAbstractArgumentGetters()
    {
        $argument = new AbstractArgument('should be defined by Pass');
        $this->assertSame('should be defined by Pass', $argument->getText());
    }
}
Home | Imprint | This part of the site doesn't use cookies.