Skip to content

Commit 8002801

Browse files
Rely on iconv and symfony/polyfill-*
1 parent cedfaa0 commit 8002801

File tree

3 files changed

+2
-151
lines changed

3 files changed

+2
-151
lines changed

LdapClient.php

Lines changed: 1 addition & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,7 @@ public function find($dn, $query, $filter = '*')
9797
*/
9898
public function escape($subject, $ignore = '', $flags = 0)
9999
{
100-
if (function_exists('ldap_escape')) {
101-
return ldap_escape($subject, $ignore, $flags);
102-
}
103-
104-
return $this->doEscape($subject, $ignore, $flags);
100+
return ldap_escape($subject, $ignore, $flags);
105101
}
106102

107103
private function connect()
@@ -132,98 +128,4 @@ private function disconnect()
132128

133129
$this->connection = null;
134130
}
135-
136-
/**
137-
* Stub implementation of the {@link ldap_escape()} function of the ldap
138-
* extension.
139-
*
140-
* Escape strings for safe use in LDAP filters and DNs.
141-
*
142-
* @author Chris Wright <ldapi@daverandom.com>
143-
*
144-
* @param string $subject
145-
* @param string $ignore
146-
* @param int $flags
147-
*
148-
* @return string
149-
*
150-
* @see http://stackoverflow.com/a/8561604
151-
*/
152-
private function doEscape($subject, $ignore = '', $flags = 0)
153-
{
154-
$charMaps = $this->getCharmaps();
155-
156-
// Create the base char map to escape
157-
$flags = (int) $flags;
158-
$charMap = array();
159-
160-
if ($flags & self::LDAP_ESCAPE_FILTER) {
161-
$charMap += $charMaps[self::LDAP_ESCAPE_FILTER];
162-
}
163-
164-
if ($flags & self::LDAP_ESCAPE_DN) {
165-
$charMap += $charMaps[self::LDAP_ESCAPE_DN];
166-
}
167-
168-
if (!$charMap) {
169-
$charMap = $charMaps[0];
170-
}
171-
172-
// Remove any chars to ignore from the list
173-
$ignore = (string) $ignore;
174-
175-
for ($i = 0, $l = strlen($ignore); $i < $l; ++$i) {
176-
unset($charMap[$ignore[$i]]);
177-
}
178-
179-
// Do the main replacement
180-
$result = strtr($subject, $charMap);
181-
182-
// Encode leading/trailing spaces if LDAP_ESCAPE_DN is passed
183-
if ($flags & self::LDAP_ESCAPE_DN) {
184-
if ($result[0] === ' ') {
185-
$result = '\\20'.substr($result, 1);
186-
}
187-
188-
if ($result[strlen($result) - 1] === ' ') {
189-
$result = substr($result, 0, -1).'\\20';
190-
}
191-
}
192-
193-
return $result;
194-
}
195-
196-
private function getCharmaps()
197-
{
198-
if (null !== $this->charmaps) {
199-
return $this->charmaps;
200-
}
201-
202-
$charMaps = array(
203-
self::LDAP_ESCAPE_FILTER => array('\\', '*', '(', ')', "\x00"),
204-
self::LDAP_ESCAPE_DN => array('\\', ',', '=', '+', '<', '>', ';', '"', '#'),
205-
);
206-
207-
$charMaps[0] = array();
208-
209-
for ($i = 0; $i < 256; ++$i) {
210-
$charMaps[0][chr($i)] = sprintf('\\%02x', $i);
211-
}
212-
213-
for ($i = 0, $l = count($charMaps[self::LDAP_ESCAPE_FILTER]); $i < $l; ++$i) {
214-
$chr = $charMaps[self::LDAP_ESCAPE_FILTER][$i];
215-
unset($charMaps[self::LDAP_ESCAPE_FILTER][$i]);
216-
$charMaps[self::LDAP_ESCAPE_FILTER][$chr] = $charMaps[0][$chr];
217-
}
218-
219-
for ($i = 0, $l = count($charMaps[self::LDAP_ESCAPE_DN]); $i < $l; ++$i) {
220-
$chr = $charMaps[self::LDAP_ESCAPE_DN][$i];
221-
unset($charMaps[self::LDAP_ESCAPE_DN][$i]);
222-
$charMaps[self::LDAP_ESCAPE_DN][$chr] = $charMaps[0][$chr];
223-
}
224-
225-
$this->charmaps = $charMaps;
226-
227-
return $this->charmaps;
228-
}
229131
}

Tests/LdapClientTest.php

Lines changed: 0 additions & 52 deletions
This file was deleted.

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
],
1818
"require": {
1919
"php": ">=5.3.9",
20+
"symfony/polyfill-php56": "~1.0",
2021
"ext-ldap": "*"
2122
},
2223
"autoload": {

0 commit comments

Comments
 (0)