| 1 | <?php |
||
| 4 | abstract class AbstractSorter |
||
| 5 | { |
||
| 6 | const ASC_ORDER = 1; |
||
| 7 | const DESC_ORDER = -1; |
||
| 8 | |||
| 9 | /** |
||
| 10 | * @var int |
||
| 11 | */ |
||
| 12 | private $order; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * @param int $order |
||
| 16 | */ |
||
| 17 | 2 | public function __construct($order = self::ASC_ORDER) |
|
| 21 | |||
| 22 | /** |
||
| 23 | * @param mixed $object1 |
||
| 24 | * @param mixed $object2 |
||
| 25 | * @return int |
||
| 26 | */ |
||
| 27 | 2 | public function __invoke($object1, $object2) |
|
| 31 | |||
| 32 | /** |
||
| 33 | * calls the property/method/key to extract the value to sort. |
||
| 34 | * |
||
| 35 | * @param mixed $object |
||
| 36 | * @return mixed |
||
| 37 | */ |
||
| 38 | abstract protected function invoke($object); |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @param mixed $value1 |
||
| 42 | * @param mixed $value2 |
||
| 43 | * @return int |
||
| 44 | */ |
||
| 45 | 2 | private function compare($value1, $value2) |
|
| 52 | |||
| 53 | /** |
||
| 54 | * @param int $value |
||
| 55 | * @return int |
||
| 56 | */ |
||
| 57 | 2 | private function order($value) |
|
| 61 | } |
||
| 62 | |||
| 63 |