Improved BC layer for the Ldap component

This commit is contained in:
Charles Sarrazin 2016-03-09 13:30:20 +01:00
parent 728bb0f0c6
commit 97d9cee062
5 changed files with 51 additions and 51 deletions

View File

@ -1,48 +0,0 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Ldap;
use Symfony\Component\Ldap\Exception\ConnectionException;
/**
* Base Ldap interface.
*
* This interface is here for reusability in the BC layer,
* and will be merged in LdapInterface in Symfony 4.0.
*
* @author Charles Sarrazin <charles@sarraz.in>
*
* @internal
*/
interface BaseLdapInterface
{
/**
* Return a connection bound to the ldap.
*
* @param string $dn A LDAP dn
* @param string $password A password
*
* @throws ConnectionException If dn / password could not be bound.
*/
public function bind($dn = null, $password = null);
/**
* Escape a string for use in an LDAP filter or DN.
*
* @param string $subject
* @param string $ignore
* @param int $flags
*
* @return string
*/
public function escape($subject, $ignore = '', $flags = 0);
}

View File

@ -44,6 +44,22 @@ final class LdapClient implements LdapClientInterface
$this->ldap->bind($dn, $password);
}
/**
* {@inheritdoc}
*/
public function query($dn, $query, array $options = array())
{
return $this->ldap->query($dn, $query, $options);
}
/**
* {@inheritdoc}
*/
public function getEntryManager()
{
return $this->ldap->getEntryManager();
}
/**
* {@inheritdoc}
*/

View File

@ -21,9 +21,9 @@ namespace Symfony\Component\Ldap;
*
* @deprecated You should use LdapInterface instead
*/
interface LdapClientInterface extends BaseLdapInterface
interface LdapClientInterface extends LdapInterface
{
/*
/**
* Find a username into ldap connection.
*
* @param string $dn

View File

@ -13,17 +13,28 @@ namespace Symfony\Component\Ldap;
use Symfony\Component\Ldap\Adapter\EntryManagerInterface;
use Symfony\Component\Ldap\Adapter\QueryInterface;
use Symfony\Component\Ldap\Exception\ConnectionException;
/**
* Ldap interface.
*
* @author Charles Sarrazin <charles@sarraz.in>
*/
interface LdapInterface extends BaseLdapInterface
interface LdapInterface
{
const ESCAPE_FILTER = 0x01;
const ESCAPE_DN = 0x02;
/**
* Return a connection bound to the ldap.
*
* @param string $dn A LDAP dn
* @param string $password A password
*
* @throws ConnectionException If dn / password could not be bound.
*/
public function bind($dn = null, $password = null);
/**
* Queries a ldap server for entries matching the given criteria.
*
@ -39,4 +50,15 @@ interface LdapInterface extends BaseLdapInterface
* @return EntryManagerInterface
*/
public function getEntryManager();
/**
* Escape a string for use in an LDAP filter or DN.
*
* @param string $subject
* @param string $ignore
* @param int $flags
*
* @return string
*/
public function escape($subject, $ignore = '', $flags = 0);
}

View File

@ -54,6 +54,16 @@ class LdapClientTest extends \PHPUnit_Framework_TestCase
$this->client->escape('foo', 'bar', 'baz');
}
public function testLdapQuery()
{
$this->ldap
->expects($this->once())
->method('query')
->with('foo', 'bar', array('baz'))
;
$this->client->query('foo', 'bar', array('baz'));
}
public function testLdapFind()
{
$collection = $this->getMock(CollectionInterface::class);