SubscribedService.php
48 lines
| 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\Contracts\Service\Attribute; |
| 13 | |
| 14 | use Symfony\Contracts\Service\ServiceMethodsSubscriberTrait; |
| 15 | use Symfony\Contracts\Service\ServiceSubscriberInterface; |
| 16 | |
| 17 | /** |
| 18 | * For use as the return value for {@see ServiceSubscriberInterface}. |
| 19 | * |
| 20 | * @example new SubscribedService('http_client', HttpClientInterface::class, false, new Target('githubApi')) |
| 21 | * |
| 22 | * Use with {@see ServiceMethodsSubscriberTrait} to mark a method's return type |
| 23 | * as a subscribed service. |
| 24 | * |
| 25 | * @author Kevin Bond <kevinbond@gmail.com> |
| 26 | */ |
| 27 | #[\Attribute(\Attribute::TARGET_METHOD)] |
| 28 | final class SubscribedService |
| 29 | { |
| 30 | /** @var object[] */ |
| 31 | public array $attributes; |
| 32 | |
| 33 | /** |
| 34 | * @param string|null $key The key to use for the service |
| 35 | * @param class-string|null $type The service class |
| 36 | * @param bool $nullable Whether the service is optional |
| 37 | * @param object|object[] $attributes One or more dependency injection attributes to use |
| 38 | */ |
| 39 | public function __construct( |
| 40 | public ?string $key = null, |
| 41 | public ?string $type = null, |
| 42 | public bool $nullable = false, |
| 43 | array|object $attributes = [], |
| 44 | ) { |
| 45 | $this->attributes = \is_array($attributes) ? $attributes : [$attributes]; |
| 46 | } |
| 47 | } |
| 48 |