buffer
4 years ago
script_loader_tag
4 years ago
traits
4 years ago
Consent_API_Helper.php
4 years ago
Cookie_Consent.php
4 years ago
Cookie_Consent_Interface.php
4 years ago
Cookiebot_Activated.php
4 years ago
Cookiebot_Automatic_Updates.php
4 years ago
Cookiebot_Deactivated.php
4 years ago
Cookiebot_Javascript_Helper.php
4 years ago
Cookiebot_WP.php
4 years ago
Dependency_Container.php
4 years ago
Settings_Page_Tab.php
4 years ago
Settings_Service.php
4 years ago
Settings_Service_Interface.php
4 years ago
Supported_Languages.php
4 years ago
WP_Rocket_Helper.php
4 years ago
Widgets.php
4 years ago
global-deprecations.php
4 years ago
helper.php
4 years ago
Dependency_Container.php
50 lines
| 1 | <?php |
| 2 | |
| 3 | namespace cybot\cookiebot\lib; |
| 4 | |
| 5 | use Exception; |
| 6 | |
| 7 | class Dependency_Container { |
| 8 | |
| 9 | /** |
| 10 | * @var array |
| 11 | */ |
| 12 | private $dependencies; |
| 13 | |
| 14 | /** |
| 15 | * Dependency_Container constructor. |
| 16 | * |
| 17 | * @param array $dependencies |
| 18 | */ |
| 19 | public function __construct( array $dependencies = array() ) { |
| 20 | $this->dependencies = $dependencies; |
| 21 | } |
| 22 | |
| 23 | /** |
| 24 | * @param $key |
| 25 | * @param $dependency |
| 26 | * |
| 27 | * @throws Exception |
| 28 | */ |
| 29 | public function set( $key, $dependency ) { |
| 30 | if ( isset( $this->dependencies[ $key ] ) ) { |
| 31 | throw new Exception( 'Dependency key ' . $key . ' already exists' ); |
| 32 | } |
| 33 | $this->dependencies[ $key ] = $dependency; |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * @param $key |
| 38 | * |
| 39 | * @return mixed |
| 40 | * @throws Exception |
| 41 | */ |
| 42 | public function get( $key ) { |
| 43 | if ( ! isset( $this->dependencies[ $key ] ) ) { |
| 44 | throw new Exception( 'Dependency key ' . $key . ' does not exists' ); |
| 45 | } |
| 46 | |
| 47 | return $this->dependencies[ $key ]; |
| 48 | } |
| 49 | } |
| 50 |