Container_DI52.php
95 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Pods\Container; |
| 4 | |
| 5 | use Pods\Prefixed\lucatume\DI52\Container as DI52Container; |
| 6 | |
| 7 | /** |
| 8 | * Describes the interface of a container that exposes methods to read its entries. |
| 9 | * |
| 10 | * @credit The StellarWP team - https://github.com/stellarwp/container-contract |
| 11 | * |
| 12 | * @since 3.0 |
| 13 | * |
| 14 | * @method mixed getVar( string $key, mixed|null $default = null ) |
| 15 | * @method void register( string $serviceProviderClass, string ...$alias ) |
| 16 | * @method self when( string $class ) |
| 17 | * @method self needs( string $id ) |
| 18 | * @method void give( mixed $implementation ) |
| 19 | */ |
| 20 | class Container_DI52 implements Container_Interface { |
| 21 | |
| 22 | /** |
| 23 | * @var self |
| 24 | */ |
| 25 | protected static $instance; |
| 26 | |
| 27 | /** |
| 28 | * @var DI52Container |
| 29 | */ |
| 30 | protected $container; |
| 31 | |
| 32 | /** |
| 33 | * Container constructor. |
| 34 | * |
| 35 | * @param object $container The container to use. |
| 36 | */ |
| 37 | public function __construct( $container = null ) { |
| 38 | $this->container = $container ?: new DI52Container(); |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * @return self |
| 43 | */ |
| 44 | public static function init() { |
| 45 | if ( empty( self::$instance ) ) { |
| 46 | self::$instance = new self(); |
| 47 | } |
| 48 | |
| 49 | return self::$instance; |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * @inheritDoc |
| 54 | */ |
| 55 | public function bind( string $id, $implementation = null, array $afterBuildMethods = null ) { |
| 56 | $this->container->bind( $id, $implementation, $afterBuildMethods ); |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * @inheritDoc |
| 61 | */ |
| 62 | public function get( string $id ) { |
| 63 | return $this->container->get( $id ); |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * @return DI52Container |
| 68 | */ |
| 69 | public function get_container() { |
| 70 | return $this->container; |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * @inheritDoc |
| 75 | */ |
| 76 | public function has( string $id ) { |
| 77 | return $this->container->has( $id ); |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * @inheritDoc |
| 82 | */ |
| 83 | public function singleton( string $id, $implementation = null, array $afterBuildMethods = null ) { |
| 84 | $this->container->singleton( $id, $implementation, $afterBuildMethods ); |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Defer all other calls to the container object. |
| 89 | */ |
| 90 | #[\ReturnTypeWillChange] |
| 91 | public function __call( $name, $arguments ) { |
| 92 | return $this->container->{$name}( ...$arguments ); |
| 93 | } |
| 94 | } |
| 95 |