PHP code example of ericgansa / filter-manager-bundle
1. Go to this page and download the library: Download ericgansa/filter-manager-bundle 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/ */
ericgansa / filter-manager-bundle example snippets
EricGansa\FilterManagerBundle\FilterManagerBundle::class => ['all' => true],
use EricGansa\FilterManagerBundle\Filter\FilterManagerTrait;
class ArticleRepository extends ServiceEntityRepository
{
use FilterManagerTrait;
}
use EricGansa\FilterManagerBundle\Filter\FilterManager;
class ArticleController extends AbstractController
{
public function __construct(private readonly FilterManager $filterManager) {}
#[Route('/api/articles', methods: ['GET'])]
public function index(Request $request, ArticleRepository $repository): JsonResponse
{
$articles = $this->filterManager->mapRequestToRepository(
$request,
$repository,
'findByFilterManager' // method from FilterManagerTrait
);
return $this->json($articles);
}
}
$qb = $repository->createQueryBuilder('e');
FilterManager::applyFiltersToQueryBuilder($qb, $filters, 'e');
FilterManager::applyPaginationToQueryBuilder($qb, $pagination, 'e');
// With configured scope (uses bundle config)
$filterManager->applyScopeWithConfig($qb, $scope, $user, 'e');
#[ORM\Entity(repositoryClass: ArticleRepository::class)]
class Article
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private int $id;
#[ORM\Column(type: Types::TEXT)]
private string $description;
#[ORM\ManyToOne(targetEntity: Label::class)]
private Label $label;
#[ORM\ManyToOne(targetEntity: User::class)]
private User $user;
#[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
private \DateTimeImmutable $createdAt;
}
GET /api/articles?title[like]=Symfony&author->name=Alice&date[after]=2024-01-01&page=1&limit=20&scope=mine
GET /api/articles?label->label=Développeur PHP
GET /api/articles?label->label[like]=Développeur
GET /api/articles?createdAt[after]=2026-01-01
GET /api/articles?createdAt[before]=2020-01-01
GET /api/articles?label->label[like]=Développeur&id[from]=3&createdAt[after]=2026-01-01&scope=mine
GET /api/articles?id=>5&description[like]=Expert&scope=all