[ 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\Plugins\BBCodes\Configurator; 9 10 use RuntimeException; 11 use s9e\TextFormatter\Configurator\Collections\NormalizedCollection; 12 use s9e\TextFormatter\Configurator\JavaScript\Dictionary; 13 use s9e\TextFormatter\Configurator\Validators\AttributeName; 14 use s9e\TextFormatter\Configurator\Validators\TagName; 15 16 class BBCodeCollection extends NormalizedCollection 17 { 18 /** 19 * {@inheritdoc} 20 */ 21 protected $onDuplicateAction = 'replace'; 22 23 /** 24 * {@inheritdoc} 25 */ 26 protected function getAlreadyExistsException($key) 27 { 28 return new RuntimeException("BBCode '" . $key . "' already exists"); 29 } 30 31 /** 32 * {@inheritdoc} 33 */ 34 protected function getNotExistException($key) 35 { 36 return new RuntimeException("BBCode '" . $key . "' does not exist"); 37 } 38 39 /** 40 * {@inheritdoc} 41 */ 42 public function normalizeKey($key) 43 { 44 return BBCode::normalizeName($key); 45 } 46 47 /** 48 * {@inheritdoc} 49 */ 50 public function normalizeValue($value) 51 { 52 return ($value instanceof BBCode) 53 ? $value 54 : new BBCode($value); 55 } 56 57 /** 58 * {@inheritdoc} 59 * 60 * This method will remove redundant info such as the BBCode's tagName or defaultAttribute values 61 * if they are the same as their default values 62 */ 63 public function asConfig() 64 { 65 $bbcodes = parent::asConfig(); 66 foreach ($bbcodes as $bbcodeName => &$bbcode) 67 { 68 // Remove the tag name if it's the same name as the BBCode 69 if (isset($bbcode['tagName']) 70 && TagName::isValid($bbcodeName) 71 && TagName::normalize($bbcodeName) === $bbcode['tagName']) 72 { 73 unset($bbcode['tagName']); 74 } 75 76 // Remove the defaultAttribute name if it's the same name as the BBCode 77 if (isset($bbcode['defaultAttribute']) 78 && AttributeName::isValid($bbcodeName) 79 && AttributeName::normalize($bbcodeName) === $bbcode['defaultAttribute']) 80 { 81 unset($bbcode['defaultAttribute']); 82 } 83 } 84 unset($bbcode); 85 86 return new Dictionary($bbcodes); 87 } 88 }
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 |