for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Dontdrinkandroot\Service;
use Doctrine\ORM\Tools\Pagination\Paginator;
use Dontdrinkandroot\Repository\CrudRepositoryInterface;
/**
* @author Philip Washington Sorst <[email protected]>
*/
class RepositoryCrudService implements CrudServiceInterface
{
* @var CrudRepositoryInterface
private $repository;
public function __construct(CrudRepositoryInterface $repository)
$this->repository = $repository;
}
* {@inheritdoc}
public function find($id): ?object
return $this->getRepository()->find($id);
public function findAll(): array
return $this->getRepository()->findAll();
public function findAllPaginated(int $page = 1, int $perPage = 50): Paginator
return $this->getRepository()->findPaginatedBy($page, $perPage);
public function create(object $entity): object
return $this->getRepository()->persist($entity, true);
public function update(object $entity): object
$this->getRepository()->flush($entity);
return $entity;
public function save(object $entity): object
return $this->getRepository()->merge($entity, true);
public function remove(object $entity): void
$this->getRepository()->remove($entity, true);
protected function getRepository(): CrudRepositoryInterface
return $this->repository;