35 lines
755 B
PHP
35 lines
755 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\UI\DTO;
|
|
|
|
class OrderDTO
|
|
{
|
|
public function __construct(public readonly string $column, public readonly OrderDirection $direction)
|
|
{
|
|
}
|
|
|
|
/**
|
|
* @param array<int, string> $acceptColumns
|
|
*/
|
|
public static function createOrReturnNullFromData(?string $order, ?string $direction, array $acceptColumns = []): ?OrderDTO
|
|
{
|
|
if ($order === null || $direction === null) {
|
|
return null;
|
|
}
|
|
|
|
if (!in_array($order, $acceptColumns, true)) {
|
|
return null;
|
|
}
|
|
|
|
$direction = OrderDirection::tryFrom($direction);
|
|
|
|
if ($direction === null) {
|
|
return null;
|
|
}
|
|
|
|
return new self($order, $direction);
|
|
}
|
|
}
|