3 declare(strict_types=1);
14 public const ASC =
'ASC';
15 public const DESC =
'DESC';
22 public function __construct(
string $subject,
string $direction)
25 $this->order[$subject] = $direction;
30 if (array_key_exists($subject, $this->order)) {
31 throw new \InvalidArgumentException(
"already sorted by subject '$subject'", 1);
37 if ($direction !== self::ASC && $direction !== self::DESC) {
38 throw new \InvalidArgumentException(
"Direction bust be Order::ASC or Order::DESC.", 1);
42 public function append(
string $subject,
string $direction):
Order 47 $clone->order[$subject] = $direction;
54 public function get(): array
59 public function join($init, callable $fn)
62 foreach ($this->order as
$key => $value) {
63 $ret = $fn($ret,
$key, $value);
join($init, callable $fn)
checkDirection(string $direction)
checkSubject(string $subject)
__construct(string $subject, string $direction)
Both the subject and the direction need to be specified when expressing an order. ...
append(string $subject, string $direction)