| 1 | <?php namespace Nord\Lumen\Search; |
||
| 5 | class Sort |
||
| 6 | { |
||
| 7 | const DIRECTION_ASCENDING = 'asc'; |
||
| 8 | const DIRECTION_DESCENDING = 'desc'; |
||
| 9 | |||
| 10 | /** |
||
| 11 | * @var string |
||
| 12 | */ |
||
| 13 | private $property; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * @var string |
||
| 17 | */ |
||
| 18 | private $direction; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @var array |
||
| 22 | */ |
||
| 23 | private $validDirections = [self::DIRECTION_ASCENDING, self::DIRECTION_DESCENDING]; |
||
| 24 | |||
| 25 | |||
| 26 | /** |
||
| 27 | * Sort constructor. |
||
| 28 | * |
||
| 29 | * @param string $property |
||
| 30 | * @param string $direction |
||
| 31 | */ |
||
| 32 | public function __construct($property, $direction) |
||
| 33 | { |
||
| 34 | $this->setProperty($property); |
||
| 35 | $this->setDirection($direction); |
||
| 36 | } |
||
| 37 | |||
| 38 | |||
| 39 | /** |
||
| 40 | * @return string |
||
| 41 | */ |
||
| 42 | public function getProperty() |
||
| 46 | |||
| 47 | |||
| 48 | /** |
||
| 49 | * @return string |
||
| 50 | */ |
||
| 51 | public function getDirection() |
||
| 55 | |||
| 56 | |||
| 57 | /** |
||
| 58 | * @param string $property |
||
| 59 | */ |
||
| 60 | private function setProperty($property) |
||
| 64 | |||
| 65 | |||
| 66 | /** |
||
| 67 | * @param string $direction |
||
| 68 | * |
||
| 69 | * @throws InvalidArgument |
||
| 70 | */ |
||
| 71 | private function setDirection($direction) |
||
| 79 | } |
||
| 80 |