Perform the attribute conversion process.

@param array $attributes
@param bool $toLdap
@return array
13960
protected function convert(array $attributes, $toLdap = true)
    {
        $direction = $toLdap ? 'toLdap' : 'fromLdap';

        foreach ($attributes as $attribute => $values) {
            // No converter, but the value should still be encoded.
            if (!$this->schema->hasConverter($attribute) && !isset($this->converted[$attribute])) {
                $attributes[$attribute] = $this->encodeValues($values);
            // Only continue if it has a converter and has not already been converted.
            } elseif ($this->schema->hasConverter($attribute) && !in_array($attribute, $this->converted)) {
                $values = $this->getConvertedValues($values, $attribute, $direction);
                if (in_array($attribute, $this->aggregated)) {
                    $attribute = $this->schema->getAttributeToLdap($attribute);
                }
                $attributes[$attribute] = (count($values) == 1) ? reset($values) : $values;
            }
        }

        return $this->removeValuesFromEntry($attributes, array_merge($this->aggregated, $this->remove));
    }
1294069
protected function mergeAttributes(array $attributes)
    {
        foreach ($this->merged as $resource) {
            $attributes = array_replace_recursive($attributes, $resource->getAttributes());
        }

        return $attributes;
    }
1363916
protected function applyDefaultAttrValues(array $attributes = [])
    {
        // Set defaults for each attribute.
        foreach ($this->getMetadata()->getAttributes() as $key => $attrMeta) {
            if (!isset($attrMeta->defaultValue) || isset($attributes[$key])) {
                continue;
            }
            $attributes[$key] = $this->convertAttributeValue($key, $attrMeta->defaultValue);
        }
        return $attributes;
    }
807106
public function replaceAttributes(array $attributes)
    {
        $url = self::makeAttributeUrl();
        $data = json_encode(array("attribute" => $attributes));

        $replaced = $this->service->prepAndSend($url, array(200), 'PUT', $data, true);
        $replaced = json_decode($replaced);
        $result = array();
        foreach ($replaced->attribute as $attr) {
            $result[] = Attribute::createFromJSON($attr);
        }
        return $result;
    }
812301
private function putAttributes($attributes)
	{
		$output = '';

		foreach($attributes as $attribute => $value)
		{
			$output.= ' '.$attribute. '="'.$value.'"';
		}

		return $output;
	}
897165
public function attributes(array $attributes)
    {
        foreach ($attributes as $attribute => &$data) {
            $data = implode(' ', (array) $data);
            $data = $attribute . '="' . htmlspecialchars($data, ENT_QUOTES, 'UTF-8') . '"';
        }

        return empty($attributes) ? '' : ' ' . implode(' ', $attributes);
    }
1098182
public static function mapAttributes($attributes)
    {
        return ' '.implode(' ', array_map(
            function ($sKey) use ($attributes) {
                return is_bool($attributes[$sKey]) ? ($attributes[$sKey] ? $sKey : '') : $sKey.'="'.$attributes[$sKey].'"';
            }, array_keys($attributes)
        ));
    }
1176760
public function toSnakeCase($attributes)
    {
        $convertedAttributes = [];

        foreach ($attributes as $key => $value) {
            $convertedAttributes[$this->getSnakeKey($key)] = $value;
        }

        return $convertedAttributes;
    }
131470
final public function getAttributes($parsed = false) {
        if (!is_array($this->attributes)) {
            $this->attributes = array();
        }
        return ($parsed) ? $this->parseAttributes() : $this->attributes;
    }
221620
protected function attributes(array $attributes): string
	{
		$attr = '';

		foreach($attributes as $attribute => $value)
		{
			if(is_int($attribute))
			{
				$attribute = $value;
			}

			$attr .= ' ' . $attribute . '="' . $value . '"';
		}

		return $attr;
	}
1323195
public function toArray($attributes = null)
    {
        $result = null;

        $excluded_attributes = self::$_manager->getExcludedAttributes($this);

        if (is_null($attributes)) {
            $result = get_object_vars($this);
        } else {
            $result = array_intersect_key(get_object_vars($this), $attributes);
        }        

        foreach ($excluded_attributes as $excluded_attribute) { 
            unset($result[$excluded_attribute]);
        }

        if (in_array('_last', $result)) {
            unset($result['_last']);
        }
        
        foreach ($result as $key => $value) { 
            if (empty($value)) { 
                unset($result[$key]);
            }
        }

        return $result;
    
    }
160453
protected function attributes($attributes = [])
    {
        $ar = [];

        foreach ($attributes as $key => $value) {
            $element = $this->attribute($key, $value);
            if (!is_null($element)) {
                $ar[] = $element;
            }
        }

        return count($ar) > 0 ? ' '.implode(' ', $ar) : '';
    }
521928
protected function getConvertedValues($values, $attribute, $direction, AttributeConverterInterface $aggregate = null)
    {
        $values = is_array($values) ? $values : [$values];
        $converter = $this->getConverterWithOptions($this->schema->getConverter($attribute), $attribute);

        if (!$aggregate && $converter->getShouldAggregateValues() && $direction == 'toLdap') {
            $values = $this->convertAggregateValues($attribute, $values);
        } else {
            $values = $this->doConvertValues($attribute, $values, $direction, $aggregate);
        }

        return $values;
    }
494891
private function translateAttributes($attributes)
    {
        $translatedAttributes = [];

        foreach ($attributes as $key => $setting) {
            if (array_key_exists($key, $this->attributesTranslate)) {
                $key = $this->attributesTranslate[ $key ];
            }

            $translatedAttributes[ $key ] = $setting;
        }

        return $translatedAttributes;
    }
1115139
public function fill(array $attributes)
    {
        foreach ($attributes as $key => $values) {
            if ($this->isKeyALocale($key)) {
                $this->getTranslationOrNew($key)->fill($values);
                unset($attributes[$key]);
            } else {
                list($attribute, $locale) = $this->getAttributeAndLocale($key);
                if ($this->isTranslationAttribute($attribute) and $this->isKeyALocale($locale)) {
                    $this->getTranslationOrNew($locale)->fill([$attribute => $values]);
                    unset($attributes[$key]);
                }
            }
        }

        return parent::fill($attributes);
    }
482773
public function ldapSchema(array $attributes)
    {
        // Check every attribute to see if it contains 8bit characters and then UTF8 encode them
        array_walk($attributes, [$this->utilities(), 'encode8bit']);

        $adldapSchema = new AdldapSchema($attributes);

        $ldapSchema = new LdapSchema($adldapSchema);

        if ($ldapSchema->countAttributes() === 0) {
            return false;
        }

        // Return a filtered array to remove NULL attributes
        return array_filter($ldapSchema->getAttributes(), function ($attribute) {
            // Only return the attribute if it is not null
            if ($attribute[0] !== null) {
                return $attribute;
            }
        });
    }
850696
public function setAttributes($attributes)
    {
        $attributes = self::prepareAttributes($attributes);
        $watched    = array();
        foreach ($this->watchedAttributes as $watchedKey) {
            if (isset($attributes[$watchedKey])) {
                $this->setAttribute($watchedKey, $attributes[$watchedKey]);
                unset($attributes[$watchedKey]);
            } else {
                $this->removeAttribute($watchedKey);
            }
            if (isset($this->attributes[$watchedKey])) {
                $watched[$watchedKey] = $this->attributes[$watchedKey];
            }
        }
        $this->attributes = array_merge($watched, $attributes);
        return $this;
    }