1<?php 2 3/** 4 * This file is part of the FreeDSx LDAP package. 5 * 6 * (c) Chad Sikorra <Chad.Sikorra@gmail.com> 7 * 8 * For the full copyright and license information, please view the LICENSE 9 * file that was distributed with this source code. 10 */ 11 12namespace FreeDSx\Ldap\Control\Sorting; 13 14/** 15 * Represents a server side sorting request SortKey. 16 * 17 * @author Chad Sikorra <Chad.Sikorra@gmail.com> 18 */ 19class SortKey 20{ 21 /** 22 * @var string 23 */ 24 protected $attribute; 25 26 /** 27 * @var null|string 28 */ 29 protected $orderingRule; 30 31 /** 32 * @var bool 33 */ 34 protected $useReverseOrder; 35 36 /** 37 * @param string $attribute 38 * @param bool $useReverseOrder 39 * @param null|string $orderingRule 40 */ 41 public function __construct(string $attribute, bool $useReverseOrder = false, ?string $orderingRule = null) 42 { 43 $this->attribute = $attribute; 44 $this->orderingRule = $orderingRule; 45 $this->useReverseOrder = $useReverseOrder; 46 } 47 48 /** 49 * @return string 50 */ 51 public function getAttribute(): string 52 { 53 return $this->attribute; 54 } 55 56 /** 57 * @param string $attribute 58 * @return $this 59 */ 60 public function setAttribute(string $attribute) 61 { 62 $this->attribute = $attribute; 63 64 return $this; 65 } 66 67 /** 68 * @return string 69 */ 70 public function getOrderingRule(): ?string 71 { 72 return $this->orderingRule; 73 } 74 75 /** 76 * @param null|string $orderingRule 77 * @return $this 78 */ 79 public function setOrderingRule(?string $orderingRule) 80 { 81 $this->orderingRule = $orderingRule; 82 83 return $this; 84 } 85 86 /** 87 * @return bool 88 */ 89 public function getUseReverseOrder(): bool 90 { 91 return $this->useReverseOrder; 92 } 93 94 /** 95 * @param bool $useReverseOrder 96 * @return $this 97 */ 98 public function setUseReverseOrder(bool $useReverseOrder) 99 { 100 $this->useReverseOrder = $useReverseOrder; 101 102 return $this; 103 } 104 105 /** 106 * Create an ascending sort key. 107 * 108 * @param string $attribute 109 * @param null|string $matchRule 110 * @return SortKey 111 */ 112 public static function ascending(string $attribute, ?string $matchRule = null) 113 { 114 return new self($attribute, false, $matchRule); 115 } 116 117 /** 118 * Create a descending sort key. 119 * 120 * @param string $attribute 121 * @param null|string $matchRule 122 * @return SortKey 123 */ 124 public static function descending(string $attribute, ?string $matchRule = null) 125 { 126 return new self($attribute, true, $matchRule); 127 } 128} 129