PHP code example of requestum / symfony-api-edition
1. Go to this page and download the library: Download requestum/symfony-api-edition 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/ */
# YourBundle\Repository\CountryRepository.php
class CountryRepository extends EntityRepository implements FilterableRepositoryInterface
{
use ApiRepositoryTrait;
...
/**
* @inheritdoc
*/
protected function createHandlers()
{
return [
new SearchHandler([
'language',
'cities.name', // use the dot for fields of related entities
'president_full_name' => ['president.firstName', 'president.lastName'] //use array to concatenate fields
])
];
}
...
}
# YourBundle\Repository\CountryRepository.php
use Doctrine\ORM\EntityRepository;
use Requestum\ApiBundle\Repository\ApiRepositoryTrait;
use Requestum\ApiBundle\Repository\FilterableRepositoryInterface;
class CountryRepository extends EntityRepository implements FilterableRepositoryInterface
{
use ApiRepositoryTrait;
/**
* @return array
*/
protected function getPathAliases()
{
return [
...
'city' => '[cities][id]',
...
];
}
}
# YourBundle\Filter\CustomFilteHandler
use Requestum\ApiBundle\Filter\Handler\AbstractHandler;
class CustomFilteHandler extends AbstractHandler
{
public function handle(QueryBuilder $builder, $filter, $value)
{
... // Some filter logic
}
protected function getFilterKey()
{
return 'customFilterName'; // filter name
}
}
# YourBundle\Repository\CountryRepository.php
class CountryRepository extends EntityRepository implements FilterableRepositoryInterface
{
use ApiRepositoryTrait;
...
/**
* @inheritdoc
*/
protected function createHandlers()
{
return [
new CustomFilterHandler()
];
}
...
}