-
-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TASK: Use value object for
sorting
to simplify codeflow
- Loading branch information
Showing
4 changed files
with
67 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Neos\Workspace\Ui\ViewModel; | ||
|
||
use Neos\Eel\ProtectedContextAwareInterface; | ||
use Neos\Flow\Annotations as Flow; | ||
|
||
#[Flow\Proxy(false)] | ||
final readonly class Sorting implements \JsonSerializable, ProtectedContextAwareInterface | ||
{ | ||
public function __construct( | ||
public string $sortBy, | ||
public bool $sortAscending | ||
) { | ||
if (!in_array($sortBy, ['title'], true)) { | ||
throw new \RuntimeException(sprintf('Invalid sortBy %s specified', $sortBy), 1736344550); | ||
} | ||
} | ||
|
||
public static function fromArray(array $array): self | ||
{ | ||
return new self( | ||
sortBy: $array['sortBy'], | ||
sortAscending: (bool)$array['sortAscending'], | ||
); | ||
} | ||
|
||
public function withInvertedSorting(): self | ||
{ | ||
return new self( | ||
sortBy: $this->sortBy, | ||
sortAscending: !$this->sortAscending | ||
); | ||
} | ||
|
||
public function jsonSerialize(): mixed | ||
{ | ||
return get_object_vars($this); | ||
} | ||
|
||
public function allowsCallOfMethod($methodName) | ||
{ | ||
return in_array($methodName, ['withInvertedSorting', 'jsonSerialize'], true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters