Creates the different types of attribute values.

@param string $name
The attribute name.
@param mixed $value
The attribute value.

@return \Drupal\Core\Template\AttributeValueBase
An AttributeValueBase representation of the attribute's value.
327533
protected function createAttributeValue($name, $value) {
    // If the value is already an AttributeValueBase object,
    // return a new instance of the same class, but with the new name.
    if ($value instanceof AttributeValueBase) {
      $class = get_class($value);
      return new $class($name, $value->value());
    }
    // An array value or 'class' attribute name are forced to always be an
    // AttributeArray value for consistency.
    if ($name == 'class' && !is_array($value)) {
      // Cast the value to string in case it implements MarkupInterface.
      $value = [(string) $value];
    }
    if (is_array($value)) {
      // Cast the value to an array if the value was passed in as a string.
      // @todo Decide to fix all the broken instances of class as a string
      // in core or cast them.
      $value = new AttributeArray($name, $value);
    }
    elseif (is_bool($value)) {
      $value = new AttributeBoolean($name, $value);
    }
    // As a development aid, we allow the value to be a safe string object.
    elseif (SafeMarkup::isSafe($value)) {
      // Attributes are not supposed to display HTML markup, so we just convert
      // the value to plain text.
      $value = PlainTextOutput::renderFromHtml($value);
      $value = new AttributeString($name, $value);
    }
    elseif (!is_object($value)) {
      $value = new AttributeString($name, $value);
    }
    return $value;
  }
372302
public function addAttribute($name, $value)
    {
        $nameUtf8 = $this->_toUTF8($name);
        $valueUtf8 = htmlspecialchars($this->_toUTF8($value), ENT_COMPAT, "UTF-8");
        if (($valueUtf8 === "") && (version_compare("5.2.2", PHP_VERSION, ">"))) {
            $this->_SimpleXmlElement->addAttribute($nameUtf8, "\0"); // Fixing bug #41175 (addAttribute() fails to add an attribute with an empty value)
        } else {
            $this->_SimpleXmlElement->addAttribute($nameUtf8, $valueUtf8);
        }
    }
391469
public function getValueAttribute($name, $value = null)
    {
        if (is_null($name)) {
            return $value;
        }

        if (!str_contains($name, ['[', ']']) && !is_null($this->old($name))) {
            return $this->old($name);
        }


        if (!is_null($value)) {
            return $value;
        }

        if (isset($this->model)) {
            return $this->getModelValueAttribute($name);
        }
    }
254929
public function withAttribute(string $name, $value = null)
    {
        $this->attributes[$name] = $value;

        return $this;
    }
252849
public function set(string $name, string $value = null): self
    {
        if (null === $value) {
            $this->remove($name);
            return $this;
        }
        if (! Xml::isValidXmlName($name)) {
            throw new \UnexpectedValueException(sprintf('Cannot set attribute with an invalid xml name: "%s"', $name));
        }
        $this->attributes[$name] = $value;
        return $this;
    }
651456
private static function convertValueBasedOnAttributeName($value, $attrName)
    {
        switch ($attrName) {
            case Profile::ATTR_DOCUMENT_DETAILS:
                return new DocumentDetails($value);

            case Profile::ATTR_DOCUMENT_IMAGES:
                if (!($value instanceof MultiValue)) {
                    throw new AttributeException('Document Images could not be decoded');
                }
                return $value
                  ->allowInstance(Image::class)
                  ->immutable();

            default:
                return $value;
        }
    }
547987
public function addAttr($name, $value)
    {
        $name = trim($name);
        $value = trim($value);

        if ($value && !$this->existsAttr($name)) {
            $this->attrs[$name] = $value;
        }

        return $this;
    }
1300851
public function setAttribute($name, $value)
    {
        if(strlen($name) < 1)
        {
            throw new HTMLTagException("Attribute name is empty");
        }

        $this->tag_attributes[strtolower($name)] = $value;

        return $this;
    }
19002
public static function attr($name, $value = null)
    {
        if (is_string($name)) {
            $name = [$name => $value];
        }

        return HtmlBuilder::buildAttributes($name);
    }
1092078
public static function create($attribute, $value)
    {
        $attributesType = self::getAllAttributeType();
        foreach ($attributesType as $attributeType) {
            if ($attributeType->isMember($attribute)) {
                return $attributeType->create($value);
            }
        }

        return $value;
    }
1228487
public function setAttribute( $name, $value )
    {
        if ( isset( $this->dynamicAttributeFunctions[$name] ) )
        {
            switch ( $name )
            {
                case 'valid_nodes':
                    $this->dynamicAttributeFunctions[$name] = $value;
                    break;
                default:
                break;
            }
        }
        else
        {
            $this->attributes[$name] = $value;
        }
    }
1304850
public function createNew(
        string $attribute,
        string $name,
        float $value
    ) : array {
        return $this->sendPost(
            sprintf('/profiles/%s/scores', $this->userName),
            [],
            [
                'attribute' => $attribute,
                'name'      => $name,
                'value'     => $value
            ]
        );
    }
804464
protected function buildValue($value)
    {
        if ($value instanceof Model || is_null($value)) {
            return $value;
        }

        $model = $this->attribute->getAttribute('type');
        $instance = new $model();

        $instance->setAttribute('entity_id', $this->entity->getKey());
        $instance->setAttribute('entity_type', get_class($this->entity));
        $instance->setAttribute($this->attribute->getForeignKey(), $this->attribute->getKey());
        $instance->setAttribute('content', $value);

        return $instance;
    }
430852
public function attr($name, $value = null)
    {
        $attrs = (array) $this->getAttribute('attribs');

        if ($value === null) {
            return isset($attrs[$name]) ? $attrs[$name] : null;
        }

        $attrs[$name] = $value;

        $this->setAttribute('attribs', $attrs);

        return $this;
    }
2282
public function addToAttribute($name, $value)
    {
        $attr = $this->getAttribute($name);
        $this->setAttribute($name, $attr . $value);

        return $this;
    }
667803
public function setAttribute(string $name, string $value) : Element
    {
        $this->getTag()->setAttribute($name, $value);

        return $this;
    }
293299
public function set($name, $value = null)
    {
        if (is_string($name)) {
            $name = $this->cleanAttributeName($name);
            if ($value === null && isset($this->props[$name])) {
                unset($this->props[$name]);
            } elseif ($value !== null) {
                $this->props[$name] = $value;
            }
        }

        return $this;
    }