CoreFiles by mySites.guru
Entry.php121 lines, 2,923 bytes, from Joomla_6.1.3-Stable-Full_Package.zip
Raw History Compare with 6.1.2
md5
98026cc3a7936536fdcf8da9275e8190
sha1
c33e23764a42a6b20ba6fb20f5f80eea2c9c91a0
sha256
dc753141e5025034c0298ac727e89c5a3f05a6118aff0aaed91ca7622932f27d
<?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
{
    /**
     * @var array<string, array>
     */
    private array $attributes = [];

    /**
     * @var array<string, string>
     */
    private array $lowerMap = [];

    /**
     * @param array<string, array> $attributes
     */
    public function __construct(
        private string $dn,
        array $attributes = [],
    ) {
        foreach ($attributes as $key => $attribute) {
            $this->setAttribute($key, $attribute);
        }
    }

    /**
     * Returns the entry's DN.
     */
    public function getDn(): string
    {
        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
     */
    public function hasAttribute(string $name, bool $caseSensitive = true): bool
    {
        $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
     */
    public function getAttribute(string $name, bool $caseSensitive = true): ?array
    {
        $attributeKey = $this->getAttributeKey($name, $caseSensitive);

        if (null === $attributeKey) {
            return null;
        }

        return $this->attributes[$attributeKey] ?? null;
    }

    /**
     * Returns the complete list of attributes.
     */
    public function getAttributes(): array
    {
        return $this->attributes;
    }

    /**
     * Sets a value for the given attribute.
     */
    public function setAttribute(string $name, array $value): void
    {
        $this->attributes[$name] = $value;
        $this->lowerMap[strtolower($name)] = $name;
    }

    /**
     * Removes a given attribute.
     */
    public function removeAttribute(string $name): void
    {
        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 49 releases, Joomla 6.0.0-beta1 to 6.3.0-alpha1. See them all, or every version of this file.