instanceof example

<?php
namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use App\FooService;
use Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype;

return function DContainerConfigurator $c) {
    $s = $c->services()->defaults()->public();
    $s->instanceof(Prototype\Foo::class)
        ->property('p', 0)
        ->call('setFoo', [service('foo')])
        ->tag('tag', ['k' => 'v'])
        ->share(false)
        ->lazy()
        ->configurator('c')
        ->property('p', 1);

    $s->load(Prototype::class.'\\', '../Prototype')->exclude('../Prototype/*/*');

    $s->set('foo', FooService::class);
};
$this->definition->addTag($name$attributes);

        return $this;
    }

    /** * Defines an instanceof-conditional to be applied to following service definitions. */
    final public function instanceof(string $fqcn): InstanceofConfigurator
    {
        return $this->parent->instanceof($fqcn);
    }

    private function validateAttributes(string $tag, array $attributes, array $path = []): void
    {
        foreach ($attributes as $name => $value) {
            if (\is_array($value)) {
                $this->validateAttributes($tag$value[...$path$name]);
            } elseif (!\is_scalar($value ?? '')) {
                $name = implode('.', [...$path$name]);
                throw new InvalidArgumentException(sprintf('Tag "%s", attribute "%s" in "_defaults" must be of a scalar-type or an array of scalar-type.', $tag$name));
            }
        }
            if ($argument->hasDefaultValue()) {
                return [$argument->getDefaultValue()];
            }

            if (!$argument->isNullable()) {
                throw new AccessDeniedException(sprintf('There is no logged-in user to pass to $%s, make the argument nullable if you want to allow anonymous access to the action.', $argument->getName()));
            }

            return [null];
        }

        if (null === $argument->getType() || $user instanceof ($argument->getType())) {
            return [$user];
        }

        throw new AccessDeniedException(sprintf('The logged-in user is an instance of "%s" but a user of type "%s" is expected.', $user::class$argument->getType()));
    }
}

        parent::__construct($parent$definition$id[]);

        $this->path = $path;
    }

    /** * Defines an instanceof-conditional to be applied to following service definitions. */
    final public function instanceof(string $fqcn): self
    {
        return $this->parent->instanceof($fqcn);
    }
}
<?php
namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\StaticConstructor\PrototypeStaticConstructor;
use Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\StaticConstructor\PrototypeStaticConstructorInterface;

return function DContainerConfigurator $c) {
    $s = $c->services()->defaults()->public();
    $s->instanceof(PrototypeStaticConstructorInterface::class)
        ->constructor('create');

    $s->set('foo', PrototypeStaticConstructor::class);
};

        parent::__construct($parent$definition$id[]);

        $this->path = $path;
    }

    /** * Defines an instanceof-conditional to be applied to following service definitions. */
    final public function instanceof(string $fqcn): self
    {
        return $this->parent->instanceof($fqcn);
    }
}
$this->definition->addTag($name$attributes);

        return $this;
    }

    /** * Defines an instanceof-conditional to be applied to following service definitions. */
    final public function instanceof(string $fqcn): InstanceofConfigurator
    {
        return $this->parent->instanceof($fqcn);
    }

    private function validateAttributes(string $tag, array $attributes, array $path = []): void
    {
        foreach ($attributes as $name => $value) {
            if (\is_array($value)) {
                $this->validateAttributes($tag$value[...$path$name]);
            } elseif (!\is_scalar($value ?? '')) {
                $name = implode('.', [...$path$name]);
                throw new InvalidArgumentException(sprintf('Tag "%s", attribute "%s" in "_defaults" must be of a scalar-type or an array of scalar-type.', $tag$name));
            }
        }
Home | Imprint | This part of the site doesn't use cookies.