LdapTools\Resolver\ParameterResolver::getValueForParameters PHP Method

getValueForParameters() protected method

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.
protected getValueForParameters ( array $parameters, array | string $original, array $attributes ) : string
$parameters array All of the parameters found within the value.
$original array | string The original value for the attribute, containing the parameters.
$attributes array 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];
    }