ContainerInterface.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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\ContainerInterface as PsrContainerInterface;
  13. interface ContainerInterface extends PsrContainerInterface
  14. {
  15. /**
  16. * Build an entry of the container by its name.
  17. * This method behave like get() except resolves the entry again every time.
  18. * For example if the entry is a class then a new instance will be created each time.
  19. * This method makes the container behave like a factory.
  20. *
  21. * @param string $name entry name or a class name
  22. * @param array $parameters Optional parameters to use to build the entry. Use this to force specific parameters
  23. * to specific values. Parameters not defined in this array will be resolved using
  24. * the container.
  25. * @throws InvalidArgumentException the name parameter must be of type string
  26. * @throws NotFoundException no entry found for the given name
  27. */
  28. public function make(string $name, array $parameters = []);
  29. /**
  30. * Bind an arbitrary resolved entry to an identifier.
  31. * Useful for testing 'get'.
  32. *
  33. * @param mixed $entry
  34. */
  35. public function set(string $name, $entry);
  36. /**
  37. * Unbind an arbitrary resolved entry.
  38. */
  39. public function unbind(string $name);
  40. /**
  41. * Bind an arbitrary definition to an identifier.
  42. * Useful for testing 'make'.
  43. *
  44. * @param array|callable|string $definition
  45. */
  46. public function define(string $name, $definition);
  47. }