Skip to content
Snippets Groups Projects
Order.php 849 B
Newer Older
Pavel's avatar
Pavel committed
<?php

namespace IQDEV\ElasticSearch\Order;

use IQDEV\ElasticSearch\Esable;
Nikita Chernykh's avatar
Nikita Chernykh committed
use IQDEV\ElasticSearch\Document\Property\Type;
Pavel's avatar
Pavel committed

Nikita Chernykh's avatar
Nikita Chernykh committed
class Order implements Esable
Pavel's avatar
Pavel committed
{
Nikita Chernykh's avatar
Nikita Chernykh committed
    public Type $by;
Pavel's avatar
Pavel committed
    public OrderType $direction;
    public array $properties;

Nikita Chernykh's avatar
Nikita Chernykh committed
    public function __construct(Type $by, OrderType $direction, array $properties = [])
Pavel's avatar
Pavel committed
    {
        $this->by = $by;
        $this->direction = $direction;
        $this->properties = $properties;
    }

    public function es(): array
    {
Nikita Chernykh's avatar
Nikita Chernykh committed
        return array_merge([$this->by->key() => $this->direction::getType()], $this->properties);
    }

    public function orderBy(): Type
    {
        return $this->by;
    }

    public function orderType(): OrderType
    {
        return $this->direction;
    }

    public function orderProperties(): array
    {
        return $this->properties;
Pavel's avatar
Pavel committed
    }
}