|
|
@@ -15,17 +15,34 @@ class Registry implements RegistryInterface
|
|
|
*/
|
|
|
private $container;
|
|
|
|
|
|
- private function __construct($typesMap)
|
|
|
+ /**
|
|
|
+ * Registry constructor.
|
|
|
+ * @param array $typesMap
|
|
|
+ */
|
|
|
+ private function __construct(array $typesMap)
|
|
|
{
|
|
|
$this->container = new CategoriesContainer();
|
|
|
- foreach ($typesMap as $category => $type) {
|
|
|
- $this->container->set($category, new ItemsContainer($type));
|
|
|
+ foreach ($typesMap as $category => $className) {
|
|
|
+ $this->container->add($category, new ItemsContainer($className));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public static function init($typesMap)
|
|
|
+ private function __clone()
|
|
|
+ {
|
|
|
+ }
|
|
|
+
|
|
|
+ private function __wakeup()
|
|
|
+ {
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param array $typesMap
|
|
|
+ * @return Registry
|
|
|
+ * @throws RegistryException
|
|
|
+ */
|
|
|
+ public static function init(array $typesMap)
|
|
|
{
|
|
|
- if(static::$instance !== null) {
|
|
|
+ if (static::$instance !== null) {
|
|
|
throw new RegistryException('Registry can be initialized only once.');
|
|
|
}
|
|
|
static::$instance = new static($typesMap);
|
|
|
@@ -33,13 +50,14 @@ class Registry implements RegistryInterface
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * Add item to category of container
|
|
|
* @param string $category
|
|
|
* @param RegistrableItem $item
|
|
|
* @throws RegistryException
|
|
|
*/
|
|
|
public static function add($category, RegistrableItem $item)
|
|
|
{
|
|
|
- if (!static::$instance->container->contains($category)) {
|
|
|
+ if (!static::$instance->container->has($category)) {
|
|
|
throw new RegistryException(strtr('Registry does not contain category "{category}"', [
|
|
|
'{category}' => $category
|
|
|
]));
|
|
|
@@ -48,13 +66,14 @@ class Registry implements RegistryInterface
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * Get category from container
|
|
|
* @param string $category
|
|
|
* @return ItemsContainer
|
|
|
* @throws RegistryException
|
|
|
*/
|
|
|
public static function get($category)
|
|
|
{
|
|
|
- if (!static::$instance->container->contains($category)) {
|
|
|
+ if (!static::$instance->container->has($category)) {
|
|
|
throw new RegistryException(strtr('Registry does not contain category "{category}"', [
|
|
|
'{category}' => $category
|
|
|
]));
|