Container_Interface.php
69 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Pods\Container; |
| 4 | |
| 5 | /** |
| 6 | * Describes the interface of a container that exposes methods to read its entries. |
| 7 | * |
| 8 | * @credit The StellarWP team - https://github.com/stellarwp/container-contract |
| 9 | * |
| 10 | * @since 3.0 |
| 11 | */ |
| 12 | interface Container_Interface { |
| 13 | /** |
| 14 | * Binds an interface, a class or a string slug to an implementation. |
| 15 | * |
| 16 | * Existing implementations are replaced. |
| 17 | * |
| 18 | * @since 3.0 |
| 19 | * |
| 20 | * @param string|class-string $id Identifier of the entry to look for. |
| 21 | * @param mixed $implementation The implementation that should be bound to the alias(es); can be a |
| 22 | * class name, an object or a closure. |
| 23 | * |
| 24 | * @return void |
| 25 | */ |
| 26 | public function bind( string $id, $implementation = null ); |
| 27 | |
| 28 | /** |
| 29 | * Finds an entry of the container by its identifier and returns it. |
| 30 | * |
| 31 | * @since 3.0 |
| 32 | * |
| 33 | * @template T |
| 34 | * |
| 35 | * @param string|class-string<T> $id Identifier of the entry to look for. |
| 36 | * |
| 37 | * @return ($id is class-string<T> ? T : mixed) Entry. |
| 38 | */ |
| 39 | public function get( string $id ); |
| 40 | |
| 41 | /** |
| 42 | * Returns true if the container can return an entry for the given identifier. |
| 43 | * Returns false otherwise. |
| 44 | * |
| 45 | * `has($id)` returning true does not mean that `get($id)` will not throw an exception. |
| 46 | * It does however mean that `get($id)` will not throw a `NotFoundExceptionInterface`. |
| 47 | * |
| 48 | * @since 3.0 |
| 49 | * |
| 50 | * @param string|class-string $id Identifier of the entry to look for. |
| 51 | * |
| 52 | * @return bool |
| 53 | */ |
| 54 | public function has( string $id ); |
| 55 | |
| 56 | /** |
| 57 | * Binds an interface a class or a string slug to an implementation and will always return the same instance. |
| 58 | * |
| 59 | * @since 3.0 |
| 60 | * |
| 61 | * @param string|class-string $id Identifier of the entry to look for. |
| 62 | * @param mixed $implementation The implementation that should be bound to the alias(es); can be a |
| 63 | * class name, an object or a closure. |
| 64 | * |
| 65 | * @return void This method does not return any value. |
| 66 | */ |
| 67 | public function singleton( string $id, $implementation = null ); |
| 68 | } |
| 69 |