Engine
2 days ago
Integrations
2 days ago
Validator
11 months ago
class-bootstrap.php
3 months ago
class-container.php
9 months ago
class-email-css-inliner.php
9 months ago
class-email-editor-container.php
5 months ago
class-package.php
11 months ago
exceptions.php
11 months ago
index.php
11 months ago
class-container.php
29 lines
| 1 | <?php |
| 2 | declare( strict_types = 1 ); |
| 3 | namespace Automattic\WooCommerce\EmailEditor; |
| 4 | if (!defined('ABSPATH')) exit; |
| 5 | class Container { |
| 6 | protected array $services = array(); |
| 7 | protected array $instances = array(); |
| 8 | public function __unserialize( array $data ): void { |
| 9 | throw new \Exception( 'Deserialization of Container is not allowed for security reasons.' ); |
| 10 | } |
| 11 | public function set( string $name, callable $callback ): void { |
| 12 | $this->services[ $name ] = $callback; |
| 13 | } |
| 14 | public function get( string $name ): object { |
| 15 | // Check if the service is already instantiated. |
| 16 | if ( isset( $this->instances[ $name ] ) ) { |
| 17 | $instance = $this->instances[ $name ]; |
| 18 | return $instance; |
| 19 | } |
| 20 | // Check if the service is registered. |
| 21 | if ( ! isset( $this->services[ $name ] ) ) { |
| 22 | throw new \Exception( esc_html( "Service not found: $name" ) ); |
| 23 | } |
| 24 | $instance = $this->services[ $name ]( $this ); |
| 25 | $this->instances[ $name ] = $instance; |
| 26 | return $instance; |
| 27 | } |
| 28 | } |
| 29 |