|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <fabien@symfony.com> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace Symfony\Config; |
| 13 | + |
| 14 | +use Symfony\Component\DependencyInjection\ContainerInterface; |
| 15 | +use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; |
| 16 | +use Symfony\Component\DependencyInjection\Loader\Configurator\ReferenceConfigurator; |
| 17 | +use Symfony\Component\DependencyInjection\Reference; |
| 18 | +use Symfony\Component\ExpressionLanguage\Expression; |
| 19 | + |
| 20 | +require_once __DIR__.\DIRECTORY_SEPARATOR.'functions.php'; |
| 21 | + |
| 22 | +/** |
| 23 | + * @psalm-type Arguments = list<mixed>|array<string, mixed> |
| 24 | + * @psalm-type Callback = string|array{0:string|Reference|ReferenceConfigurator,1:string}|\Closure|Reference|ReferenceConfigurator|Expression |
| 25 | + * @psalm-type Tags = list<string|array<string, array<string, mixed>>> |
| 26 | + * @psalm-type Deprecation = array{package: string, version: string, message?: string} |
| 27 | + * @psalm-type Call = array<string, Arguments>|array{0:string, 1?:Arguments, 2?:bool}|array{method:string, arguments?:Arguments, returns_clone?:bool} |
| 28 | + * @psalm-type Imports = list<string|array{ |
| 29 | + * resource: string, |
| 30 | + * type?: string|null, |
| 31 | + * ignore_errors?: bool, |
| 32 | + * }> |
| 33 | + * @psalm-type Parameters = array<string, scalar|\UnitEnum|array<scalar|\UnitEnum|array|null>|null> |
| 34 | + * @psalm-type Defaults = array{ |
| 35 | + * public?: bool, |
| 36 | + * tags?: Tags, |
| 37 | + * resource_tags?: Tags, |
| 38 | + * autowire?: bool, |
| 39 | + * autoconfigure?: bool, |
| 40 | + * bind?: array<string, mixed>, |
| 41 | + * } |
| 42 | + * @psalm-type Instanceof = array{ |
| 43 | + * shared?: bool, |
| 44 | + * lazy?: bool|string, |
| 45 | + * public?: bool, |
| 46 | + * properties?: array<string, mixed>, |
| 47 | + * configurator?: Callback, |
| 48 | + * calls?: list<Call>, |
| 49 | + * tags?: Tags, |
| 50 | + * resource_tags?: Tags, |
| 51 | + * autowire?: bool, |
| 52 | + * bind?: array<string, mixed>, |
| 53 | + * constructor?: string, |
| 54 | + * } |
| 55 | + * @psalm-type Definition = array{ |
| 56 | + * class?: string, |
| 57 | + * file?: string, |
| 58 | + * parent?: string, |
| 59 | + * shared?: bool, |
| 60 | + * synthetic?: bool, |
| 61 | + * lazy?: bool|string, |
| 62 | + * public?: bool, |
| 63 | + * abstract?: bool, |
| 64 | + * deprecated?: Deprecation, |
| 65 | + * factory?: Callback, |
| 66 | + * configurator?: Callback, |
| 67 | + * arguments?: Arguments, |
| 68 | + * properties?: array<string, mixed>, |
| 69 | + * calls?: list<Call>, |
| 70 | + * tags?: Tags, |
| 71 | + * resource_tags?: Tags, |
| 72 | + * decorates?: string, |
| 73 | + * decoration_inner_name?: string, |
| 74 | + * decoration_priority?: int, |
| 75 | + * decoration_on_invalid?: 'exception'|'ignore'|null|ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE|ContainerInterface::IGNORE_ON_INVALID_REFERENCE|ContainerInterface::NULL_ON_INVALID_REFERENCE, |
| 76 | + * autowire?: bool, |
| 77 | + * autoconfigure?: bool, |
| 78 | + * bind?: array<string, mixed>, |
| 79 | + * constructor?: string, |
| 80 | + * from_callable?: mixed, |
| 81 | + * } |
| 82 | + * @psalm-type Alias = string|array{ |
| 83 | + * alias: string, |
| 84 | + * public?: bool, |
| 85 | + * deprecated?: Deprecation, |
| 86 | + * } |
| 87 | + * @psalm-type Prototype = array{ |
| 88 | + * resource: string, |
| 89 | + * namespace?: string, |
| 90 | + * exclude?: string|list<string>, |
| 91 | + * parent?: string, |
| 92 | + * shared?: bool, |
| 93 | + * lazy?: bool|string, |
| 94 | + * public?: bool, |
| 95 | + * abstract?: bool, |
| 96 | + * deprecated?: Deprecation, |
| 97 | + * factory?: Callback, |
| 98 | + * arguments?: Arguments, |
| 99 | + * properties?: array<string, mixed>, |
| 100 | + * configurator?: Callback, |
| 101 | + * calls?: list<Call>, |
| 102 | + * tags?: Tags, |
| 103 | + * resource_tags?: Tags, |
| 104 | + * autowire?: bool, |
| 105 | + * autoconfigure?: bool, |
| 106 | + * bind?: array<string, mixed>, |
| 107 | + * constructor?: string, |
| 108 | + * } |
| 109 | + * @psalm-type Stack = array{ |
| 110 | + * stack: list<Definition|Alias|Prototype|array<class-string, Arguments|null>>, |
| 111 | + * public?: bool, |
| 112 | + * deprecated?: Deprecation, |
| 113 | + * } |
| 114 | + * @psalm-type Services = array<string, Definition|Alias|Prototype|Stack>|array<class-string, Arguments|null> |
| 115 | + */ |
| 116 | +class ServicesConfig |
| 117 | +{ |
| 118 | + public readonly array $services; |
| 119 | + |
| 120 | + /** |
| 121 | + * @param Services $services |
| 122 | + * @param Imports $imports |
| 123 | + * @param Parameters $parameters |
| 124 | + * @param Defaults $defaults |
| 125 | + * @param Instanceof $instanceof |
| 126 | + */ |
| 127 | + public function __construct( |
| 128 | + array $services = [], |
| 129 | + public readonly array $imports = [], |
| 130 | + public readonly array $parameters = [], |
| 131 | + array $defaults = [], |
| 132 | + array $instanceof = [], |
| 133 | + ) { |
| 134 | + if (isset($services['_defaults']) || isset($services['_instanceof'])) { |
| 135 | + throw new InvalidArgumentException('The $services argument should not contain "_defaults" or "_instanceof" keys, use the $defaults and $instanceof parameters instead.'); |
| 136 | + } |
| 137 | + |
| 138 | + $services['_defaults'] = $defaults; |
| 139 | + $services['_instanceof'] = $instanceof; |
| 140 | + $this->services = $services; |
| 141 | + } |
| 142 | +} |
0 commit comments