| 1 |
<?php |
| 2 |
/** |
| 3 |
* A local container mapping di52 methods to ContainerInterface. |
| 4 |
* |
| 5 |
* @since 0.1.0 |
| 6 |
* |
| 7 |
* @package SolidWP\Performance |
| 8 |
*/ |
| 9 |
|
| 10 |
namespace SolidWP\Performance; |
| 11 |
|
| 12 |
use SolidWP\Performance\StellarWP\ContainerContract\ContainerInterface; |
| 13 |
use SolidWP\Performance\lucatume\DI52\Container as DI52Container; |
| 14 |
|
| 15 |
if ( ! defined( 'ABSPATH' ) ) { |
| 16 |
exit; |
| 17 |
} |
| 18 |
|
| 19 |
/** |
| 20 |
* A local container implementation. |
| 21 |
* |
| 22 |
* @since 0.1.0 |
| 23 |
* |
| 24 |
* @package SolidWP\Performance |
| 25 |
* |
| 26 |
* @method mixed getVar(string $key, mixed|null $default = null) |
| 27 |
* @method void setVar(string $key, mixed $value) |
| 28 |
* @method void register(string $serviceProviderClass, string ...$alias) |
| 29 |
* @method self when(string $class) |
| 30 |
* @method self needs(string $id) |
| 31 |
* @method void give(mixed $implementation) |
| 32 |
* @method void callback(string|object $id, string $method) |
| 33 |
* @method void offsetUnset(string $id) |
| 34 |
*/ |
| 35 |
class Container implements ContainerInterface { |
| 36 |
|
| 37 |
/** |
| 38 |
* @since 0.1.0 |
| 39 |
* |
| 40 |
* @var DI52Container |
| 41 |
*/ |
| 42 |
protected DI52Container $container; |
| 43 |
|
| 44 |
/** |
| 45 |
* Container constructor. |
| 46 |
* |
| 47 |
* @since 0.1.0 |
| 48 |
* |
| 49 |
* @param DI52Container $container The container to use. |
| 50 |
*/ |
| 51 |
public function __construct( DI52Container $container ) { |
| 52 |
$this->container = $container; |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* {@inheritdoc} |
| 57 |
*/ |
| 58 |
public function bind( string $id, $implementation = null, array $after_build_methods = null ) { |
| 59 |
$this->container->bind( $id, $implementation, $after_build_methods ); |
| 60 |
} |
| 61 |
|
| 62 |
/** |
| 63 |
* {@inheritdoc} |
| 64 |
*/ |
| 65 |
public function get( string $id ) { |
| 66 |
return $this->container->get( $id ); |
| 67 |
} |
| 68 |
|
| 69 |
/** |
| 70 |
* @since 0.1.0 |
| 71 |
* |
| 72 |
* @return DI52Container |
| 73 |
*/ |
| 74 |
public function get_container() { |
| 75 |
return $this->container; |
| 76 |
} |
| 77 |
|
| 78 |
/** |
| 79 |
* {@inheritdoc} |
| 80 |
*/ |
| 81 |
public function has( string $id ) { |
| 82 |
return $this->container->has( $id ); |
| 83 |
} |
| 84 |
|
| 85 |
/** |
| 86 |
* {@inheritdoc} |
| 87 |
*/ |
| 88 |
public function singleton( string $id, $implementation = null, array $after_build_methods = null ) { |
| 89 |
$this->container->singleton( $id, $implementation, $after_build_methods ); |
| 90 |
} |
| 91 |
|
| 92 |
/** |
| 93 |
* Defer all other calls to the container object. |
| 94 |
* |
| 95 |
* @since 0.1.0 |
| 96 |
* |
| 97 |
* @param string $name The name of the method to call. |
| 98 |
* @param array $args The arguments to pass to the method. |
| 99 |
*/ |
| 100 |
public function __call( $name, $args ) { |
| 101 |
return $this->container->{$name}( ...$args ); |
| 102 |
} |
| 103 |
} |
| 104 |
|