| 1 | <?php |
||
| 8 | class DoctrineEntityRepositoryCrudService extends EntityRepository implements CrudServiceInterface |
||
| 9 | { |
||
| 10 | 18 | public function __construct($entityManager, $entityClass) |
|
| 14 | |||
| 15 | /** |
||
| 16 | * {@inheritdoc} |
||
| 17 | */ |
||
| 18 | 14 | public function findById($id) |
|
| 19 | { |
||
| 20 | 14 | if ($this->isUuid($id)) { |
|
| 21 | return $this->findOneBy(['uuid' => $id]); |
||
| 22 | } |
||
| 23 | |||
| 24 | 14 | return $this->find($id); |
|
| 25 | } |
||
| 26 | |||
| 27 | /** |
||
| 28 | * {@inheritdoc} |
||
| 29 | */ |
||
| 30 | 4 | public function listPaginated(int $page, int $perPage = 50): Paginator |
|
| 38 | |||
| 39 | 14 | protected function isUuid($id) |
|
| 40 | { |
||
| 41 | 14 | return 1 === preg_match('/^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$/', $id); |
|
| 42 | } |
||
| 43 | |||
| 44 | /** |
||
| 45 | * {@inheritdoc} |
||
| 46 | */ |
||
| 47 | public function create($entity) |
||
| 54 | |||
| 55 | /** |
||
| 56 | * {@inheritdoc} |
||
| 57 | */ |
||
| 58 | 2 | public function update($entity) |
|
| 59 | { |
||
| 60 | 2 | $this->getEntityManager()->flush($entity); |
|
| 61 | |||
| 62 | 2 | return $entity; |
|
| 63 | } |
||
| 64 | |||
| 65 | /** |
||
| 66 | * {@inheritdoc} |
||
| 67 | */ |
||
| 68 | public function remove($entity) |
||
| 73 | } |
||
| 74 |