19 declare(strict_types=1);
30 public const ASC =
'ASC';
31 public const DESC =
'DESC';
38 public function __construct(
string $subject,
string $direction)
41 $this->order[$subject] = $direction;
46 if (array_key_exists($subject, $this->order)) {
47 throw new \InvalidArgumentException(
"already sorted by subject '$subject'", 1);
53 if ($direction !== self::ASC && $direction !== self::DESC) {
54 throw new \InvalidArgumentException(
"Direction bust be Order::ASC or Order::DESC.", 1);
58 public function append(
string $subject,
string $direction):
Order 63 $clone->order[$subject] = $direction;
70 public function get(): array
75 public function join($init, callable $fn)
78 foreach ($this->order as $key => $value) {
79 $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)