1
0

psr_container.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. declare(strict_types=1);
  3. namespace Psr\Container;
  4. use Throwable;
  5. /**
  6. * Base interface representing a generic exception in a container.
  7. */
  8. interface ContainerExceptionInterface extends Throwable
  9. {
  10. }
  11. /**
  12. * Describes the interface of a container that exposes methods to read its entries.
  13. */
  14. interface ContainerInterface
  15. {
  16. /**
  17. * Finds an entry of the container by its identifier and returns it.
  18. *
  19. * @param string $id Identifier of the entry to look for.
  20. *
  21. * @throws NotFoundExceptionInterface No entry was found for **this** identifier.
  22. * @throws ContainerExceptionInterface Error while retrieving the entry.
  23. *
  24. * @return mixed Entry.
  25. */
  26. public function get(string $id);
  27. /**
  28. * Returns true if the container can return an entry for the given identifier.
  29. * Returns false otherwise.
  30. *
  31. * `has($id)` returning true does not mean that `get($id)` will not throw an exception.
  32. * It does however mean that `get($id)` will not throw a `NotFoundExceptionInterface`.
  33. *
  34. * @param string $id Identifier of the entry to look for.
  35. *
  36. * @return bool
  37. */
  38. public function has(string $id): bool;
  39. }
  40. /**
  41. * No entry was found in the container.
  42. */
  43. interface NotFoundExceptionInterface extends ContainerExceptionInterface
  44. {
  45. }