Skip to content
This repository was archived by the owner on Jun 3, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions src/Umber/Database/DatabaseManagerInterface.php

This file was deleted.

16 changes: 0 additions & 16 deletions src/Umber/Database/EntityRepositoryFactoryInterface.php

This file was deleted.

9 changes: 0 additions & 9 deletions src/Umber/Database/EntityRepositoryInterface.php

This file was deleted.

25 changes: 8 additions & 17 deletions src/Umber/Database/Manager/DoctrineDatabaseManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,36 @@

namespace Umber\Database\Manager;

use Umber\Database\DatabaseManagerInterface;
use Umber\Database\EntityRepositoryFactoryInterface;
use Umber\Database\EntityRepositoryInterface;

use Symfony\Bridge\Doctrine\RegistryInterface;

use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\QueryBuilder;

/**
* A doctrine database manager.
*/
final class DoctrineDatabaseManager implements DatabaseManagerInterface
final class DoctrineDatabaseManager
{
private $registry;
private $entityRepositoryFactory;

public function __construct(
RegistryInterface $registry,
EntityRepositoryFactoryInterface $entityRepositoryFactory
) {
public function __construct(RegistryInterface $registry)
{
$this->registry = $registry;
$this->entityRepositoryFactory = $entityRepositoryFactory;
}

/**
* Return the entity manager.
* Return the doctrine entity manager.
*/
public function getEntityManager(): EntityManagerInterface
{
return $this->registry->getEntityManager();
}

/**
* {@inheritdoc}
* Create a doctrine query builder.
*/
public function getRepository(string $entity): EntityRepositoryInterface
public function createQueryBuilder(): QueryBuilder
{
$repository = $this->entityRepositoryFactory->create($entity);

return $repository;
return $this->getEntityManager()->createQueryBuilder();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,31 @@

namespace Umber\Database\Manager\Repository;

use Umber\Database\EntityRepositoryInterface;
use Umber\Database\Manager\DoctrineDatabaseManager;
use Umber\Database\Pagination\PaginatorFactoryInterface;

use Doctrine\Common\Persistence\ObjectRepository;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\QueryBuilder;

/**
* A custom entity repository.
* A custom entity repository that is stripped back.
*/
abstract class AbstractDoctrineEntityRepository implements EntityRepositoryInterface, ObjectRepository
abstract class AbstractDoctrineEntityRepository
{
protected const SORT_ASC = 'ASC';
protected const SORT_DESC = 'DESC';

private $entity;
private $entityManager;
private $database;
private $paginatorFactory;
private $entity;

public function __construct(
string $entity,
EntityManagerInterface $entityManager,
PaginatorFactoryInterface $paginatorFactory
DoctrineDatabaseManager $database,
PaginatorFactoryInterface $paginatorFactory,
string $entity
) {
$this->entity = $entity;
$this->entityManager = $entityManager;
$this->database = $database;
$this->paginatorFactory = $paginatorFactory;
$this->entity = $entity;
}

/**
Expand All @@ -46,62 +44,8 @@ final protected function getPaginatorFactory(): PaginatorFactoryInterface
*/
final protected function createQueryBuilder(string $alias, ?string $indexBy = null): QueryBuilder
{
return $this->entityManager->createQueryBuilder()
return $this->database->createQueryBuilder()
->select($alias)
->from($this->entity, $alias, $indexBy);
}

/**
* {@inheritdoc}
*
* @internal These methods are implemented for the interface, do not consume them.
*/
public function find($id, $lockMode = null, $lockVersion = null)
{
return $this->entityManager->find($this->entity, $id);
}

/**
* {@inheritdoc}
*
* @internal These methods are implemented for the interface, do not consume them.
*/
public function findAll()
{
return $this->findBy([]);
}

/**
* {@inheritdoc}
*
* @internal These methods are implemented for the interface, do not consume them.
*/
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null)
{
$persister = $this->entityManager->getUnitOfWork()->getEntityPersister($this->entity);

return $persister->loadAll($criteria, $orderBy, $limit, $offset);
}

/**
* {@inheritdoc}
*
* @internal These methods are implemented for the interface, do not consume them.
*/
public function findOneBy(array $criteria, ?array $orderBy = null)
{
$persister = $this->entityManager->getUnitOfWork()->getEntityPersister($this->entity);

return $persister->load($criteria, null, null, [], null, 1, $orderBy);
}

/**
* {@inheritdoc}
*
* @internal These methods are implemented for the interface, do not consume them.
*/
public function getClassName()
{
return $this->entity;
}
}

This file was deleted.

6 changes: 5 additions & 1 deletion src/Umber/Database/Pagination/PaginatorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@

namespace Umber\Database\Pagination;

interface PaginatorInterface
use Countable;
use IteratorAggregate;
use Traversable;

interface PaginatorInterface extends Traversable, Countable, IteratorAggregate
{
public function getResultPerPageCount(): int;

Expand Down