コード例 #1
0
 /**
  * Adds an attribute to the name.
  *
  * @param string $name  The attribute name. Must start with a letter and
  *                      contain letters, digits and hyphens only.
  * @param string $value The attribute value. Any non-empty string is
  *                      allowed.
  *
  * @see merge()
  */
 public function add($name, $value)
 {
     Assert::string($name, 'The attribute name must be a string. Got: %s');
     Assert::notEmpty($name, 'The attribute name must not be empty.');
     Assert::startsWithLetter($name, 'The attribute name %s must start with a letter.');
     Assert::true((bool) preg_match('~^[a-zA-Z][a-zA-Z0-9\\-]*$~', $name), sprintf('The attribute name must contain letters, numbers and hyphens only. Got: "%s"', $name));
     Assert::string($value, 'The attribute value must be a string. Got: %s');
     $this->attributes[$name] = $value;
 }