[ Index ]

PHP Cross Reference of phpBB-3.3.14-deutsch

title

Body

[close]

/vendor/s9e/text-formatter/src/Configurator/Validators/ -> AttributeName.php (source)

   1  <?php
   2  
   3  /**
   4  * @package   s9e\TextFormatter
   5  * @copyright Copyright (c) 2010-2022 The s9e authors
   6  * @license   http://www.opensource.org/licenses/mit-license.php The MIT License
   7  */
   8  namespace s9e\TextFormatter\Configurator\Validators;
   9  
  10  use InvalidArgumentException;
  11  
  12  /**
  13  * Attribute name rules:
  14  *  - must start with a letter or an underscore
  15  *  - can only contain letters, numbers, underscores and dashes
  16  *
  17  * Unprefixed names are normalized to uppercase. Prefixed names are preserved as-is.
  18  */
  19  abstract class AttributeName
  20  {
  21      /**
  22      * Return whether a string is a valid attribute name
  23      *
  24      * @param  string $name
  25      * @return bool
  26      */
  27  	public static function isValid($name)
  28      {
  29          return (bool) preg_match('#^(?!xmlns$)[a-z_][-a-z_0-9]*$#Di', $name);
  30      }
  31  
  32      /**
  33      * Normalize a tag name
  34      *
  35      * @throws InvalidArgumentException if the original name is not valid
  36      *
  37      * @param  string $name Original name
  38      * @return string       Normalized name
  39      */
  40  	public static function normalize($name)
  41      {
  42          if (!static::isValid($name))
  43          {
  44              throw new InvalidArgumentException("Invalid attribute name '" . $name . "'");
  45          }
  46  
  47          return strtolower($name);
  48      }
  49  }


Generated: Mon Nov 25 19:05:08 2024 Cross-referenced by PHPXref 0.7.1