ContainerInterface.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * This file is part of Hyperf.
  5. *
  6. * @link https://www.hyperf.io
  7. * @document https://hyperf.wiki
  8. * @contact group@hyperf.io
  9. * @license https://github.com/hyperf/hyperf/blob/master/LICENSE
  10. */
  11. namespace Hyperf\Contract;
  12. use Psr\Container\ContainerExceptionInterface;
  13. use Psr\Container\ContainerInterface as PsrContainerInterface;
  14. use Psr\Container\NotFoundExceptionInterface;
  15. use Throwable;
  16. interface ContainerInterface extends PsrContainerInterface
  17. {
  18. /**
  19. * Build an entry of the container by its name.
  20. * This method behave like get() except resolves the entry again every time.
  21. * For example if the entry is a class then a new instance will be created each time.
  22. * This method makes the container behave like a factory.
  23. *
  24. * @param string $name entry name or a class name
  25. * @param array $parameters Optional parameters to use to build the entry. Use this to force specific parameters
  26. * to specific values. Parameters not defined in this array will be resolved using
  27. * the container.
  28. * @throws ContainerExceptionInterface&Throwable the name parameter must be of type string
  29. * @throws NotFoundExceptionInterface&Throwable no entry found for the given name
  30. */
  31. public function make(string $name, array $parameters = []);
  32. /**
  33. * Bind an arbitrary resolved entry to an identifier.
  34. * Useful for testing 'get'.
  35. *
  36. * @param mixed $entry
  37. */
  38. public function set(string $name, $entry): void;
  39. /**
  40. * Unbind an arbitrary resolved entry.
  41. */
  42. public function unbind(string $name): void;
  43. /**
  44. * Bind an arbitrary definition to an identifier.
  45. * Useful for testing 'make'.
  46. *
  47. * @param array|callable|string $definition
  48. */
  49. public function define(string $name, $definition): void;
  50. }