- md5
- d1278ba93173570907dc1090a787a9a0
- sha1
- a4d250d40af60fbe8565d2ff61196dfcc40ed989
- sha256
- a45c52f53a4aef50b3e4d84e9ee551e322224896ec12ddcfd778ede59a916910
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Ldap;
/**
* @author Charles Sarrazin <[email protected]>
* @author Karl Shea <[email protected]>
*/
class Entry
{
private $dn;
/**
* @var array<string, array>
*/
private $attributes = [];
/**
* @var array<string, string>
*/
private $lowerMap = [];
/**
* @param array<string, array> $attributes
*/
public function __construct(string $dn, array $attributes = [])
{
$this->dn = $dn;
foreach ($attributes as $key => $attribute) {
$this->setAttribute($key, $attribute);
}
}
/**
* Returns the entry's DN.
*
* @return string
*/
public function getDn()
{
return $this->dn;
}
/**
* Returns whether an attribute exists.
*
* @param string $name The name of the attribute
* @param bool $caseSensitive Whether the check should be case-sensitive
*
* @return bool
*/
public function hasAttribute(string $name/* , bool $caseSensitive = true */)
{
$caseSensitive = 2 > \func_num_args() || true === func_get_arg(1);
$attributeKey = $this->getAttributeKey($name, $caseSensitive);
if (null === $attributeKey) {
return false;
}
return isset($this->attributes[$attributeKey]);
}
/**
* Returns a specific attribute's value.
*
* As LDAP can return multiple values for a single attribute,
* this value is returned as an array.
*
* @param string $name The name of the attribute
* @param bool $caseSensitive Whether the attribute name is case-sensitive
*
* @return array|null
*/
public function getAttribute(string $name/* , bool $caseSensitive = true */)
{
$caseSensitive = 2 > \func_num_args() || true === func_get_arg(1);
$attributeKey = $this->getAttributeKey($name, $caseSensitive);
if (null === $attributeKey) {
return null;
}
return $this->attributes[$attributeKey] ?? null;
}
/**
* Returns the complete list of attributes.
*
* @return array
*/
public function getAttributes()
{
return $this->attributes;
}
/**
* Sets a value for the given attribute.
*/
public function setAttribute(string $name, array $value)
{
$this->attributes[$name] = $value;
$this->lowerMap[strtolower($name)] = $name;
}
/**
* Removes a given attribute.
*/
public function removeAttribute(string $name)
{
unset($this->attributes[$name]);
unset($this->lowerMap[strtolower($name)]);
}
private function getAttributeKey(string $name, bool $caseSensitive = true): ?string
{
if ($caseSensitive) {
return $name;
}
return $this->lowerMap[strtolower($name)] ?? null;
}
}
The same content is in 97 releases, Joomla 4.1.0-beta3 to 4.4.14. See them all, or every version of this file.