welcome back to dyb-tech
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Attribute;
|
||||
|
||||
/**
|
||||
* An attribute to tell under which alias a service should be registered or to use the implemented interface if no parameter is given.
|
||||
*
|
||||
* @author Alan Poulain <contact@alanpoulain.eu>
|
||||
*/
|
||||
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::IS_REPEATABLE)]
|
||||
final class AsAlias
|
||||
{
|
||||
public function __construct(
|
||||
public ?string $id = null,
|
||||
public bool $public = false,
|
||||
) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Attribute;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
#[\Attribute(\Attribute::TARGET_CLASS)]
|
||||
class AsDecorator
|
||||
{
|
||||
public function __construct(
|
||||
public string $decorates,
|
||||
public int $priority = 0,
|
||||
public int $onInvalid = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
|
||||
) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Attribute;
|
||||
|
||||
/**
|
||||
* An attribute to tell under which index and priority a service class should be found in tagged iterators/locators.
|
||||
*
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*/
|
||||
#[\Attribute(\Attribute::TARGET_CLASS)]
|
||||
class AsTaggedItem
|
||||
{
|
||||
public function __construct(
|
||||
public ?string $index = null,
|
||||
public ?int $priority = null,
|
||||
) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Attribute;
|
||||
|
||||
/**
|
||||
* An attribute to tell how a base type should be autoconfigured.
|
||||
*
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*/
|
||||
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::IS_REPEATABLE)]
|
||||
class Autoconfigure
|
||||
{
|
||||
public function __construct(
|
||||
public ?array $tags = null,
|
||||
public ?array $calls = null,
|
||||
public ?array $bind = null,
|
||||
public bool|string|null $lazy = null,
|
||||
public ?bool $public = null,
|
||||
public ?bool $shared = null,
|
||||
public ?bool $autowire = null,
|
||||
public ?array $properties = null,
|
||||
public array|string|null $configurator = null,
|
||||
public string|null $constructor = null,
|
||||
) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Attribute;
|
||||
|
||||
/**
|
||||
* An attribute to tell how a base type should be tagged.
|
||||
*
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*/
|
||||
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::IS_REPEATABLE)]
|
||||
class AutoconfigureTag extends Autoconfigure
|
||||
{
|
||||
public function __construct(?string $name = null, array $attributes = [])
|
||||
{
|
||||
parent::__construct(
|
||||
tags: [
|
||||
[$name ?? 0 => $attributes],
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Attribute;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Argument\ArgumentInterface;
|
||||
use Symfony\Component\DependencyInjection\Exception\LogicException;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\ExpressionLanguage\Expression;
|
||||
|
||||
/**
|
||||
* Attribute to tell a parameter how to be autowired.
|
||||
*
|
||||
* @author Kevin Bond <kevinbond@gmail.com>
|
||||
*/
|
||||
#[\Attribute(\Attribute::TARGET_PARAMETER)]
|
||||
class Autowire
|
||||
{
|
||||
public readonly string|array|Expression|Reference|ArgumentInterface|null $value;
|
||||
public readonly bool|array $lazy;
|
||||
|
||||
/**
|
||||
* Use only ONE of the following.
|
||||
*
|
||||
* @param string|array|ArgumentInterface|null $value Value to inject (ie "%kernel.project_dir%/some/path")
|
||||
* @param string|null $service Service ID (ie "some.service")
|
||||
* @param string|null $expression Expression (ie 'service("some.service").someMethod()')
|
||||
* @param string|null $env Environment variable name (ie 'SOME_ENV_VARIABLE')
|
||||
* @param string|null $param Parameter name (ie 'some.parameter.name')
|
||||
* @param bool|class-string|class-string[] $lazy Whether to use lazy-loading for this argument
|
||||
*/
|
||||
public function __construct(
|
||||
string|array|ArgumentInterface|null $value = null,
|
||||
?string $service = null,
|
||||
?string $expression = null,
|
||||
?string $env = null,
|
||||
?string $param = null,
|
||||
bool|string|array $lazy = false,
|
||||
) {
|
||||
if ($this->lazy = \is_string($lazy) ? [$lazy] : $lazy) {
|
||||
if (null !== ($expression ?? $env ?? $param)) {
|
||||
throw new LogicException('#[Autowire] attribute cannot be $lazy and use $expression, $env, or $param.');
|
||||
}
|
||||
if (null !== $value && null !== $service) {
|
||||
throw new LogicException('#[Autowire] attribute cannot declare $value and $service at the same time.');
|
||||
}
|
||||
} elseif (!(null !== $value xor null !== $service xor null !== $expression xor null !== $env xor null !== $param)) {
|
||||
throw new LogicException('#[Autowire] attribute must declare exactly one of $service, $expression, $env, $param or $value.');
|
||||
}
|
||||
|
||||
if (\is_string($value) && str_starts_with($value, '@')) {
|
||||
match (true) {
|
||||
str_starts_with($value, '@@') => $value = substr($value, 1),
|
||||
str_starts_with($value, '@=') => $expression = substr($value, 2),
|
||||
default => $service = substr($value, 1),
|
||||
};
|
||||
}
|
||||
|
||||
$this->value = match (true) {
|
||||
null !== $service => new Reference($service),
|
||||
null !== $expression => class_exists(Expression::class) ? new Expression($expression) : throw new LogicException('Unable to use expressions as the Symfony ExpressionLanguage component is not installed. Try running "composer require symfony/expression-language".'),
|
||||
null !== $env => "%env($env)%",
|
||||
null !== $param => "%$param%",
|
||||
default => $value,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Attribute;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\Exception\LogicException;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
/**
|
||||
* Attribute to tell which callable to give to an argument of type Closure.
|
||||
*/
|
||||
#[\Attribute(\Attribute::TARGET_PARAMETER)]
|
||||
class AutowireCallable extends Autowire
|
||||
{
|
||||
/**
|
||||
* @param bool|class-string $lazy Whether to use lazy-loading for this argument
|
||||
*/
|
||||
public function __construct(
|
||||
string|array|null $callable = null,
|
||||
?string $service = null,
|
||||
?string $method = null,
|
||||
bool|string $lazy = false,
|
||||
) {
|
||||
if (!(null !== $callable xor null !== $service)) {
|
||||
throw new LogicException('#[AutowireCallable] attribute must declare exactly one of $callable or $service.');
|
||||
}
|
||||
if (null === $service && null !== $method) {
|
||||
throw new LogicException('#[AutowireCallable] attribute cannot have a $method without a $service.');
|
||||
}
|
||||
|
||||
parent::__construct($callable ?? [new Reference($service), $method ?? '__invoke'], lazy: $lazy);
|
||||
}
|
||||
|
||||
public function buildDefinition(mixed $value, ?string $type, \ReflectionParameter $parameter): Definition
|
||||
{
|
||||
return (new Definition($type = \is_string($this->lazy) ? $this->lazy : ($type ?: 'Closure')))
|
||||
->setFactory(['Closure', 'fromCallable'])
|
||||
->setArguments([\is_array($value) ? $value + [1 => '__invoke'] : $value])
|
||||
->setLazy($this->lazy || 'Closure' !== $type && 'callable' !== (string) $parameter->getType());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Attribute;
|
||||
|
||||
#[\Attribute(\Attribute::TARGET_PARAMETER)]
|
||||
class AutowireDecorated
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Attribute;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
/**
|
||||
* Attribute to wrap a service in a closure that returns it.
|
||||
*/
|
||||
#[\Attribute(\Attribute::TARGET_PARAMETER)]
|
||||
class AutowireServiceClosure extends Autowire
|
||||
{
|
||||
public function __construct(string $service)
|
||||
{
|
||||
parent::__construct(new ServiceClosureArgument(new Reference($service)));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Attribute;
|
||||
|
||||
/**
|
||||
* An attribute to tell the class should not be registered as service.
|
||||
*
|
||||
* @author Grégoire Pineau <lyrixx@lyrixx.info>
|
||||
*/
|
||||
#[\Attribute(\Attribute::TARGET_CLASS)]
|
||||
class Exclude
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Attribute;
|
||||
|
||||
trigger_deprecation('symfony/dependency-injection', '6.3', 'The "%s" class is deprecated, use "%s" instead.', MapDecorated::class, AutowireDecorated::class);
|
||||
|
||||
/**
|
||||
* @deprecated since Symfony 6.3, use AutowireDecorated instead
|
||||
*/
|
||||
#[\Attribute(\Attribute::TARGET_PARAMETER)]
|
||||
class MapDecorated
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Attribute;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument;
|
||||
|
||||
#[\Attribute(\Attribute::TARGET_PARAMETER)]
|
||||
class TaggedIterator extends Autowire
|
||||
{
|
||||
public function __construct(
|
||||
public string $tag,
|
||||
public ?string $indexAttribute = null,
|
||||
public ?string $defaultIndexMethod = null,
|
||||
public ?string $defaultPriorityMethod = null,
|
||||
public string|array $exclude = [],
|
||||
public bool $excludeSelf = true,
|
||||
) {
|
||||
parent::__construct(new TaggedIteratorArgument($tag, $indexAttribute, $defaultIndexMethod, false, $defaultPriorityMethod, (array) $exclude, $excludeSelf));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Attribute;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Argument\ServiceLocatorArgument;
|
||||
use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument;
|
||||
|
||||
#[\Attribute(\Attribute::TARGET_PARAMETER)]
|
||||
class TaggedLocator extends Autowire
|
||||
{
|
||||
public function __construct(
|
||||
public string $tag,
|
||||
public ?string $indexAttribute = null,
|
||||
public ?string $defaultIndexMethod = null,
|
||||
public ?string $defaultPriorityMethod = null,
|
||||
public string|array $exclude = [],
|
||||
public bool $excludeSelf = true,
|
||||
) {
|
||||
parent::__construct(new ServiceLocatorArgument(new TaggedIteratorArgument($tag, $indexAttribute, $defaultIndexMethod, true, $defaultPriorityMethod, (array) $exclude, $excludeSelf)));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Attribute;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* An attribute to tell how a dependency is used and hint named autowiring aliases.
|
||||
*
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*/
|
||||
#[\Attribute(\Attribute::TARGET_PARAMETER)]
|
||||
final class Target
|
||||
{
|
||||
public string $name;
|
||||
|
||||
public function __construct(string $name)
|
||||
{
|
||||
$this->name = lcfirst(str_replace(' ', '', ucwords(preg_replace('/[^a-zA-Z0-9\x7f-\xff]++/', ' ', $name))));
|
||||
}
|
||||
|
||||
public static function parseName(\ReflectionParameter $parameter, ?self &$attribute = null): string
|
||||
{
|
||||
$attribute = null;
|
||||
if (!$target = $parameter->getAttributes(self::class)[0] ?? null) {
|
||||
return $parameter->name;
|
||||
}
|
||||
|
||||
$attribute = $target->newInstance();
|
||||
$name = $attribute->name;
|
||||
|
||||
if (!preg_match('/^[a-zA-Z_\x7f-\xff]/', $name)) {
|
||||
if (($function = $parameter->getDeclaringFunction()) instanceof \ReflectionMethod) {
|
||||
$function = $function->class.'::'.$function->name;
|
||||
} else {
|
||||
$function = $function->name;
|
||||
}
|
||||
|
||||
throw new InvalidArgumentException(sprintf('Invalid #[Target] name "%s" on parameter "$%s" of "%s()": the first character must be a letter.', $name, $parameter->name, $function));
|
||||
}
|
||||
|
||||
return $name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Attribute;
|
||||
|
||||
/**
|
||||
* An attribute to tell under which environment this class should be registered as a service.
|
||||
*
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*/
|
||||
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD | \Attribute::TARGET_FUNCTION | \Attribute::IS_REPEATABLE)]
|
||||
class When
|
||||
{
|
||||
public function __construct(
|
||||
public string $env,
|
||||
) {
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user