| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- <?php
- namespace AlexLcDee\RegistryContainer;
- class Registry implements RegistryInterface
- {
- /**
- * @var CategoriesContainer
- */
- private static $container;
- public static function init($typesMap)
- {
- if (static::$container !== null) {
- throw new RegistryException('Registry must be initialized once');
- }
- static::$container = new CategoriesContainer();
- foreach ($typesMap as $category => $type) {
- static::$container->set($category, $type);
- }
- }
- /**
- * @param string $category
- * @param RegistrableItem $item
- * @throws RegistryException
- */
- public static function add($category, RegistrableItem $item)
- {
- if (!static::$container->contains($category)) {
- throw new RegistryException(strtr('Registry does not contain category "{category}"', [
- '{category}' => $category
- ]));
- }
- static::$container->get($category)->add($item);
- }
- /**
- * @param string $category
- * @return ItemsContainer
- * @throws RegistryException
- */
- public static function get($category)
- {
- if (!static::$container->contains($category)) {
- throw new RegistryException(strtr('Registry does not contain category "{category}"', [
- '{category}' => $category
- ]));
- }
- return static::$container->get($category);
- }
- }
|