attr

@param string|array $name
@param mixed        $value

@return  string

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

        return HtmlBuilder::buildAttributes($name);
    }
3851
public function attr(string $name, string $value = null)
    {
        if ($value === null) {
            if (isset($this->customAttributes[$name])) {
                return $this->customAttributes[$name];
            }

            throw new SsmlException('Unknown attribute ' . $name . ' in class ' . get_class($this));
        }

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

        return $this;
    }
819986
public function appendAttribute($name, $value, $option = TRUE)
	{
		if (is_array($value)) {
			$prev = isset($this->attrs[$name]) ? (array)$this->attrs[$name] : [];
			$this->attrs[$name] = $value + $prev;

		} elseif ((string)$value === '') {
			$tmp = &$this->attrs[$name]; // appending empty value? -> ignore, but ensure it exists

		} elseif (!isset($this->attrs[$name]) || is_array($this->attrs[$name])) { // needs array
			$this->attrs[$name][$value] = $option;

		} else {
			$this->attrs[$name] = [$this->attrs[$name] => TRUE, $value => $option];
		}

		return $this;
	}
1185140
protected static function convertAttribute($name, $value)
    {
        $isSimpleSelector = !in_array(substr($name, 0, 1), ['^', '!'], true);
        $isSimpleSelector = $isSimpleSelector && (!in_array(substr($name, -1), ['^', '$', '*', '!', '~'], true));

        if ($isSimpleSelector) {
            // if specified only the attribute name
            $xpath = $value === null ? '@'.$name : sprintf('@%s="%s"', $name, $value);

            return $xpath;
        }

        // if the attribute name starts with ^
        // example: *[^data-]
        if (substr($name, 0, 1) === '^') {
            $xpath = sprintf('@*[starts-with(name(), "%s")]', substr($name, 1));

            return $value === null ? $xpath : sprintf('%s="%s"', $xpath, $value);
        }

        // if the attribute name starts with !
        // example: input[!disabled]
        if (substr($name, 0, 1) === '!') {
            $xpath = sprintf('not(@%s)', substr($name, 1));

            return $xpath;
        }

        $symbol = substr($name, -1);
        $name = substr($name, 0, -1);

        switch ($symbol) {
            case '^':
                $xpath = sprintf('starts-with(@%s, "%s")', $name, $value);
                break;
            case '$':
                $xpath = sprintf('substring(@%s, string-length(@%s) - string-length("%s") + 1) = "%s"', $name, $name, $value, $value);
                break;
            case '*':
                $xpath = sprintf('contains(@%s, "%s")', $name, $value);
                break;
            case '!':
                $xpath = sprintf('not(@%s="%s")', $name, $value);
                break;
            case '~':
                $xpath = sprintf('contains(concat(" ", normalize-space(@%s), " "), " %s ")', $name, $value);
                break;
        }

        return $xpath;
    }
1066892
public function attribute( string $attr, string $value ): Tag
    {
        $this->attributes[$attr] = $value;

        return $this;
    }
825228
public function withAttribute($name, $value)
    {
        $attributes = $this->getAttributes();
        if (array_key_exists($name, $attributes) && $attributes[$name] === $value) {
            return $this;
        }

        $attributes[$name] = $value;

        $newInstance = clone $this;
        $newInstance->setAttributes($attributes);
        return $newInstance;
    }
3988
public static function input(string $name, string $value = '', array $attributes = null) : string
    {
        // Set the input name
        $attributes['name'] = $name;

        // Set the input id
        $attributes['id'] = (isset($attributes['id'])) ? $attributes['id'] : $name;

        // Set the input value
        $attributes['value'] = $value;

        if ( ! isset($attributes['type'])) {

            // Default type is text
            $attributes['type'] = 'text';
        }

        return '<input'.Html::attributes($attributes).'>';
    }
1055872
public function getAttribStr($name)
	{
		$value = $this->attributes[$name];
		if ($value === null || $value === false || $name === null) {
			return '';
		}
		if ($value === true) {
			if ($this->element) {
				$class = get_class($this->element);
				if ($class::HTML_MODE) {
					return ' ' . $name;
				}
			}
			$value = $name;
		}
		return ' ' . $name . '="' . $value . '"';
	}
295054
public static function radio($name, $value, $attributes = array())
    {
        $attributes['value'] = $value;
        return self::input('radio', $name, $attributes);
    }
313144
public function addAttribute($name, $value = '')
    {
        $org = $this->getAttribute($name);
        if ($org) {
            $value = trim($org . $value);
        }
        $this->attributes[$name] = $value;
        return $this;
    }
429889
public static function text($name, $value, array $attributes = array())
    {
        $node = new Node\Text();

        if (!is_null($name)) {
            $attributes['name'] = $name;
        }

        if (!is_null($value)) {
            $attributes['value'] = $value;
        }

        return $node->render($attributes);
    }
1247433
public function attribute(string $name, string $value = null) : object
    {
        $this->attributes[$name] = $value;
        return $this;
    }
655783
public function withAttribute($name, $value)
    {
        $request             = clone $this;
        $request->attributes = clone $this->attributes;
        $request->attributes->set($name, $value);

        return $request;
    }
1253091
private static function getHtmlAttribute(string $name, $value): string
    {
        if (!self::isset($value)) {
            return '';
        }

        if ($value === true) {
            return $name;
        }

        if (is_array($value)) {
            $value = self::convertAttributeArrayValue($name, $value);
        }

        return sprintf('%s="%s"', $name, static::escape((string) $value));
    }
55636
public final function withAttribute($name, $value): ServerRequestInterface
   {
       $attributes = $this->attributes;
       $attributes[$name] = $value;
       return $this->with("attributes", $attributes);
   }
1139129
private static function element($name, array $attrs)
    {
        $str = "<$name";

        foreach ($attrs as $name => $value) {
            if ($value === null) {
                continue;
            } elseif ($value === true) {
                $str .= " $name";
            } elseif ($value !== false) {
                $str .= ' '.$name.'="'.htmlspecialchars($value).'"';
            }
        }

        return "$str>";
    }