| <?php |
|
|
| |
| |
| |
| |
| |
| |
|
|
| namespace Piwik\Container; |
|
|
| use Piwik\Container\Container; |
| use Piwik\Exception\DI\DependencyException; |
| use Piwik\Exception\DI\NotFoundException; |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| class StaticContainer |
| { |
| |
| |
| |
| private static $containerStack = array(); |
|
|
| |
| |
| |
| |
| |
| private static $definitions = array(); |
|
|
| |
| |
| |
| public static function getContainer() |
| { |
| if (empty(self::$containerStack)) { |
| throw new ContainerDoesNotExistException("The root container has not been created yet."); |
| } |
|
|
| return end(self::$containerStack); |
| } |
|
|
| public static function clearContainer() |
| { |
| self::pop(); |
| } |
|
|
| |
| |
| |
| public static function push(Container $container) |
| { |
| self::$containerStack[] = $container; |
| } |
|
|
| public static function pop() |
| { |
| array_pop(self::$containerStack); |
| } |
|
|
| public static function addDefinitions(array $definitions) |
| { |
| self::$definitions[] = $definitions; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| public static function get($name) |
| { |
| try { |
| return self::getContainer()->get($name); |
| } catch (\DI\NotFoundException $e) { |
| throw new NotFoundException($e->getMessage(), $e->getCode(), $e); |
| } catch (\DI\DependencyException $e) { |
| throw new DependencyException($e->getMessage(), $e->getCode(), $e); |
| } |
| } |
|
|
| public static function getDefinitions() |
| { |
| return self::$definitions; |
| } |
| } |
|
|