<?php
require_once 'ItemPrototypeAbstract.php';
class ItemManager
{
private $_items;
public function __construct()
{
$this->_items = array();
}
public function registItem(ItemPrototypeAbstract $item)
{
$this->_items[$item->getId()] = $item;
}
public function create($id)
{
if (!array_key_exists($id, $this->_items)) {
throw new RuntimeException('ID [' . $id . '] not exists.');
}
$clonedItem = $this->_items[$id]->newInstance();
return $clonedItem;
}
}