-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[DependencyInjection][Routing] Define array-shapes to help writing PHP configs using yaml-like arrays #61490
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
142 changes: 142 additions & 0 deletions
142
src/Symfony/Component/DependencyInjection/Loader/Config/ServicesConfig.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| <?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\Config; | ||
|
|
||
| use Symfony\Component\DependencyInjection\ContainerInterface; | ||
| use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; | ||
| use Symfony\Component\DependencyInjection\Loader\Configurator\ReferenceConfigurator; | ||
| use Symfony\Component\DependencyInjection\Reference; | ||
| use Symfony\Component\ExpressionLanguage\Expression; | ||
|
|
||
| require_once __DIR__.\DIRECTORY_SEPARATOR.'functions.php'; | ||
|
|
||
| /** | ||
| * @psalm-type Arguments = list<mixed>|array<string, mixed> | ||
| * @psalm-type Callback = string|array{0:string|Reference|ReferenceConfigurator,1:string}|\Closure|Reference|ReferenceConfigurator|Expression | ||
| * @psalm-type Tags = list<string|array<string, array<string, mixed>>> | ||
| * @psalm-type Deprecation = array{package: string, version: string, message?: string} | ||
| * @psalm-type Call = array<string, Arguments>|array{0:string, 1?:Arguments, 2?:bool}|array{method:string, arguments?:Arguments, returns_clone?:bool} | ||
| * @psalm-type Imports = list<string|array{ | ||
| * resource: string, | ||
| * type?: string|null, | ||
| * ignore_errors?: bool, | ||
| * }> | ||
| * @psalm-type Parameters = array<string, scalar|\UnitEnum|array<scalar|\UnitEnum|array|null>|null> | ||
| * @psalm-type Defaults = array{ | ||
| * public?: bool, | ||
| * tags?: Tags, | ||
| * resource_tags?: Tags, | ||
| * autowire?: bool, | ||
| * autoconfigure?: bool, | ||
| * bind?: array<string, mixed>, | ||
| * } | ||
| * @psalm-type Instanceof = array{ | ||
| * shared?: bool, | ||
| * lazy?: bool|string, | ||
| * public?: bool, | ||
| * properties?: array<string, mixed>, | ||
| * configurator?: Callback, | ||
| * calls?: list<Call>, | ||
| * tags?: Tags, | ||
| * resource_tags?: Tags, | ||
| * autowire?: bool, | ||
| * bind?: array<string, mixed>, | ||
| * constructor?: string, | ||
| * } | ||
| * @psalm-type Definition = array{ | ||
| * class?: string, | ||
| * file?: string, | ||
| * parent?: string, | ||
| * shared?: bool, | ||
| * synthetic?: bool, | ||
| * lazy?: bool|string, | ||
| * public?: bool, | ||
| * abstract?: bool, | ||
| * deprecated?: Deprecation, | ||
| * factory?: Callback, | ||
| * configurator?: Callback, | ||
| * arguments?: Arguments, | ||
| * properties?: array<string, mixed>, | ||
| * calls?: list<Call>, | ||
| * tags?: Tags, | ||
| * resource_tags?: Tags, | ||
| * decorates?: string, | ||
| * decoration_inner_name?: string, | ||
| * decoration_priority?: int, | ||
| * decoration_on_invalid?: 'exception'|'ignore'|null|ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE|ContainerInterface::IGNORE_ON_INVALID_REFERENCE|ContainerInterface::NULL_ON_INVALID_REFERENCE, | ||
| * autowire?: bool, | ||
| * autoconfigure?: bool, | ||
| * bind?: array<string, mixed>, | ||
| * constructor?: string, | ||
| * from_callable?: mixed, | ||
| * } | ||
| * @psalm-type Alias = string|array{ | ||
| * alias: string, | ||
| * public?: bool, | ||
| * deprecated?: Deprecation, | ||
| * } | ||
| * @psalm-type Prototype = array{ | ||
| * resource: string, | ||
| * namespace?: string, | ||
| * exclude?: string|list<string>, | ||
| * parent?: string, | ||
| * shared?: bool, | ||
| * lazy?: bool|string, | ||
| * public?: bool, | ||
| * abstract?: bool, | ||
| * deprecated?: Deprecation, | ||
| * factory?: Callback, | ||
| * arguments?: Arguments, | ||
| * properties?: array<string, mixed>, | ||
| * configurator?: Callback, | ||
| * calls?: list<Call>, | ||
| * tags?: Tags, | ||
| * resource_tags?: Tags, | ||
| * autowire?: bool, | ||
| * autoconfigure?: bool, | ||
| * bind?: array<string, mixed>, | ||
| * constructor?: string, | ||
| * } | ||
| * @psalm-type Stack = array{ | ||
| * stack: list<Definition|Alias|Prototype|array<class-string, Arguments|null>>, | ||
| * public?: bool, | ||
| * deprecated?: Deprecation, | ||
| * } | ||
| * @psalm-type Services = array<string, Definition|Alias|Prototype|Stack>|array<class-string, Arguments|null> | ||
| */ | ||
| class ServicesConfig | ||
| { | ||
| public readonly array $services; | ||
|
|
||
| /** | ||
| * @param Services $services | ||
| * @param Imports $imports | ||
| * @param Parameters $parameters | ||
| * @param Defaults $defaults | ||
| * @param Instanceof $instanceof | ||
| */ | ||
| public function __construct( | ||
| array $services = [], | ||
| public readonly array $imports = [], | ||
| public readonly array $parameters = [], | ||
| array $defaults = [], | ||
| array $instanceof = [], | ||
| ) { | ||
| if (isset($services['_defaults']) || isset($services['_instanceof'])) { | ||
| throw new InvalidArgumentException('The $services argument should not contain "_defaults" or "_instanceof" keys, use the $defaults and $instanceof parameters instead.'); | ||
| } | ||
|
|
||
| $services['_defaults'] = $defaults; | ||
| $services['_instanceof'] = $instanceof; | ||
| $this->services = $services; | ||
| } | ||
| } |
129 changes: 129 additions & 0 deletions
129
src/Symfony/Component/DependencyInjection/Loader/Config/functions.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| <?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\Config; | ||
|
|
||
| use Symfony\Component\Config\Loader\ParamConfigurator; | ||
| use Symfony\Component\DependencyInjection\Argument\AbstractArgument; | ||
| use Symfony\Component\DependencyInjection\Argument\IteratorArgument; | ||
| use Symfony\Component\DependencyInjection\Argument\ServiceLocatorArgument; | ||
| use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument; | ||
| use Symfony\Component\DependencyInjection\Definition; | ||
| use Symfony\Component\DependencyInjection\Loader\Configurator\AbstractConfigurator; | ||
| use Symfony\Component\DependencyInjection\Loader\Configurator\ClosureReferenceConfigurator; | ||
| use Symfony\Component\DependencyInjection\Loader\Configurator\EnvConfigurator; | ||
| use Symfony\Component\DependencyInjection\Loader\Configurator\InlineServiceConfigurator; | ||
| use Symfony\Component\DependencyInjection\Loader\Configurator\ReferenceConfigurator; | ||
| use Symfony\Component\ExpressionLanguage\Expression; | ||
|
|
||
| /** | ||
| * Creates a parameter. | ||
| */ | ||
| function param(string $name): ParamConfigurator | ||
| { | ||
| return new ParamConfigurator($name); | ||
| } | ||
|
|
||
| /** | ||
| * Creates a reference to a service. | ||
| */ | ||
| function service(string $serviceId): ReferenceConfigurator | ||
| { | ||
| return new ReferenceConfigurator($serviceId); | ||
| } | ||
|
|
||
| /** | ||
| * Creates an inline service. | ||
| */ | ||
| function inline_service(?string $class = null): InlineServiceConfigurator | ||
| { | ||
| return new InlineServiceConfigurator(new Definition($class)); | ||
| } | ||
|
|
||
| /** | ||
| * Creates a service locator. | ||
| * | ||
| * @param array<ReferenceConfigurator|InlineServiceConfigurator> $values | ||
| */ | ||
| function service_locator(array $values): ServiceLocatorArgument | ||
| { | ||
| $values = AbstractConfigurator::processValue($values, true); | ||
|
|
||
| return new ServiceLocatorArgument($values); | ||
| } | ||
|
|
||
| /** | ||
| * Creates a lazy iterator. | ||
| * | ||
| * @param ReferenceConfigurator[] $values | ||
| */ | ||
| function iterator(array $values): IteratorArgument | ||
| { | ||
| return new IteratorArgument(AbstractConfigurator::processValue($values, true)); | ||
| } | ||
|
|
||
| /** | ||
| * Creates a lazy iterator by tag name. | ||
| */ | ||
| function tagged_iterator(string $tag, ?string $indexAttribute = null, ?string $defaultIndexMethod = null, ?string $defaultPriorityMethod = null, string|array $exclude = [], bool $excludeSelf = true): TaggedIteratorArgument | ||
fabpot marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| return new TaggedIteratorArgument($tag, $indexAttribute, $defaultIndexMethod, false, $defaultPriorityMethod, (array) $exclude, $excludeSelf); | ||
| } | ||
|
|
||
| /** | ||
| * Creates a service locator by tag name. | ||
| */ | ||
| function tagged_locator(string $tag, ?string $indexAttribute = null, ?string $defaultIndexMethod = null, ?string $defaultPriorityMethod = null, string|array $exclude = [], bool $excludeSelf = true): ServiceLocatorArgument | ||
| { | ||
| return new ServiceLocatorArgument(new TaggedIteratorArgument($tag, $indexAttribute, $defaultIndexMethod, true, $defaultPriorityMethod, (array) $exclude, $excludeSelf)); | ||
| } | ||
|
|
||
| /** | ||
| * Creates an expression. | ||
| */ | ||
| 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. | ||
| */ | ||
| function service_closure(string $serviceId): ClosureReferenceConfigurator | ||
| { | ||
| return new ClosureReferenceConfigurator($serviceId); | ||
| } | ||
|
|
||
| /** | ||
| * Creates a closure. | ||
| */ | ||
| function closure(string|array|\Closure|ReferenceConfigurator|Expression $callable): InlineServiceConfigurator | ||
| { | ||
| return (new InlineServiceConfigurator(new Definition('Closure'))) | ||
| ->factory(['Closure', 'fromCallable']) | ||
| ->args([$callable]); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file is adding the functions of the PHP-DSL to the
Symfony\Confignamespace. It's loaded byPhpFileLoader.