PHP code example of api-skeletons / doctrine-criteria

1. Go to this page and download the library: Download api-skeletons/doctrine-criteria 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/ */

    

api-skeletons / doctrine-criteria example snippets


use Doctrine\Common\Util\ClassUtils;
use ApiSkeletons\Doctrine\Criteria\Builder as CriteriaBuilder;

$filterArray = [
    [
        'type' => 'eq',
        'field' => 'name',
        'value' => 'Grateful Dead',
    ],
    [
        'type' => 'beginswith',
        'field' => 'state',
        'value' => 'UT',
    ],
];

$orderByArray = [
    [
        'type' => 'field',
        'field' => 'venue',
        'direction' => 'asc',
    ]
];

$criteriaBuilder = $container->get(CriteriaBuilder::class);
$entityClassName = ClassUtils::getRealClass(get_class($collection->first()));
$metadata = $objectManager->getClassMetadata($entityClassName);
$criteria = $criteriaBuilder->create($metadata, $filterArray, $orderByArray);

$filteredCollection = $collection->matching($criteria);

[
    'format' => 'Y-m-d',
    'value' => '2014-02-04',
]

['type' => 'eq', 'field' => 'fieldName', 'value' => 'matchValue']

['type' => 'neq', 'field' => 'fieldName', 'value' => 'matchValue']

['type' => 'lt', 'field' => 'fieldName', 'value' => 'matchValue']

['type' => 'lte', 'field' => 'fieldName', 'value' => 'matchValue']

['type' => 'gt', 'field' => 'fieldName', 'value' => 'matchValue']

['type' => 'gte', 'field' => 'fieldName', 'value' => 'matchValue']

['type' => 'contains', 'field' => 'fieldName', 'value' => 'matchValue']

['type' => 'startswith', 'field' => 'fieldName', 'value' => 'matchValue']

['type' => 'endswith', 'field' => 'fieldName', 'value' => 'matchValue']

['type' => 'memeberof', 'field' => 'fieldName', 'value' => 'matchValue']

['type' => 'in', 'field' => 'fieldName', 'values' => [1, 2, 3]]

['type' => 'notin', 'field' => 'fieldName', 'values' => [1, 2, 3]]

['type' => 'isnull', 'field' => 'fieldName']

['type' => 'field', 'field' => 'fieldName', 'direction' => 'desc']