taktik-nette
This commit is contained in:
34
app/UI/DTO/OrderDTO.php
Normal file
34
app/UI/DTO/OrderDTO.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user