* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\DependencyInjection\Loader\Configurator; // For the phpdoc to remain compatible with the generation of per-app App class, // this file should have no "use" statements: all symbols referenced by // the phpdoc need to be in the current namespace or be root-scoped. /** * This class provides array-shapes for configuring the services and bundles of an application. * * Services declared with the config() method below are autowired and autoconfigured by default. * * This is for apps only. Bundles SHOULD NOT use it. * * Example: * * ```php * // config/services.php * namespace Symfony\Component\DependencyInjection\Loader\Configurator; * * return App::config([ * 'services' => [ * 'App\\' => [ * 'resource' => '../src/', * ], * ], * ]); * ``` * * @psalm-type ImportsConfig = list * @psalm-type ParametersConfig = array|\Symfony\Component\Config\Loader\ParamConfigurator|null>|\Symfony\Component\Config\Loader\ParamConfigurator|null> * @psalm-type ArgumentsType = list|array * @psalm-type CallType = array|array{0:string, 1?:ArgumentsType, 2?:bool}|array{method:string, arguments?:ArgumentsType, returns_clone?:bool} * @psalm-type TagsType = list>> // arrays inside the list must have only one element, with the tag name as the key * @psalm-type CallbackType = string|array{0:string|ReferenceConfigurator,1:string}|\Closure|ReferenceConfigurator|ExpressionConfigurator * @psalm-type DeprecationType = array{package: string, version: string, message?: string} * @psalm-type DefaultsType = array{ * public?: bool, * tags?: TagsType, * resource_tags?: TagsType, * autowire?: bool, * autoconfigure?: bool, * bind?: array, * } * @psalm-type InstanceofType = array{ * shared?: bool, * lazy?: bool|string, * public?: bool, * properties?: array, * configurator?: CallbackType, * calls?: list, * tags?: TagsType, * resource_tags?: TagsType, * autowire?: bool, * bind?: array, * constructor?: string, * } * @psalm-type DefinitionType = array{ * class?: string, * file?: string, * parent?: string, * shared?: bool, * synthetic?: bool, * lazy?: bool|string, * public?: bool, * abstract?: bool, * deprecated?: DeprecationType, * factory?: CallbackType, * configurator?: CallbackType, * arguments?: ArgumentsType, * properties?: array, * calls?: list, * tags?: TagsType, * resource_tags?: TagsType, * decorates?: string, * decoration_inner_name?: string, * decoration_priority?: int, * decoration_on_invalid?: 'exception'|'ignore'|null, * autowire?: bool, * autoconfigure?: bool, * bind?: array, * constructor?: string, * from_callable?: CallbackType, * } * @psalm-type AliasType = string|array{ * alias: string, * public?: bool, * deprecated?: DeprecationType, * } * @psalm-type PrototypeType = array{ * resource: string, * namespace?: string, * exclude?: string|list, * parent?: string, * shared?: bool, * lazy?: bool|string, * public?: bool, * abstract?: bool, * deprecated?: DeprecationType, * factory?: CallbackType, * arguments?: ArgumentsType, * properties?: array, * configurator?: CallbackType, * calls?: list, * tags?: TagsType, * resource_tags?: TagsType, * autowire?: bool, * autoconfigure?: bool, * bind?: array, * constructor?: string, * } * @psalm-type StackType = array{ * stack: list>, * public?: bool, * deprecated?: DeprecationType, * } * @psalm-type ServicesConfig = array{ * _defaults?: DefaultsType, * _instanceof?: InstanceofType, * ... * } * @psalm-type ExtensionType = array * @psalm-type ConfigType = array{ * imports?: ImportsConfig, * parameters?: ParametersConfig, * services?: ServicesConfig, * ..., * }> * } */ class AppReference { /** * @param ConfigType $config * * @psalm-return ConfigType */ public static function config(array $config): array { $defaults = [ '_defaults' => [ 'autowire' => true, 'autoconfigure' => true, ], ]; if (\is_array($config['services'] ?? null)) { $config['services'] = array_replace_recursive($defaults, $config['services']); } foreach ($config as $key => $value) { if (str_starts_with($key, 'when@') && \is_array($value['services'] ?? null)) { $config[$key]['services'] = array_replace_recursive($defaults, $value['services']); } } return $config; } }