ServiceSubscriberInterface.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Contracts\Service;
  11. /**
  12. * A ServiceSubscriber exposes its dependencies via the static {@link getSubscribedServices} method.
  13. *
  14. * The getSubscribedServices method returns an array of service types required by such instances,
  15. * optionally keyed by the service names used internally. Service types that start with an interrogation
  16. * mark "?" are optional, while the other ones are mandatory service dependencies.
  17. *
  18. * The injected service locators SHOULD NOT allow access to any other services not specified by the method.
  19. *
  20. * It is expected that ServiceSubscriber instances consume PSR-11-based service locators internally.
  21. * This interface does not dictate any injection method for these service locators, although constructor
  22. * injection is recommended.
  23. *
  24. * @author Nicolas Grekas <p@tchwork.com>
  25. */
  26. interface ServiceSubscriberInterface
  27. {
  28. /**
  29. * Returns an array of service types required by such instances, optionally keyed by the service names used internally.
  30. *
  31. * For mandatory dependencies:
  32. *
  33. * * ['logger' => 'Psr\Log\LoggerInterface'] means the objects use the "logger" name
  34. * internally to fetch a service which must implement Psr\Log\LoggerInterface.
  35. * * ['loggers' => 'Psr\Log\LoggerInterface[]'] means the objects use the "loggers" name
  36. * internally to fetch an iterable of Psr\Log\LoggerInterface instances.
  37. * * ['Psr\Log\LoggerInterface'] is a shortcut for
  38. * * ['Psr\Log\LoggerInterface' => 'Psr\Log\LoggerInterface']
  39. *
  40. * otherwise:
  41. *
  42. * * ['logger' => '?Psr\Log\LoggerInterface'] denotes an optional dependency
  43. * * ['loggers' => '?Psr\Log\LoggerInterface[]'] denotes an optional iterable dependency
  44. * * ['?Psr\Log\LoggerInterface'] is a shortcut for
  45. * * ['Psr\Log\LoggerInterface' => '?Psr\Log\LoggerInterface']
  46. *
  47. * @return string[] The required service types, optionally keyed by service names
  48. */
  49. public static function getSubscribedServices();
  50. }