1: <?php declare(strict_types = 1);
2:
3: namespace PHPStan\DependencyInjection;
4:
5: use Attribute;
6:
7: /**
8: * Registers a service in the DI container.
9: *
10: * Auto-adds service extension tags based on implemented interfaces.
11: * Pass autoTag: false for services whose implemented interfaces
12: * must not lead to the associated tags.
13: *
14: * The factory is a method of another service like '@App\MyFactory::create',
15: * or a static method like 'App\MyFactory::create'.
16: *
17: * A single type in `as` becomes the type of the service, like `class: Interface, factory: Implementation`
18: * in NEON: the service is autowired only as that type and gets the tags of the interfaces that type implements.
19: * A list of types restricts autowiring without changing the type of the service.
20: *
21: * Works thanks to https://github.com/ondrejmirtes/composer-attribute-collector
22: * and AutowiredAttributeServicesExtension.
23: *
24: * @api
25: */
26: #[Attribute(flags: Attribute::TARGET_CLASS)]
27: final class AutowiredService
28: {
29:
30: /**
31: * @api
32: * @param true|list<class-string>|class-string $as
33: */
34: public function __construct(
35: public ?string $name = null,
36: public ?string $factory = null,
37: public bool|array|string $as = true,
38: public bool $autoTag = true,
39: )
40: {
41: }
42:
43: }
44: