| 1 |
<?php |
| 2 |
|
| 3 |
namespace Your\Namespace; |
| 4 |
|
| 5 |
use Give\Vendors\StellarWP\ContainerContract\ContainerInterface; |
| 6 |
|
| 7 |
// If you are including lucatume\DI52 using Strauss (recommended), then: |
| 8 |
use Your\Namespace\lucatume\DI52\Container as DI52Container; |
| 9 |
|
| 10 |
// If you are including lucatume\DI52 directly, then you'd want to do: |
| 11 |
// use lucatume\DI52\Container as DI52Container; |
| 12 |
|
| 13 |
class Container implements ContainerInterface { |
| 14 |
/** |
| 15 |
* @var DI52Container |
| 16 |
*/ |
| 17 |
protected $container; |
| 18 |
|
| 19 |
/** |
| 20 |
* Container constructor. |
| 21 |
* |
| 22 |
* @param object $container The container to use. |
| 23 |
*/ |
| 24 |
public function __construct( $container = null ) { |
| 25 |
$this->container = $container ?: new DI52Container(); |
| 26 |
} |
| 27 |
|
| 28 |
/** |
| 29 |
* @inheritDoc |
| 30 |
*/ |
| 31 |
public function bind( string $id, $implementation = null, array $afterBuildMethods = null ) { |
| 32 |
$this->container->bind( $id, $implementation, $afterBuildMethods ); |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* @inheritDoc |
| 37 |
*/ |
| 38 |
public function get( string $id ) { |
| 39 |
return $this->container->get( $id ); |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* @return DI52Container |
| 44 |
*/ |
| 45 |
public function get_container() { |
| 46 |
return $this->container; |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* @inheritDoc |
| 51 |
*/ |
| 52 |
public function has( string $id ) { |
| 53 |
return $this->container->has( $id ); |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* @inheritDoc |
| 58 |
*/ |
| 59 |
public function singleton( string $id, $implementation = null, array $afterBuildMethods = null ) { |
| 60 |
$this->container->singleton( $id, $implementation, $afterBuildMethods ); |
| 61 |
} |
| 62 |
|
| 63 |
/** |
| 64 |
* Defer all other calls to the container object. |
| 65 |
*/ |
| 66 |
public function __call( $name, $args ) { |
| 67 |
return $this->container->{$name}( ...$args ); |
| 68 |
} |
| 69 |
} |