From c59d0453e4a62d65f199ab045e153d9dc92d363b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Jakes=CC=8C?= Date: Fri, 5 Jul 2019 17:03:17 +0200 Subject: [PATCH] Add basic Repository class as a root for other repositories [MAILPOET-2014] --- lib/Doctrine/Repository.php | 75 +++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 lib/Doctrine/Repository.php diff --git a/lib/Doctrine/Repository.php b/lib/Doctrine/Repository.php new file mode 100644 index 0000000000..85ed479f02 --- /dev/null +++ b/lib/Doctrine/Repository.php @@ -0,0 +1,75 @@ +entity_manager = $entity_manager; + $this->class_metadata = $entity_manager->getClassMetadata($this->getEntityClassName()); + $this->doctrine_repository = new DoctrineEntityRepository($this->entity_manager, $this->class_metadata); + } + + /** + * @param array $criteria + * @param array|null $order_by + * @param int|null $limit + * @param int|null $offset + * @return array + */ + function findBy(array $criteria, array $order_by = null, $limit = null, $offset = null) { + return $this->doctrine_repository->findBy($criteria, $order_by, $limit, $offset); + } + + /** + * @param array $criteria + * @param array|null $order_by + * @return object|null + */ + function findOneBy(array $criteria, array $order_by = null) { + return $this->doctrine_repository->findOneBy($criteria, $order_by); + } + + /** + * @param mixed $id + * @return object|null + */ + function findOneById($id) { + return $this->doctrine_repository->find($id); + } + + /** + * @param object $entity + */ + function persist($entity) { + $this->entity_manager->persist($entity); + } + + /** + * @param object $entity + */ + function remove($entity) { + $this->entity_manager->remove($entity); + } + + function flush() { + $this->entity_manager->flush(); + } + + /** + * @return string + */ + abstract protected function getEntityClassName(); +}