@@ -132,7 +132,7 @@ |
||
132 | 132 | return '('.$this->operator[$operator].'('.implode(") (", $parts).')'.implode($other).')'; |
133 | 133 | } else if (!empty($other)) { |
134 | 134 | return '('.$this->operator[$operator].implode($other).')'; |
135 | - }else { |
|
135 | + } else { |
|
136 | 136 | return ''; |
137 | 137 | } |
138 | 138 | } |
@@ -132,7 +132,7 @@ |
||
132 | 132 | return '('.$this->operator[$operator].'('.implode(") (", $parts).')'.implode($other).')'; |
133 | 133 | } else if (!empty($other)) { |
134 | 134 | return '('.$this->operator[$operator].implode($other).')'; |
135 | - }else { |
|
135 | + } else { |
|
136 | 136 | return ''; |
137 | 137 | } |
138 | 138 | } |
@@ -97,10 +97,10 @@ discard block |
||
97 | 97 | |
98 | 98 | $select = (is_array($this->select)) ? $this->select : []; |
99 | 99 | |
100 | - if(ctype_digit((string) $this->limit)){ |
|
100 | + if (ctype_digit((string) $this->limit)) { |
|
101 | 101 | $db->pageSize = $this->limit; |
102 | 102 | } |
103 | - if(ctype_digit((string) $this->offset)){ |
|
103 | + if (ctype_digit((string) $this->offset)) { |
|
104 | 104 | $db->offset = $this->offset == 0 ? 1 : $this->offset; |
105 | 105 | } |
106 | 106 | |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | */ |
118 | 118 | public function all($db = null) |
119 | 119 | { |
120 | - if(!($this->dataReader instanceof DataReader)) { |
|
120 | + if (!($this->dataReader instanceof DataReader)) { |
|
121 | 121 | /** @var $result DataReader */ |
122 | 122 | $this->dataReader = $this->execute($db); |
123 | 123 | } else { |
@@ -125,10 +125,10 @@ discard block |
||
125 | 125 | $db = Yii::$app->get('ldap'); |
126 | 126 | } |
127 | 127 | |
128 | - if(ctype_digit((string) $this->limit)){ |
|
128 | + if (ctype_digit((string) $this->limit)) { |
|
129 | 129 | $db->pageSize = $this->limit; |
130 | 130 | } |
131 | - if(ctype_digit((string) $this->offset)){ |
|
131 | + if (ctype_digit((string) $this->offset)) { |
|
132 | 132 | $db->offset = $this->offset == 0 ? 1 : $this->offset; |
133 | 133 | } |
134 | 134 | } |
@@ -74,10 +74,10 @@ discard block |
||
74 | 74 | */ |
75 | 75 | public function __construct(Connection $conn, $results, $config = []) |
76 | 76 | { |
77 | - $this->_conn = $conn; |
|
77 | + $this->_conn = $conn; |
|
78 | 78 | $this->_results = $results; |
79 | 79 | |
80 | - if(is_array($this->_results)){ |
|
80 | + if (is_array($this->_results)) { |
|
81 | 81 | foreach ($this->_results as $result) { |
82 | 82 | $this->_count += $this->_conn->countEntries($result); |
83 | 83 | //$this->setEntries($result); |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | * @param resource|array $result |
102 | 102 | * @return void |
103 | 103 | */ |
104 | - protected function setEntries($result){ |
|
104 | + protected function setEntries($result) { |
|
105 | 105 | $identifier = $this->_conn->getFirstEntry($result); |
106 | 106 | |
107 | 107 | while (false !== $identifier) { |
@@ -124,12 +124,12 @@ discard block |
||
124 | 124 | return []; |
125 | 125 | } |
126 | 126 | |
127 | - $token = 'Get entries with limit pagination ' . $this->_conn->pageSize; |
|
127 | + $token = 'Get entries with limit pagination '.$this->_conn->pageSize; |
|
128 | 128 | Yii::beginProfile($token, __METHOD__); |
129 | - if($this->_conn->offset > 0){ |
|
130 | - $this->setEntries($this->_results[intval($this->_conn->offset/$this->_conn->pageSize)]); |
|
129 | + if ($this->_conn->offset > 0) { |
|
130 | + $this->setEntries($this->_results[intval($this->_conn->offset / $this->_conn->pageSize)]); |
|
131 | 131 | } else { |
132 | - if(is_array($this->_results)){ |
|
132 | + if (is_array($this->_results)) { |
|
133 | 133 | foreach ($this->_results as $result) { |
134 | 134 | $this->setEntries($result); |
135 | 135 | } |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | } |
140 | 140 | Yii::endProfile($token, __METHOD__); |
141 | 141 | |
142 | - $token = 'Get Attributes of entries with limit pagination in ' . $this->_conn->pageSize; |
|
142 | + $token = 'Get Attributes of entries with limit pagination in '.$this->_conn->pageSize; |
|
143 | 143 | Yii::beginProfile($token, __METHOD__); |
144 | 144 | $data = []; |
145 | 145 | foreach ($this as $item) { |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | */ |
158 | 158 | public function close() |
159 | 159 | { |
160 | - if(is_array($this->_results)){ |
|
160 | + if (is_array($this->_results)) { |
|
161 | 161 | foreach ($this->_results as $result) { |
162 | 162 | $this->_conn->freeResult($result); |
163 | 163 | } |
@@ -26,11 +26,11 @@ |
||
26 | 26 | */ |
27 | 27 | public $dn; |
28 | 28 | |
29 | - /** |
|
30 | - * Returns the list of attribute names. |
|
31 | - * By default, this method returns all public properties of the class. |
|
32 | - * @return array list of attribute names. |
|
33 | - */ |
|
29 | + /** |
|
30 | + * Returns the list of attribute names. |
|
31 | + * By default, this method returns all public properties of the class. |
|
32 | + * @return array list of attribute names. |
|
33 | + */ |
|
34 | 34 | public function getAttributes() { |
35 | 35 | $class = new ReflectionClass(self::class); |
36 | 36 | $names = []; |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | return 0; |
188 | 188 | } |
189 | 189 | |
190 | - if(($condition = $this->getOldPrimaryKey(true)) !== $this->getPrimaryKey(true)) { |
|
190 | + if (($condition = $this->getOldPrimaryKey(true)) !== $this->getPrimaryKey(true)) { |
|
191 | 191 | // TODO Change DN |
192 | 192 | // static::getDb()->rename($condition, $newRdn, $newParent, true); |
193 | 193 | // if (!$this->refresh()){ |
@@ -197,12 +197,12 @@ discard block |
||
197 | 197 | } |
198 | 198 | |
199 | 199 | foreach ($values as $key => $value) { |
200 | - if($key == 'dn'){ |
|
200 | + if ($key == 'dn') { |
|
201 | 201 | continue; |
202 | 202 | } |
203 | - if(empty ($this->getOldAttribute($key)) && $value === ''){ |
|
203 | + if (empty ($this->getOldAttribute($key)) && $value === '') { |
|
204 | 204 | unset($values[$key]); |
205 | - } else if($value === ''){ |
|
205 | + } else if ($value === '') { |
|
206 | 206 | $attributes[] = ['attrib' => $key, 'modtype' => LDAP_MODIFY_BATCH_REMOVE]; |
207 | 207 | } else if (empty ($this->getOldAttribute($key))) { |
208 | 208 | $attributes[] = ['attrib' => $key, 'modtype' => LDAP_MODIFY_BATCH_ADD, 'values' => is_array($value) ? $value : [$value]]; |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | */ |
246 | 246 | public static function updateAll($attributes, $condition = '') |
247 | 247 | { |
248 | - if(is_array($condition)){ |
|
248 | + if (is_array($condition)) { |
|
249 | 249 | $condition = $condition['dn']; |
250 | 250 | } |
251 | 251 |
@@ -133,6 +133,10 @@ discard block |
||
133 | 133 | protected $userDN; |
134 | 134 | |
135 | 135 | # Create AD password (Microsoft Active Directory password format) |
136 | + |
|
137 | + /** |
|
138 | + * @param string $password |
|
139 | + */ |
|
136 | 140 | protected static function encodePassword($password) { |
137 | 141 | $password = "\"" . $password . "\""; |
138 | 142 | $adpassword = mb_convert_encoding($password, "UTF-16LE", "UTF-8"); |
@@ -230,7 +234,7 @@ discard block |
||
230 | 234 | * Authenticate user |
231 | 235 | * @param string $username |
232 | 236 | * @param string $password |
233 | - * @return int indicate occurrence of error. |
|
237 | + * @return boolean indicate occurrence of error. |
|
234 | 238 | */ |
235 | 239 | public function auth($username, $password) |
236 | 240 | { |
@@ -563,8 +567,6 @@ discard block |
||
563 | 567 | |
564 | 568 | /** |
565 | 569 | * Send LDAP pagination control. |
566 | - * @param int $pageSize |
|
567 | - * @param bool $isCritical |
|
568 | 570 | * @param string $cookie |
569 | 571 | * @return bool |
570 | 572 | */ |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | |
135 | 135 | # Create AD password (Microsoft Active Directory password format) |
136 | 136 | protected static function encodePassword($password) { |
137 | - $password = "\"" . $password . "\""; |
|
137 | + $password = "\"".$password."\""; |
|
138 | 138 | $adpassword = mb_convert_encoding($password, "UTF-16LE", "UTF-8"); |
139 | 139 | return $adpassword; |
140 | 140 | } |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | */ |
184 | 184 | public function open($anonymous = false) |
185 | 185 | { |
186 | - $token = 'Opening LDAP connection: ' . LdapUtils::recursive_implode($this->dc, ' or '); |
|
186 | + $token = 'Opening LDAP connection: '.LdapUtils::recursive_implode($this->dc, ' or '); |
|
187 | 187 | Yii::info($token, __METHOD__); |
188 | 188 | Yii::beginProfile($token, __METHOD__); |
189 | 189 | // Connect to the LDAP server. |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | # Search for user and get user DN |
241 | 241 | $searchResult = ldap_search($this->resource, $this->baseDn, "(&(objectClass=person)($this->loginAttribute=$username))", [$this->loginAttribute]); |
242 | 242 | $entry = $this->getFirstEntry($searchResult); |
243 | - if($entry) { |
|
243 | + if ($entry) { |
|
244 | 244 | $this->userDN = $this->getDn($entry); |
245 | 245 | } else { |
246 | 246 | $this->userDN = null; |
@@ -269,7 +269,7 @@ discard block |
||
269 | 269 | } |
270 | 270 | |
271 | 271 | // Open connection with user |
272 | - if(!$this->auth($username, $oldPassword)){ |
|
272 | + if (!$this->auth($username, $oldPassword)) { |
|
273 | 273 | return false; |
274 | 274 | } |
275 | 275 | |
@@ -326,20 +326,20 @@ discard block |
||
326 | 326 | $this->open(); |
327 | 327 | $results = []; |
328 | 328 | $cookie = ''; |
329 | - $token = $function . ' - params: ' . LdapUtils::recursive_implode($params, ';'); |
|
329 | + $token = $function.' - params: '.LdapUtils::recursive_implode($params, ';'); |
|
330 | 330 | |
331 | - Yii::info($token , 'chrmorandi\ldap\Connection::query'); |
|
331 | + Yii::info($token, 'chrmorandi\ldap\Connection::query'); |
|
332 | 332 | |
333 | 333 | Yii::beginProfile($token, 'chrmorandi\ldap\Connection::query'); |
334 | 334 | do { |
335 | - if($this->pageSize > 0) { |
|
335 | + if ($this->pageSize > 0) { |
|
336 | 336 | $this->setControlPagedResult($cookie); |
337 | 337 | } |
338 | 338 | |
339 | 339 | // Run the search. |
340 | 340 | $result = call_user_func($function, $this->resource, ...$params); |
341 | 341 | |
342 | - if($this->pageSize > 0) { |
|
342 | + if ($this->pageSize > 0) { |
|
343 | 343 | $this->setControlPagedResultResponse($result, $cookie); |
344 | 344 | } |
345 | 345 |