factory = $factory; $this->store = []; } public function add(ModelInterface $model) { $this->store[$model->identity()] = $model; } public function removeById(AtomInterface $id) { if ($this->has($id)) { unset($this->store[$id->getValue()]); } } public function has(AtomInterface $id) { return isset($this->store[$id->getValue()]) && array_key_exists($id->getValue(), $this->store); } public function update(ModelInterface $model, BagInterface $data) { $updated_model = $this->factory->update($model, $data); $this->store[$model->identity()] = $updated_model; } public function getById(AtomInterface $id) { return $this->has($id) ? $this->store[$id->getValue()] : null; } public function getAll() { return $this->store; } }