array_change_key_case() public static method

Change the keys in an array to their lower-case values.
public static array_change_key_case ( array $values ) : array
$values array
return array
示例#1
0
 /**
  * Make sure that the current attribute has actually been defined.
  *
  * @throws AttributeConverterException
  */
 protected function validateCurrentAttribute()
 {
     if (!array_key_exists(MBString::strtolower($this->getAttribute()), MBString::array_change_key_case($this->getOptions()))) {
         throw new AttributeConverterException(sprintf('Attribute "%s" must be defined in the converter options.', $this->getAttribute()));
     }
 }
示例#2
0
 /**
  * Checks to make sure all required attributes are present.
  *
  * @param array $attributes
  */
 protected function validateAttributesToLdap(array $attributes)
 {
     if (!$this->schema) {
         return;
     }
     $missing = [];
     foreach ($this->schema->getRequiredAttributes() as $attribute) {
         if (!array_key_exists(MBString::strtolower($attribute), MBString::array_change_key_case($attributes))) {
             $missing[] = $attribute;
         }
     }
     if (!empty($missing)) {
         throw new LogicException(sprintf('The following required attributes are missing: %s', implode(', ', $missing)));
     }
 }
示例#3
0
 /**
  * Determine how to get the value for the attribute from the LDAP entry being compared, and return that value.
  *
  * @param array|LdapObject $entry
  * @param string $attribute
  * @return mixed
  */
 protected function getComparisonValue($entry, $attribute)
 {
     $alias = null;
     if (!empty($this->aliases)) {
         list($alias, $attribute) = LdapUtilities::getAliasAndAttribute($attribute);
     }
     $value = '';
     if (is_array($entry) && isset($entry[$attribute])) {
         $value = $entry[$attribute];
         // Be forgiving if they are hydrating to an array and the case of the attribute was not correct.
     } elseif (is_array($entry) && array_key_exists(MBString::strtolower($attribute), MBString::array_change_key_case($entry))) {
         $value = MBString::array_change_key_case($entry)[MBString::strtolower($attribute)];
         // Only get the value if there is no alias requested, or if an alias was requested the object type must match the alias.
     } elseif ($entry instanceof LdapObject && (!$alias || $entry->isType($this->aliases[$alias]->getObjectType())) && $entry->has($attribute)) {
         $value = $entry->get($attribute);
     }
     // How to handle multi-valued attributes? This will at least prevent errors, but may not be accurate.
     $value = is_array($value) ? reset($value) : $value;
     return $this->convertValueToString($value);
 }
示例#4
0
 /**
  * @param string $propName
  * @return TSProperty
  */
 protected function getTsPropObj($propName)
 {
     return MBString::array_change_key_case($this->tsProperty)[MBString::strtolower($propName)];
 }
 /**
  * Get the value of an array key in a case-insensitive way.
  *
  * @param array $options
  * @param string $key
  */
 protected function getArrayValue(array $options, $key)
 {
     return MBString::array_change_key_case($options)[MBString::strtolower($key)];
 }
示例#6
0
 /**
  * Given an attribute name, this will get the attribute that LDAP is expecting for that name.
  *
  * @param string $attribute
  * @return string
  */
 public function getAttributeToLdap($attribute)
 {
     return $this->hasAttribute($attribute) ? MBString::array_change_key_case($this->attributeMap)[MBString::strtolower($attribute)] : $attribute;
 }
示例#7
0
 /**
  * @param string $attribute
  * @return int
  */
 protected function getBitForAttribute($attribute)
 {
     $bit = MBString::array_change_key_case($this->getOptions()['typeMap'])[MBString::strtolower($attribute)];
     $bit = in_array($this->getAttribute(), $this->getOptions()['types']['type']) ? -1 * abs($bit) : $bit;
     return $bit;
 }
示例#8
0
 /**
  * Takes all parameters (%username%, %someParameter%) within an attribute value and first checks for explicitly
  * set values for the parameter, then checks to see if the parameter name is a different attribute. If found it
  * takes the value either explicitly set or of the other attribute and replaces it within the original attribute.
  *
  * @param array $parameters All of the parameters found within the value.
  * @param array|string $original The original value for the attribute, containing the parameters.
  * @param array $attributes  All of the attributes being sent to LDAP.
  * @return string The attribute value after the passed parameters have been set.
  */
 protected function getValueForParameters(array $parameters, $original, array $attributes)
 {
     $wasArray = is_array($original);
     $original = $wasArray ? $original : [$original];
     foreach (array_keys($original) as $index) {
         foreach ($parameters as $parameter) {
             $value = '';
             // Explicitly set parameters values will take precedence
             if (array_key_exists(MBString::strtolower($parameter), MBString::array_change_key_case($this->parameters))) {
                 $value = array_change_key_case($this->parameters)[MBString::strtolower($parameter)];
             } elseif (array_key_exists(MBString::strtolower($parameter), MBString::array_change_key_case($attributes))) {
                 $value = MBString::array_change_key_case($attributes)[MBString::strtolower($parameter)];
             }
             if (is_array($value) && count($value) !== 1) {
                 throw new InvalidArgumentException(sprintf('Cannot use a multi-valued attribute "%s" as a parameter.', $parameter));
             }
             $value = is_array($value) && count($value) == 1 ? reset($value) : $value;
             $original[$index] = preg_replace("/" . self::PARAM_MARKER . $parameter . self::PARAM_MARKER . "/", $value, $original[$index]);
         }
     }
     return $wasArray ? $original : $original[0];
 }
 /**
  * Check whether the attribute name was selected to be returned but is not yet part of the entry. Adjusts the check
  * to be case insensitive.
  *
  * @param string $attribute
  * @param array $entry
  * @return bool
  */
 protected function selectedButNotPartOfEntry($attribute, array $entry)
 {
     $lcAttribute = MBString::strtolower($attribute);
     $inSelectedAttributes = in_array($lcAttribute, MBString::array_change_value_case($this->selectedAttributes));
     $existsInEntry = array_key_exists($lcAttribute, MBString::array_change_key_case($entry));
     return $inSelectedAttributes && !$existsInEntry;
 }
示例#10
0
 /**
  * Get the value of an attribute. An attribute with multiple values will return an array of values.
  *
  * @param string $attribute
  * @return mixed
  */
 public function get($attribute)
 {
     if ($this->has($attribute)) {
         return MBString::array_change_key_case($this->attributes)[MBString::strtolower($attribute)];
     } else {
         throw new InvalidArgumentException(sprintf('Attribute "%s" is not defined for this LDAP object.', $attribute));
     }
 }