LdapTools\Utilities\LdapUtilities::sanitizeAttributeArray PHP Метод

sanitizeAttributeArray() публичный статический Метод

Sanitizes certain values in an attribute key => value array to make them safe for logging (ie. mask passwords, replace binary data).
public static sanitizeAttributeArray ( array $attributes ) : array
$attributes array
Результат array
    public static function sanitizeAttributeArray(array $attributes)
    {
        foreach ($attributes as $name => $values) {
            if (in_array(strtolower($name), self::MASK_ATTRIBUTES)) {
                $attributes[$name] = self::MASK_PASSWORD;
            } else {
                $replaced = false;
                $newValues = is_array($values) ? $values : [$values];
                foreach ($newValues as $i => $v) {
                    if (is_string($v) && self::isBinary($v)) {
                        $newValues[$i] = LdapUtilities::MASK_BINARY;
                        $replaced = true;
                    }
                }
                if ($replaced) {
                    $attributes[$name] = is_array($values) ? $newValues : reset($newValues);
                }
            }
        }
        return $attributes;
    }

Usage Example

Пример #1
0
 /**
  * {@inheritdoc}
  */
 public function getLogArray()
 {
     return $this->mergeLogDefaults(['DN' => $this->properties['dn'], 'Attributes' => print_r(LdapUtilities::sanitizeAttributeArray($this->properties['attributes']), true)]);
 }