kyoushu/doctrine-orm-entity-finder

This package is abandoned and no longer maintained. No replacement package was suggested.

Boilerplate for building finder classes to be used with Doctrine ORM

1.0.0 2018-08-23 09:33 UTC

This package is auto-updated.

Last update: 2023-01-15 19:29:07 UTC


README

Build Status

Boilerplate for building finder classes to be used with Doctrine ORM

Class Example

<?php

namespace App;

use Kyoushu\DoctrineORMEntityFinder\Test\AbstractFinder;
use Doctrine\ORM\QueryBuilder;

class MyFinder extends AbstractFinder
{
    
    protected $name;
    
    public function getName()
    {
        return $this->name;
    }
    
    public function setName($name)
    {
        $this->name = $name;
        return $this;
    }
    
    public function getParameterKeys()
    {
        return array('name');
    }
    
    public function getEntityClass()
    {
        return 'App\Entity\MyEntity';        
    }
    
    public function configureQueryBuilder(QueryBuilder $queryBuilder)
    {
        $name = $this->name;
        if($name){
            $queryBuilder->andWhere('entity.name = :name');
            $queryBuilder->setParameter('name', $name);
        }
    }
    
}

Usage Example

<?php

namespace App;

use Kyoushu\DoctrineORMEntityFinder\FinderFactory;

// Create finder factory
$factory = new FinderFactory($entityManager);

// Register finder class
$factory->registerFinder('my_finder', 'App\MyFinder');

// Create finder and configure it to find entities named Foo
$finder = $factory->createFinder('my_finder');
$finder->setPage(1)->setPerPage(5)->setName('Foo');

// Get search results
$result = $finder->getResult();

// Generate a URL using parameters from the finder
$url = $router->generate('search', $finder->getRouteParameters());