| 1 | <?php |
||
| 11 | class Manager implements Contracts\Manager |
||
| 12 | { |
||
| 13 | protected $meta; |
||
| 14 | protected $schema; |
||
| 15 | protected $client; |
||
| 16 | protected $repositores = []; |
||
| 17 | |||
| 18 | 4 | public function __construct(Client $client) |
|
| 22 | |||
| 23 | /** |
||
| 24 | * @return Contracts\Repository |
||
| 25 | */ |
||
| 26 | 4 | public function get($type) |
|
| 27 | { |
||
| 28 | 4 | if (!array_key_exists($type, $this->repositores)) { |
|
| 29 | 4 | $this->repositores[$type] = new Repository($this->getMeta()->get($type)); |
|
| 30 | } |
||
| 31 | 4 | return $this->repositores[$type]; |
|
| 32 | } |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @return Contracts\Entity |
||
| 36 | */ |
||
| 37 | 4 | public function save(Contracts\Entity $entity) |
|
| 38 | { |
||
| 39 | 4 | foreach ($this->repositores as $repository) { |
|
| 40 | 4 | if ($repository->knows($entity)) { |
|
| 41 | 4 | return $repository->save($entity); |
|
| 42 | } |
||
| 43 | } |
||
| 44 | |||
| 45 | throw new LogicException("Entity should be related with repository"); |
||
| 46 | } |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @return Client |
||
| 50 | */ |
||
| 51 | 4 | public function getClient() |
|
| 55 | |||
| 56 | /** |
||
| 57 | * @return Schema |
||
| 58 | */ |
||
| 59 | 4 | public function getSchema() |
|
| 66 | |||
| 67 | /** |
||
| 68 | * @return Meta |
||
| 69 | */ |
||
| 70 | 4 | public function getMeta() |
|
| 77 | } |
||
| 78 |