PHP code example of digipolisgent / doctrine-extra
1. Go to this page and download the library: Download digipolisgent/doctrine-extra library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
digipolisgent / doctrine-extra example snippets
class OrderRepository extends \Doctrine\ORM\EntityRepository
{
/** Resolves filters **/
use Resolver;
public function filter($filters)
{
$builder = $this->createQueryBuilder('root');
return $this->resolve($filters, $builder)->getQuery()->getResult();
}
}
/**
* @var OrderRepository
*/
private $repository;
public function categoryAction($category)
{
$orders = $this->repository->filter(new PropertyFilter($category, 'category'));
}
class CategoryFilter extends AbstractFilter
{
public function createExpression($root)
{
return $this->expr()->eq(
sprintf('%s.category', $root),
$this->expr()->literal($this->parameter)
);
}
}
class UserEmailFilter extends AbstractFilter
{
public function createExpression($root)
{
return $this->expr()->eq('user.email', $this->expr()->literal($this->parameter));
}
public function getAlias()
{
return 'user';
}
public function addAlias(QueryBuilder $builder, $root)
{
$builder->leftJoin(sprintf('%s.user', $root), 'user');
}
}
class OrderRepository extends EntityRepository
{
use Assertable;
public function getOrdersByCategory($category)
{
$builder = $this->createQueryBuilder('root');
$builder->andWhere('root.category = :category');
$builder->setParameter('category', $category);
return $this->assertResult($builder);
}
}