# cookiebot/3.11.2/addons/lib/dependency-container.php

Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA &amp; Google Consent Mode, version 3.11.2. 54 lines.

- Page: https://pluginprobe.com/plugins/cookiebot/3.11.2/code/addons/lib/dependency-container.php
- Raw: https://pluginprobe.com/plugins/cookiebot/3.11.2/raw/addons/lib/dependency-container.php
- Modified: 2021-09-22T10:24:46+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/cookiebot/3.11.2/code/addons/lib/dependency-container.php#L10-L20`.

```php
<?php

namespace cookiebot_addons\lib;

use Exception;

/**
 * Class Dependency_Container
 * @package cookiebot_addons\lib
 */
class Dependency_Container {

	/**
	 * @var array
	 */
	private $dependencies;

	/**
	 * Dependency_Container constructor.
	 *
	 * @param  array  $dependencies
	 */
	public function __construct( array $dependencies = array() ) {
		$this->dependencies = $dependencies;
	}

	/**
	 * @param $key
	 * @param $dependency
	 *
	 * @throws Exception
	 */
	public function set( $key, $dependency ) {
		if ( isset( $this->dependencies[ $key ] ) ) {
			throw new Exception( 'Dependency key ' . $key . ' already exists' );
		}
		$this->dependencies[ $key ] = $dependency;
	}

	/**
	 * @param $key
	 *
	 * @return mixed
	 * @throws Exception
	 */
	public function get( $key ) {
		if ( ! isset( $this->dependencies[ $key ] ) ) {
			throw new Exception( 'Dependency key ' . $key . ' does not exists' );
		}

		return $this->dependencies[ $key ];
	}
}

```
