1 | <?php |
||
13 | class CrudRepository extends EntityRepository implements CrudRepositoryInterface |
||
14 | { |
||
15 | /** |
||
16 | * {@inheritdoc} |
||
17 | */ |
||
18 | 2 | public function persist(object $entity, bool $flush = true): object |
|
28 | |||
29 | /** |
||
30 | * {@inheritdoc} |
||
31 | */ |
||
32 | 4 | public function merge(object $entity, bool $flush = false): object |
|
33 | { |
||
34 | 4 | $entity = $this->getEntityManager()->merge($entity); |
|
35 | |||
36 | 4 | if ($flush) { |
|
37 | 4 | $this->flush($entity); |
|
38 | } |
||
39 | |||
40 | 4 | return $entity; |
|
41 | } |
||
42 | |||
43 | /** |
||
44 | * {@inheritdoc} |
||
45 | */ |
||
46 | 8 | public function flush(object $entity = null): void |
|
50 | |||
51 | /** |
||
52 | * {@inheritdoc} |
||
53 | */ |
||
54 | public function detach(object $entity): void |
||
58 | |||
59 | /** |
||
60 | * {@inheritdoc} |
||
61 | */ |
||
62 | public function removeById($id, bool $flush = false): void |
||
63 | { |
||
64 | /** @var EntityInterface $entity */ |
||
65 | $entity = $this->find($id); |
||
66 | $this->remove($entity, $flush); |
||
67 | } |
||
68 | |||
69 | /** |
||
70 | * {@inheritdoc} |
||
71 | */ |
||
72 | public function remove(object $entity, bool $flush = false): void |
||
73 | { |
||
74 | $this->getEntityManager()->remove($entity); |
||
75 | |||
76 | if ($flush) { |
||
77 | $this->flush($entity); |
||
78 | } |
||
79 | } |
||
80 | |||
81 | /** |
||
82 | * {@inheritdoc} |
||
83 | */ |
||
84 | 4 | public function removeAll(bool $flush = false, bool $iterate = true): void |
|
85 | { |
||
86 | 4 | if ($iterate) { |
|
87 | 2 | $this->removeAllByIterating(); |
|
88 | } else { |
||
89 | 2 | $this->removeAllByQuery(); |
|
90 | } |
||
91 | |||
92 | 4 | if ($flush) { |
|
93 | $this->flush(); |
||
94 | } |
||
95 | 4 | } |
|
96 | |||
97 | /** |
||
98 | * {@inheritdoc} |
||
99 | */ |
||
100 | 2 | public function findPaginatedBy( |
|
124 | |||
125 | /** |
||
126 | * {@inheritdoc} |
||
127 | */ |
||
128 | 6 | public function countAll(): int |
|
137 | |||
138 | 2 | protected function removeAllByIterating(int $batchSize = 100): void |
|
151 | |||
152 | 2 | protected function removeAllByQuery(): void |
|
159 | |||
160 | protected function createBlankQueryBuilder(): QueryBuilder |
||
164 | } |
||
165 |