PHP code example of mymedia / php-argument-builder
1. Go to this page and download the library: Download mymedia/php-argument-builder 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/ */
mymedia / php-argument-builder example snippets
$builder
->setSearch('foobar')
->setFilter('color', 'iridescent')
->setFilter('size', 'height', 2)
->setFilter('size', 'width', 10);
const ARGUMENT_TYPE_MIXED = 0;
const ARGUMENT_TYPE_ARGUMENT_BUILDER = 1;
const ARGUMENT_TYPE_NUMERIC = 2;
const ARGUMENT_TYPE_ENUM = 3;
const ARGUMENT_TYPE_BOOLEAN = 4;
class SearchArgumentBuilder extends AbstractArgumentBuilder
{
protected $fields = [
'search' => self::ARGUMENT_TYPE_MIXED,
'filter' => SearchFilterArgumentBuilder::class,
];
}
class SearchFilterArgumentBuilder extends AbstractArgumentBuilder
{
protected $fields = [
'color' => self::ARGUMENT_TYPE_MIXED,
'size' => SearchFilterSizeArgumentConverter::class,
];
}
class SearchFilterSizeArgumentBuilder extends AbstractArgumentBuilder
{
protected $fields = [
'height' => self::ARGUMENT_TYPE_MIXED,
'width' => self::ARGUMENT_TYPE_MIXED,
];
}
class SearchFilterPriceArgumentBuilder extends AbstractArgumentBuilder
{
protected function load()
{
$this->fields = array(
'min' => array(
'type' => self::ARGUMENT_TYPE_MIXED,
'validator' => function ($value) {
return $value >= 0 && $value <= 1000;
}
),
'max' => array(
'type' => self::ARGUMENT_TYPE_MIXED,
'validator' => function ($value) {
return $value >= 0 && $value <= 1000;
}
),
);
}
}
bash
$ composer