Skip to content
Snippets Groups Projects
OrderFactory.php 797 B
Newer Older
<?php

namespace IQDEV\ElasticSearch\Order;

use IQDEV\ElasticSearch\Document\Property\Property;
use IQDEV\ElasticSearch\Document\Property\PropertyType;
use IQDEV\ElasticSearch\Order\Type\BaseOrder;
use IQDEV\ElasticSearch\Order\Type\KeywordPropertyOrder;
use IQDEV\ElasticSearch\Order\Type\NumberPropertyOrder;

class OrderFactory
{
    public static function createByProperty(
        Property $property,
        OrderDirection $direction,
    ): Order {
        match ($property->getType()) {
            PropertyType::KEYWORD => $order = new KeywordPropertyOrder($property, $direction),
            PropertyType::NUMBER => $order = new NumberPropertyOrder($property, $direction),
            default => $order = new BaseOrder($property, $direction),
        };

        return $order;
    }
}