|
| 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 | +/** |
| 21 | + * @phpstan-type Imports list<string|array{ |
| 22 | + * resource: string, |
| 23 | + * type?: string|null, |
| 24 | + * ignore_errors?: bool, |
| 25 | + * }> |
| 26 | + * @phpstan-type Parameters array<string, scalar|\UnitEnum|array<scalar|\UnitEnum|array|null>|null> |
| 27 | + * @phpstan-type Services array<string, Definition|Alias|Prototype|Stack>|array<class-string, Arguments|null> |
| 28 | + * @phpstan-type Defaults array{ |
| 29 | + * public?: bool, |
| 30 | + * tags?: Tags, |
| 31 | + * resource_tags?: Tags, |
| 32 | + * autowire?: bool, |
| 33 | + * autoconfigure?: bool, |
| 34 | + * bind?: array<string, mixed>, |
| 35 | + * } |
| 36 | + * @phpstan-type Instanceof array{ |
| 37 | + * shared?: bool, |
| 38 | + * lazy?: bool|string, |
| 39 | + * public?: bool, |
| 40 | + * properties?: array<string, mixed>, |
| 41 | + * configurator?: Callback, |
| 42 | + * calls?: list<Call>, |
| 43 | + * tags?: Tags, |
| 44 | + * resource_tags?: Tags, |
| 45 | + * autowire?: bool, |
| 46 | + * bind?: array<string, mixed>, |
| 47 | + * constructor?: string, |
| 48 | + * } |
| 49 | + * @phpstan-type Definition array{ |
| 50 | + * class?: string, |
| 51 | + * file?: string, |
| 52 | + * parent?: string, |
| 53 | + * shared?: bool, |
| 54 | + * synthetic?: bool, |
| 55 | + * lazy?: bool|string, |
| 56 | + * public?: bool, |
| 57 | + * abstract?: bool, |
| 58 | + * deprecated?: Deprecation, |
| 59 | + * factory?: Callback, |
| 60 | + * configurator?: Callback, |
| 61 | + * arguments?: Arguments, |
| 62 | + * properties?: array<string, mixed>, |
| 63 | + * calls?: list<Call>, |
| 64 | + * tags?: Tags, |
| 65 | + * resource_tags?: Tags, |
| 66 | + * decorates?: string, |
| 67 | + * decoration_inner_name?: string, |
| 68 | + * decoration_priority?: int, |
| 69 | + * decoration_on_invalid?: 'exception'|'ignore'|null|ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE|ContainerInterface::IGNORE_ON_INVALID_REFERENCE|ContainerInterface::NULL_ON_INVALID_REFERENCE, |
| 70 | + * autowire?: bool, |
| 71 | + * autoconfigure?: bool, |
| 72 | + * bind?: array<string, mixed>, |
| 73 | + * constructor?: string, |
| 74 | + * from_callable?: mixed, |
| 75 | + * } |
| 76 | + * @phpstan-type Alias string|array{ |
| 77 | + * alias: string, |
| 78 | + * public?: bool, |
| 79 | + * deprecated?: Deprecation, |
| 80 | + * } |
| 81 | + * @phpstan-type Prototype array{ |
| 82 | + * resource: string, |
| 83 | + * namespace?: string, |
| 84 | + * exclude?: string|list<string>, |
| 85 | + * parent?: string, |
| 86 | + * shared?: bool, |
| 87 | + * lazy?: bool|string, |
| 88 | + * public?: bool, |
| 89 | + * abstract?: bool, |
| 90 | + * deprecated?: Deprecation, |
| 91 | + * factory?: Callback, |
| 92 | + * arguments?: Arguments, |
| 93 | + * properties?: array<string, mixed>, |
| 94 | + * configurator?: Callback, |
| 95 | + * calls?: list<Call>, |
| 96 | + * tags?: Tags, |
| 97 | + * resource_tags?: Tags, |
| 98 | + * autowire?: bool, |
| 99 | + * autoconfigure?: bool, |
| 100 | + * bind?: array<string, mixed>, |
| 101 | + * constructor?: string, |
| 102 | + * } |
| 103 | + * @phpstan-type Stack array{ |
| 104 | + * stack: list<Definition|Alias|Prototype|array<class-string, Arguments|null>>, |
| 105 | + * public?: bool, |
| 106 | + * deprecated?: Deprecation, |
| 107 | + * } |
| 108 | + * @phpstan-type Arguments list<mixed>|array<string, mixed> |
| 109 | + * @phpstan-type Callback string|array{0:string|Reference|ReferenceConfigurator,1:string}|\Closure|Reference|ReferenceConfigurator|Expression |
| 110 | + * @phpstan-type Tags list<string|array<string, array<string, mixed>>> |
| 111 | + * @phpstan-type Deprecation array{package: string, version: string, message?: string} |
| 112 | + * @phpstan-type Call array<string, Arguments>|array{0:string, 1?:Arguments, 2?:bool}|array{method:string, arguments?:Arguments, returns_clone?:bool} |
| 113 | + */ |
| 114 | +class ServicesConfig |
| 115 | +{ |
| 116 | + public readonly array $services; |
| 117 | + |
| 118 | + /** |
| 119 | + * @param Imports $imports |
| 120 | + * @param Parameters $parameters |
| 121 | + * @param Defaults $defaults |
| 122 | + * @param Instanceof $instanceof |
| 123 | + * @param Services $services |
| 124 | + */ |
| 125 | + public function __construct( |
| 126 | + public readonly array $imports = [], |
| 127 | + public readonly array $parameters = [], |
| 128 | + array $defaults = [], |
| 129 | + array $instanceof = [], |
| 130 | + array $services = [], |
| 131 | + ) { |
| 132 | + if (isset($services['_defaults']) || isset($services['_instanceof'])) { |
| 133 | + throw new InvalidArgumentException('The $services argument should not contain "_defaults" or "_instanceof" keys, use the $defaults and $instanceof parameters instead.'); |
| 134 | + } |
| 135 | + |
| 136 | + $services['_defaults'] = $defaults; |
| 137 | + $services['_instanceof'] = $instanceof; |
| 138 | + $this->services = $services; |
| 139 | + } |
| 140 | +} |
| 141 | + |
| 142 | +/** |
| 143 | + * Pre-configured ServicesConfig for the App namespace. |
| 144 | + * |
| 145 | + * This class helps configuring the App namespace with autowiring and autoconfiguration enabled by default. |
| 146 | + * Use ServicesConfig directly if you don't want this behavior, or if you're a bundle author. |
| 147 | + * |
| 148 | + * @phpstan-import-type Imports from ServicesConfig |
| 149 | + * @phpstan-import-type Parameters from ServicesConfig |
| 150 | + * @phpstan-import-type Defaults from ServicesConfig |
| 151 | + * @phpstan-import-type Instanceof from ServicesConfig |
| 152 | + * @phpstan-import-type Services from ServicesConfig |
| 153 | + */ |
| 154 | +class AppServicesConfig extends ServicesConfig |
| 155 | +{ |
| 156 | + /** |
| 157 | + * @param Imports $imports |
| 158 | + * @param Parameters $parameters |
| 159 | + * @param Defaults $defaults |
| 160 | + * @param Instanceof $instanceof |
| 161 | + * @param Services $services |
| 162 | + */ |
| 163 | + public function __construct( |
| 164 | + array $imports = [], |
| 165 | + array $parameters = [], |
| 166 | + array $defaults = [], |
| 167 | + array $instanceof = [], |
| 168 | + array $services = [], |
| 169 | + ) { |
| 170 | + $services = array_merge(['App\\' => ['resource' => '../src']], $services); |
| 171 | + $defaults = array_merge([ |
| 172 | + 'autowire' => true, |
| 173 | + 'autoconfigure' => true, |
| 174 | + ], $defaults); |
| 175 | + |
| 176 | + parent::__construct($imports, $parameters, $defaults, $instanceof, $services); |
| 177 | + } |
| 178 | +} |
| 179 | + |
| 180 | +namespace Symfony\Component\DependencyInjection\Loader\Config; |
| 181 | + |
| 182 | +class ServicesConfig extends \Symfony\Config\ServicesConfig |
| 183 | +{ |
| 184 | +} |
0 commit comments