repository = $repository; } /** * @param int $id * @return \databox */ public function find($id) { $this->load(); if (! isset($this->databoxes[$id])) { return null; } return $this->databoxes[$id]; } /** * @return \databox[] */ public function findAll() { $this->load(); return $this->databoxes; } /** * @param \databox $databox */ public function save(\databox $databox) { $this->loaded = false; $this->databoxes = []; return $this->repository->save($databox); } private function load() { if (! $this->loaded) { $this->databoxes = $this->repository->findAll(); $this->loaded = true; } } }