| [ Index ] |
PHP Cross Reference of phpBB-3.3.14-deutsch |
[Summary view] [Print] [Text view]
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 * Tag name rules: 14 * - must start with a letter or an underscore 15 * - can only contain letters, numbers, dashes and underscores 16 * - can be prefixed with one prefix following the same rules, separated with one colon 17 * - the prefixes "xsl" and "s9e" are reserved 18 * 19 * Unprefixed names are normalized to uppercase. Prefixed names are preserved as-is. 20 */ 21 abstract class TagName 22 { 23 /** 24 * Return whether a string is a valid tag name 25 * 26 * @param string $name 27 * @return bool 28 */ 29 public static function isValid($name) 30 { 31 return (bool) preg_match('#^(?:(?!xmlns|xsl|s9e)[a-z_][a-z_0-9]*:)?[a-z_][-a-z_0-9]*$#Di', $name); 32 } 33 34 /** 35 * Normalize a tag name 36 * 37 * @throws InvalidArgumentException if the original name is not valid 38 * 39 * @param string $name Original name 40 * @return string Normalized name 41 */ 42 public static function normalize($name) 43 { 44 if (!static::isValid($name)) 45 { 46 throw new InvalidArgumentException("Invalid tag name '" . $name . "'"); 47 } 48 49 // Non-namespaced tags are uppercased 50 if (strpos($name, ':') === false) 51 { 52 $name = strtoupper($name); 53 } 54 55 return $name; 56 } 57 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Nov 25 19:05:08 2024 | Cross-referenced by PHPXref 0.7.1 |