PHP code example of nebkam / odm-search-param

1. Go to this page and download the library: Download nebkam/odm-search-param 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/ */

    

nebkam / odm-search-param example snippets


class SearchFilter
{
    #[SearchParam(type: SearchParamType::String)]
    public string $name;
}

$builder->field('name')->equals($propertyValue);

class SearchFilter
{
    #[SearchParam(type: SearchParamType::Exists, field: 'images')]
    public bool $hasImages;
}

$builder->field('images')->exists(true);

class SearchFilter
{
    #[SearchParam(type: SearchParamType::Int)]
    public $age;
}

$builder->field('age')->equals((int) $propertyValue);

class SearchFilter
{
    /**
    * @var int[] 
    */
    #[SearchParam(type: SearchParamType::IntArray)]
    public array $grades;
}

$builder->field('grades')->in($propertyValuesAllCastedToInt);

class SearchFilter
{
    #[SearchParam(type: SearchParamType::StringEnum)]
    public SideOfTheWorldEnum $sideOfTheWorld;
}

$builder->field('sideOfTheWorld')->equals($propertyValue->value);

class SearchFilter
{
    /**
    * @var SideOfTheWorldEnum[]
    */
    #[SearchParam(type: SearchParamType::StringEnumArray)]
    public array $sidesOfTheWorld;
}

$builder->field('sideOfTheWorld')->in($backingValuesOfPropertyValue);

class SearchFilter
{
    #[SearchParam(type: SearchParamType::RangeInt, direction: SearchParamDirection::From)]
    public int $price;
}

$builder->field('price')->gte((int) $propertyValue);

class SearchFilter
{
    #[SearchParam(type: SearchParamType::Callable, callable: [SomeClass::class, 'setStatus'])]
    public string $status;
}

class SomeClass
{
    public static function setStatus(Builder|MatchStage $builder, $value, $filter)
    {
    // Call $builder methods to build the query
    }
}