Fixed issue with legacy client initialization
This commit is contained in:
parent
c7f1f7810c
commit
6804efeeee
@ -11,6 +11,8 @@
|
||||
|
||||
namespace Symfony\Component\Ldap;
|
||||
|
||||
@trigger_error('The '.__NAMESPACE__.'\LdapClient class is deprecated since version 3.1 and will be removed in 4.0. Use the Ldap class directly instead.', E_USER_DEPRECATED);
|
||||
|
||||
/**
|
||||
* @author Grégoire Pineau <lyrixx@lyrixx.info>
|
||||
* @author Francis Besset <francis.besset@gmail.com>
|
||||
@ -24,14 +26,7 @@ final class LdapClient implements LdapClientInterface
|
||||
|
||||
public function __construct($host = null, $port = 389, $version = 3, $useSsl = false, $useStartTls = false, $optReferrals = false, LdapInterface $ldap = null)
|
||||
{
|
||||
$config = array(
|
||||
'host' => $host,
|
||||
'port' => $port,
|
||||
'version' => $version,
|
||||
'useSsl' => (bool) $useSsl,
|
||||
'useStartTls' => (bool) $useStartTls,
|
||||
'optReferrals' => (bool) $optReferrals,
|
||||
);
|
||||
$config = $this->normalizeConfig($host, $port, $version, $useSsl, $useStartTls, $optReferrals);
|
||||
|
||||
$this->ldap = null !== $ldap ? $ldap : Ldap::create('ext_ldap', $config);
|
||||
}
|
||||
@ -98,4 +93,25 @@ final class LdapClient implements LdapClientInterface
|
||||
{
|
||||
return $this->ldap->escape($subject, $ignore, $flags);
|
||||
}
|
||||
|
||||
private function normalizeConfig($host, $port, $version, $useSsl, $useStartTls, $optReferrals)
|
||||
{
|
||||
if ((bool) $useSsl) {
|
||||
$encryption = 'ssl';
|
||||
} elseif ((bool) $useStartTls) {
|
||||
$encryption = 'tls';
|
||||
} else {
|
||||
$encryption = 'none';
|
||||
}
|
||||
|
||||
return array(
|
||||
'host' => $host,
|
||||
'port' => $port,
|
||||
'encryption' => $encryption,
|
||||
'options' => array(
|
||||
'protocol_version' => $version,
|
||||
'referrals' => (bool) $optReferrals,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -177,4 +177,70 @@ class LdapClientTest extends \PHPUnit_Framework_TestCase
|
||||
);
|
||||
$this->assertEquals($expected, $this->client->find('dc=foo,dc=com', 'bar', 'baz'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideConfig
|
||||
*/
|
||||
public function testLdapClientConfig($args, $expected)
|
||||
{
|
||||
$reflObj = new \ReflectionObject($this->client);
|
||||
$reflMethod = $reflObj->getMethod('normalizeConfig');
|
||||
$reflMethod->setAccessible(true);
|
||||
array_unshift($args, $this->client);
|
||||
$this->assertEquals($expected, call_user_func_array(array($reflMethod, 'invoke'), $args));
|
||||
}
|
||||
|
||||
public function provideConfig()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
array('localhost', 389, 3, true, false, false),
|
||||
array(
|
||||
'host' => 'localhost',
|
||||
'port' => 389,
|
||||
'encryption' => 'ssl',
|
||||
'options' => array(
|
||||
'protocol_version' => 3,
|
||||
'referrals' => false,
|
||||
),
|
||||
),
|
||||
),
|
||||
array(
|
||||
array('localhost', 389, 3, false, true, false),
|
||||
array(
|
||||
'host' => 'localhost',
|
||||
'port' => 389,
|
||||
'encryption' => 'tls',
|
||||
'options' => array(
|
||||
'protocol_version' => 3,
|
||||
'referrals' => false,
|
||||
),
|
||||
),
|
||||
),
|
||||
array(
|
||||
array('localhost', 389, 3, false, false, false),
|
||||
array(
|
||||
'host' => 'localhost',
|
||||
'port' => 389,
|
||||
'encryption' => 'none',
|
||||
'options' => array(
|
||||
'protocol_version' => 3,
|
||||
'referrals' => false,
|
||||
),
|
||||
),
|
||||
),
|
||||
array(
|
||||
array('localhost', 389, 3, false, false, false),
|
||||
array(
|
||||
'host' => 'localhost',
|
||||
'port' => 389,
|
||||
'encryption' => 'none',
|
||||
'options' => array(
|
||||
'protocol_version' => 3,
|
||||
'referrals' => false,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user