| @@ 38-51 (lines=14) @@ | ||
| 35 | * |
|
| 36 | * @throws ObjectClassNotAllowedException |
|
| 37 | */ |
|
| 38 | public function insert(AbstractEntity $object) |
|
| 39 | { |
|
| 40 | if (!$this->getSupport($object)) { |
|
| 41 | throw new ObjectClassNotAllowedException(); |
|
| 42 | } |
|
| 43 | $object->setCreatedAt(new DateTime()); |
|
| 44 | if (method_exists($this, "preInsert")) { |
|
| 45 | $this->preInsert($object); |
|
| 46 | } |
|
| 47 | $this->entityManager->persist($object); |
|
| 48 | $this->flush(); |
|
| 49 | ||
| 50 | return $object; |
|
| 51 | } |
|
| 52 | ||
| 53 | /** |
|
| 54 | * Permet de gérer un flush en mode transactions manuelles. |
|
| @@ 71-83 (lines=13) @@ | ||
| 68 | * |
|
| 69 | * @throws ObjectClassNotAllowedException |
|
| 70 | */ |
|
| 71 | public function update(AbstractEntity $object) |
|
| 72 | { |
|
| 73 | if (!$this->getSupport($object)) { |
|
| 74 | throw new ObjectClassNotAllowedException(); |
|
| 75 | } |
|
| 76 | $object->setUpdatedAt(new DateTime()); |
|
| 77 | if (method_exists($this, "preUpdate")) { |
|
| 78 | $this->preUpdate($object); |
|
| 79 | } |
|
| 80 | $this->flush(); |
|
| 81 | ||
| 82 | return $object; |
|
| 83 | } |
|
| 84 | ||
| 85 | /** |
|
| 86 | * @param Entity $object |
|
| @@ 89-99 (lines=11) @@ | ||
| 86 | * @param Entity $object |
|
| 87 | * @throws ObjectClassNotAllowedException |
|
| 88 | */ |
|
| 89 | public function delete(AbstractEntity $object) |
|
| 90 | { |
|
| 91 | if (!$this->getSupport($object)) { |
|
| 92 | throw new ObjectClassNotAllowedException(); |
|
| 93 | } |
|
| 94 | if (method_exists($this, "preDelete")) { |
|
| 95 | $this->preDelete($object); |
|
| 96 | } |
|
| 97 | $this->entityManager->remove($object); |
|
| 98 | $this->flush(); |
|
| 99 | } |
|
| 100 | ||
| 101 | /** |
|
| 102 | * Finds an entity by its primary key / identifier. |
|