[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/vendor/symfony/ldap/ -> Entry.php (source)

   1  <?php
   2  
   3  /*
   4   * This file is part of the Symfony package.
   5   *
   6   * (c) Fabien Potencier <[email protected]>
   7   *
   8   * For the full copyright and license information, please view the LICENSE
   9   * file that was distributed with this source code.
  10   */
  11  
  12  namespace Symfony\Component\Ldap;
  13  
  14  /**
  15   * @author Charles Sarrazin <[email protected]>
  16   * @author Karl Shea <[email protected]>
  17   */
  18  class Entry
  19  {
  20      private $dn;
  21  
  22      /**
  23       * @var array<string, array>
  24       */
  25      private $attributes = [];
  26  
  27      /**
  28       * @var array<string, string>
  29       */
  30      private $lowerMap = [];
  31  
  32      /**
  33       * @param array<string, array> $attributes
  34       */
  35      public function __construct(string $dn, array $attributes = [])
  36      {
  37          $this->dn = $dn;
  38  
  39          foreach ($attributes as $key => $attribute) {
  40              $this->setAttribute($key, $attribute);
  41          }
  42      }
  43  
  44      /**
  45       * Returns the entry's DN.
  46       *
  47       * @return string
  48       */
  49      public function getDn()
  50      {
  51          return $this->dn;
  52      }
  53  
  54      /**
  55       * Returns whether an attribute exists.
  56       *
  57       * @param string $name          The name of the attribute
  58       * @param bool   $caseSensitive Whether the check should be case-sensitive
  59       *
  60       * @return bool
  61       */
  62      public function hasAttribute(string $name/* , bool $caseSensitive = true */)
  63      {
  64          $caseSensitive = 2 > \func_num_args() || true === func_get_arg(1);
  65          $attributeKey = $this->getAttributeKey($name, $caseSensitive);
  66  
  67          if (null === $attributeKey) {
  68              return false;
  69          }
  70  
  71          return isset($this->attributes[$attributeKey]);
  72      }
  73  
  74      /**
  75       * Returns a specific attribute's value.
  76       *
  77       * As LDAP can return multiple values for a single attribute,
  78       * this value is returned as an array.
  79       *
  80       * @param string $name          The name of the attribute
  81       * @param bool   $caseSensitive Whether the attribute name is case-sensitive
  82       *
  83       * @return array|null
  84       */
  85      public function getAttribute(string $name/* , bool $caseSensitive = true */)
  86      {
  87          $caseSensitive = 2 > \func_num_args() || true === func_get_arg(1);
  88          $attributeKey = $this->getAttributeKey($name, $caseSensitive);
  89  
  90          if (null === $attributeKey) {
  91              return null;
  92          }
  93  
  94          return $this->attributes[$attributeKey] ?? null;
  95      }
  96  
  97      /**
  98       * Returns the complete list of attributes.
  99       *
 100       * @return array
 101       */
 102      public function getAttributes()
 103      {
 104          return $this->attributes;
 105      }
 106  
 107      /**
 108       * Sets a value for the given attribute.
 109       */
 110      public function setAttribute(string $name, array $value)
 111      {
 112          $this->attributes[$name] = $value;
 113          $this->lowerMap[strtolower($name)] = $name;
 114      }
 115  
 116      /**
 117       * Removes a given attribute.
 118       */
 119      public function removeAttribute(string $name)
 120      {
 121          unset($this->attributes[$name]);
 122          unset($this->lowerMap[strtolower($name)]);
 123      }
 124  
 125      private function getAttributeKey(string $name, bool $caseSensitive = true): ?string
 126      {
 127          if ($caseSensitive) {
 128              return $name;
 129          }
 130  
 131          return $this->lowerMap[strtolower($name)] ?? null;
 132      }
 133  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer