Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • vendor/search_dc
1 result
Show changes
Commits on Source (8)
Showing
with 444 additions and 0 deletions
.DS_Store
/composer.lock
/vendor/
/.idea/
\ No newline at end of file
{
"name": "iqdev/search-dc",
"description": "Declaring the search structure",
"minimum-stability": "stable",
"license": "proprietary",
"authors": [
{
"name": "Pavel Piligrimov",
"email": "p.piligrimov@iqdev.digital"
}
],
"type": "library",
"keywords": [
"search",
"declaring",
"php"
],
"require": {
"php": ">=7.4",
"ramsey/collection": "^1.2"
},
"autoload": {
"psr-4": {
"IQDEV\\Search\\": "src/Search/"
}
}
}
<?php
namespace IQDEV\Search;
use IQDEV\Search\Filter\FilterCollection;
use IQDEV\Search\Order\OrderCollection;
final class Criteria
{
private FilterCollection $filters;
private OrderCollection $sorting;
private Pagination $pagination;
public function __construct()
{
$this->filters = new FilterCollection();
$this->sorting = new OrderCollection();
$this->pagination = new Pagination();
}
public function filters(): FilterCollection
{
return $this->filters;
}
public function sorting(): OrderCollection
{
return $this->sorting;
}
public function pagination(): Pagination
{
return $this->pagination;
}
}
<?php
namespace IQDEV\Search\Document;
final class Product
{
public string $id;
public string $title;
public array $info;
public function __construct(
string $id,
string $title,
array $info = []
)
{
$this->id = $id;
$this->title = $title;
$this->info = $info;
}
}
<?php
namespace IQDEV\Search\Document;
use Ramsey\Collection\AbstractCollection;
/**
* @extends AbstractCollection<Product>
*/
final class ProductCollection extends AbstractCollection
{
public function getType(): string
{
return Product::class;
}
}
<?php
namespace IQDEV\Search\Document\Property;
class AttrType implements Type
{
protected string $key;
protected ?string $type;
public function __construct(string $key, ?string $type = null)
{
$this->key = $key;
$this->type = $type;
}
public function key(): string
{
return $this->key;
}
public function type(): ?string
{
return $this->type;
}
public static function types(): array
{
return [];
}
}
\ No newline at end of file
<?php
namespace IQDEV\Search\Document\Property;
class PropertyType implements Type
{
protected string $key;
protected string $type;
public const TYPE_NUMBER = 'number';
public const TYPE_KEYWORD = 'keyword';
public function __construct(string $key, string $type = null)
{
if (!in_array($type, self::types(), true)) {
throw new \InvalidArgumentException(sprintf('Invalid type "%s" for property "%s"', $type, $key));
}
$this->key = $key;
$this->type = $type;
}
public function key(): string
{
return $this->key;
}
public function type(): string
{
return $this->type;
}
public static function types(): array
{
return [
self::TYPE_NUMBER,
self::TYPE_KEYWORD,
];
}
}
<?php
namespace IQDEV\Search\Document\Property;
interface Type
{
public function key(): string;
public function type(): ?string;
/** @return string[] */
public static function types(): array;
}
<?php
namespace IQDEV\Search\Facet;
use IQDEV\Search\Facet\Item\FacetItemCollection;
use IQDEV\Search\Facet\Type\FacetType;
final class Facet
{
public FacetItemCollection $products;
protected FacetType $type;
protected string $code;
public function __construct(FacetType $type, string $code)
{
$this->type = $type;
$this->code = $code;
$this->products = new FacetItemCollection();
}
public function getType(): FacetType
{
return $this->type;
}
public function getCode(): string
{
return $this->code;
}
}
<?php
namespace IQDEV\Search\Facet;
use Ramsey\Collection\AbstractCollection;
final class FacetCollection extends AbstractCollection
{
public function getType(): string
{
return Facet::class;
}
}
<?php
namespace IQDEV\Search\Facet\Item;
abstract class FacetItem
{
protected ?string $label = null;
protected ?string $value = null;
protected bool $selected = false;
protected int $count = 0;
abstract public static function create(): self;
public function getLabel(): ?string
{
return $this->label;
}
public function getValue(): ?string
{
return $this->value;
}
public function getCount(): int
{
return $this->count;
}
public function isActive(): bool
{
return $this->count > 0;
}
public function isSelected(): bool
{
return $this->selected;
}
}
<?php
namespace IQDEV\Search\Facet\Item;
use Ramsey\Collection\AbstractCollection;
class FacetItemCollection extends AbstractCollection
{
public function getType(): string
{
return FacetItem::class;
}
}
<?php
namespace IQDEV\Search\Facet\Item;
class FacetItemList extends FacetItem
{
public static function create(
?string $value = null,
int $count = 0,
bool $selected = false,
?string $label = null
): self
{
$instance = new self();
$instance->value = $value;
$instance->label = $label;
$instance->count = $count;
$instance->selected = $selected;
return $instance;
}
}
<?php
namespace IQDEV\Search\Facet\Item;
class FacetItemRange extends FacetItem
{
protected FacetItemRangeDTO $data;
protected ?FacetItemRangeDTO $selectedData;
public static function create(
FacetItemRangeDTO $data = null,
FacetItemRangeDTO $selectedData = null,
int $count = 0,
bool $selected = false,
?string $label = null
): self
{
$instance = new self();
$instance->label = $label;
$instance->count = $count;
$instance->selected = $selected;
$instance->data = $data;
$instance->selectedData = $selectedData;
return $instance;
}
public function getFullRange(): array
{
return [
'min' => $this->data->min,
'max' => $this->data->max
];
}
public function getSelectedRange(): array
{
return [
'min' => $this->selectedData->min,
'max' => $this->selectedData->max
];
}
public function getData(): FacetItemRangeDTO
{
return $this->data;
}
public function getSelectedData(): FacetItemRangeDTO
{
return $this->selectedData;
}
}
<?php
namespace IQDEV\Search\Facet\Item;
class FacetItemRangeDTO
{
public ?float $min = null;
public ?float $max = null;
public ?float $avg = null;
public ?float $sum = null;
public static function create(?float $min = null, ?float $max = null, ?float $avg = null, ?float $sum = null): self
{
$instance = new self();
$instance->min = $min;
$instance->max = $max;
$instance->avg = $avg;
$instance->sum = $sum;
return $instance;
}
}
\ No newline at end of file
<?php
namespace IQDEV\Search\Facet\Item;
class FacetItemSingle extends FacetItem
{
public static function create(?string $value = null, int $count = 0, ?string $label = null): self
{
$instance = new self();
$instance->value = $value;
$instance->count = $count;
$instance->label = $label;
return $instance;
}
}
<?php
namespace IQDEV\Search\Facet\Type;
class FacetListType implements FacetType
{
}
\ No newline at end of file
<?php
namespace IQDEV\Search\Facet\Type;
class FacetRangeType implements FacetType
{
}
<?php
namespace IQDEV\Search\Facet\Type;
interface FacetType
{
}
<?php
namespace IQDEV\Search\Filter;
final class Field
{
protected string $value;
public function __construct(string $value)
{
$this->value = $value;
}
public function value(): string
{
return $this->value;
}
}