Verzeichnisstruktur phpBB-3.3.15
- Veröffentlicht
- 28.08.2024
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
AttributePreprocessorCollection.php
001 <?php
002
003 /**
004 * @package s9e\TextFormatter
005 * @copyright Copyright (c) 2010-2022 The s9e authors
006 * @license http://www.opensource.org/licenses/mit-license.php The MIT License
007 */
008 namespace s9e\TextFormatter\Configurator\Collections;
009
010 use InvalidArgumentException;
011 use s9e\TextFormatter\Configurator\Helpers\RegexpParser;
012 use s9e\TextFormatter\Configurator\Items\AttributePreprocessor;
013 use s9e\TextFormatter\Configurator\Items\Regexp;
014 use s9e\TextFormatter\Configurator\JavaScript\RegexpConvertor;
015 use s9e\TextFormatter\Configurator\Validators\AttributeName;
016
017 class AttributePreprocessorCollection extends Collection
018 {
019 /**
020 * Add an attribute preprocessor
021 *
022 * @param string $attrName Original name
023 * @param string $regexp Preprocessor's regexp
024 * @return AttributePreprocessor
025 */
026 public function add($attrName, $regexp)
027 {
028 $attrName = AttributeName::normalize($attrName);
029
030 $k = serialize([$attrName, $regexp]);
031 $this->items[$k] = new AttributePreprocessor($regexp);
032
033 return $this->items[$k];
034 }
035
036 /**
037 * @return string Name of the attribute the attribute processor uses as source
038 */
039 public function key()
040 {
041 list($attrName) = unserialize(key($this->items));
042
043 return $attrName;
044 }
045
046 /**
047 * Merge a set of attribute preprocessors into this collection
048 *
049 * @param array|AttributePreprocessorCollection $attributePreprocessors Instance of AttributePreprocessorCollection or 2D array of [[attrName,regexp|AttributePreprocessor]]
050 */
051 public function merge($attributePreprocessors)
052 {
053 $error = false;
054
055 if ($attributePreprocessors instanceof AttributePreprocessorCollection)
056 {
057 foreach ($attributePreprocessors as $attrName => $attributePreprocessor)
058 {
059 $this->add($attrName, $attributePreprocessor->getRegexp());
060 }
061 }
062 elseif (is_array($attributePreprocessors))
063 {
064 // This should be a list where each element is a [attrName,regexp] pair, or
065 // [attrName,AttributePreprocessor]
066 foreach ($attributePreprocessors as $values)
067 {
068 if (!is_array($values))
069 {
070 $error = true;
071 break;
072 }
073
074 list($attrName, $value) = $values;
075
076 if ($value instanceof AttributePreprocessor)
077 {
078 $value = $value->getRegexp();
079 }
080
081 $this->add($attrName, $value);
082 }
083 }
084 else
085 {
086 $error = true;
087 }
088
089 if ($error)
090 {
091 throw new InvalidArgumentException('merge() expects an instance of AttributePreprocessorCollection or a 2D array where each element is a [attribute name, regexp] pair');
092 }
093 }
094
095 /**
096 * {@inheritdoc}
097 */
098 public function asConfig()
099 {
100 $config = [];
101
102 foreach ($this->items as $k => $ap)
103 {
104 list($attrName) = unserialize($k);
105 $config[] = [$attrName, $ap, $ap->getCaptureNames()];
106 }
107
108 return $config;
109 }
110 }