forked from NIBLCO/nibl.co.uk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
dyzajash
committed
Jan 18, 2021
1 parent
25850a9
commit a5a1948
Showing
13 changed files
with
197 additions
and
38 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,3 +21,4 @@ Thumbs.db | |
*.db | ||
.php_cs.cache | ||
config/settings.local.php | ||
*.log |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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,15 @@ | ||
<?php | ||
|
||
namespace App\Domain; | ||
|
||
use MyCLabs\Enum\Enum; | ||
|
||
/** | ||
* @method static SortDirectionEnum ASC() | ||
* @method static SortDirectionEnum DESC() | ||
*/ | ||
final class SortDirectionEnum extends Enum | ||
{ | ||
private const ASC = 'ASC'; | ||
private const DESC = 'DESC'; | ||
} |
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,45 @@ | ||
<?php | ||
|
||
namespace App\Domain; | ||
|
||
final class SortDto | ||
{ | ||
private const DEFAULT_SORT = 'name'; | ||
private const ALLOWED_SORT_PARAMS = ['name', 'number', 'size', 'sizekbits', 'episodeNumber']; | ||
private string $by; | ||
private SortDirectionEnum $direction; | ||
|
||
private function __construct(string $by, SortDirectionEnum $sortDirectionEnum) | ||
{ | ||
$this->by = $by; | ||
$this->direction = $sortDirectionEnum; | ||
} | ||
|
||
public static function fromRequest(array $params): self | ||
{ | ||
$by = self::DEFAULT_SORT; | ||
$direction = SortDirectionEnum::ASC(); | ||
|
||
$byParam = $params['by']; | ||
if (isset($byParam) && in_array($byParam, self::ALLOWED_SORT_PARAMS, true)) { | ||
$by = $byParam; | ||
} | ||
|
||
$directionParam = strtoupper($params['direction']); | ||
if (isset($directionParam) && in_array($directionParam, SortDirectionEnum::toArray(), true)) { | ||
$direction = new SortDirectionEnum($directionParam); | ||
} | ||
|
||
return new self($by, $direction); | ||
} | ||
|
||
public function getDirection(): SortDirectionEnum | ||
{ | ||
return $this->direction; | ||
} | ||
|
||
public function getBy(): string | ||
{ | ||
return $this->by; | ||
} | ||
} |
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
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
Oops, something went wrong.