1 | <?php |
||
14 | class EntityRepository implements ObjectRepository, Selectable |
||
15 | { |
||
16 | /** @var ApiMetadata */ |
||
17 | private $metadata; |
||
18 | /** @var EntityManager */ |
||
19 | private $manager; |
||
20 | |||
21 | /** |
||
22 | * EntityRepository constructor. |
||
23 | * |
||
24 | * @param EntityManager $manager |
||
25 | * @param string $className |
||
26 | */ |
||
27 | 18 | public function __construct(EntityManager $manager, $className) |
|
28 | { |
||
29 | 18 | $this->manager = $manager; |
|
30 | 18 | $this->metadata = $this->manager->getClassMetadata($className); |
|
31 | 18 | } |
|
32 | |||
33 | /** {@inheritdoc} */ |
||
34 | 13 | public function find($id) |
|
38 | |||
39 | /** {@inheritdoc} */ |
||
40 | 17 | public function getClassName() |
|
41 | { |
||
42 | 17 | return $this->metadata->getReflectionClass()->getName(); |
|
|
|||
43 | } |
||
44 | |||
45 | /** {@inheritdoc} */ |
||
46 | 2 | public function findAll() |
|
47 | { |
||
48 | 2 | return $this->findBy([]); |
|
49 | } |
||
50 | |||
51 | /** {@inheritdoc} */ |
||
52 | 5 | public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) |
|
53 | { |
||
54 | 5 | $persister = $this->manager->getUnitOfWork()->getEntityPersister($this->getClassName()); |
|
55 | |||
56 | 5 | return $persister->loadAll($criteria, $orderBy, $limit, $offset); |
|
57 | } |
||
58 | |||
59 | /** {@inheritdoc} */ |
||
60 | public function findOneBy(array $criteria) |
||
61 | { |
||
62 | $objects = $this->findBy($criteria, [], 1); |
||
63 | |||
64 | return array_shift($objects); |
||
65 | } |
||
66 | |||
67 | /** |
||
68 | * @return EntityManager |
||
69 | */ |
||
70 | public function getManager() |
||
71 | { |
||
72 | return $this->manager; |
||
73 | } |
||
74 | |||
75 | /** {@inheritdoc} */ |
||
76 | public function matching(Criteria $criteria) |
||
77 | { |
||
78 | return new LazyCriteriaCollection(new CollectionMatcher($this->getManager(), $this->getApi()), $criteria); |
||
79 | } |
||
80 | |||
81 | /** |
||
82 | * @return RpcClientInterface |
||
83 | */ |
||
84 | 1 | protected function getClient() |
|
85 | { |
||
86 | 1 | return $this->manager->getConfiguration()->getClientRegistry()->get($this->metadata->getClientName()); |
|
87 | } |
||
88 | |||
89 | /** |
||
90 | * @return CrudsApiInterface |
||
91 | */ |
||
92 | protected function getApi() |
||
96 | |||
97 | /** |
||
98 | * @return ApiMetadata |
||
99 | */ |
||
100 | 1 | protected function getMetadata() |
|
101 | { |
||
102 | 1 | return $this->metadata; |
|
103 | } |
||
104 | |||
105 | /** |
||
106 | * Hydrates object from given data or merges it to already fetched object |
||
107 | * |
||
108 | * @param mixed $data |
||
109 | * |
||
110 | * @return object |
||
111 | */ |
||
112 | protected function hydrateObject($data) |
||
116 | |||
117 | /** |
||
118 | * @param string $alias |
||
119 | * |
||
120 | * @return string |
||
121 | * @throws \OutOfBoundsException if no method exist |
||
122 | */ |
||
123 | protected function getClientMethod($alias) |
||
127 | } |
||
128 |