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 |
NormalizedList.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
012 class NormalizedList extends NormalizedCollection
013 {
014 /**
015 * Add (append) a value to this list
016 *
017 * Alias for append(). Overrides NormalizedCollection::add()
018 *
019 * @param mixed $value Original value
020 * @param null $void Unused
021 * @return mixed Normalized value
022 */
023 public function add($value, $void = null)
024 {
025 return $this->append($value);
026 }
027
028 /**
029 * Append a value to this list
030 *
031 * @param mixed $value Original value
032 * @return mixed Normalized value
033 */
034 public function append($value)
035 {
036 $value = $this->normalizeValue($value);
037
038 $this->items[] = $value;
039
040 return $value;
041 }
042
043 /**
044 * Delete a value from this list and remove gaps in keys
045 *
046 * NOTE: parent::offsetUnset() maps to $this->delete() so this method covers both usages
047 *
048 * @param string $key
049 * @return void
050 */
051 public function delete($key)
052 {
053 parent::delete($key);
054
055 // Reindex the array to eliminate any gaps
056 $this->items = array_values($this->items);
057 }
058
059 /**
060 * Insert a value at an arbitrary 0-based position
061 *
062 * @param integer $offset
063 * @param mixed $value
064 * @return mixed Normalized value
065 */
066 public function insert($offset, $value)
067 {
068 $offset = $this->normalizeKey($offset);
069 $value = $this->normalizeValue($value);
070
071 // Insert the value at given offset. We put the value into an array so that array_splice()
072 // won't insert it as multiple elements if it happens to be an array
073 array_splice($this->items, $offset, 0, [$value]);
074
075 return $value;
076 }
077
078 /**
079 * Ensure that the key is a valid offset
080 *
081 * Negative values count from the end of the list
082 *
083 * @param mixed $key
084 * @return integer
085 */
086 public function normalizeKey($key)
087 {
088 $normalizedKey = filter_var(
089 (preg_match('(^-\\d+$)D', $key)) ? count($this->items) + $key : $key,
090 FILTER_VALIDATE_INT,
091 [
092 'options' => [
093 'min_range' => 0,
094 'max_range' => count($this->items)
095 ]
096 ]
097 );
098
099 if ($normalizedKey === false)
100 {
101 throw new InvalidArgumentException("Invalid offset '" . $key . "'");
102 }
103
104 return $normalizedKey;
105 }
106
107 /**
108 * Custom offsetSet() implementation to allow assignment with a null offset to append to the
109 * chain
110 *
111 * @param mixed $offset
112 * @param mixed $value
113 * @return void
114 */
115 public function offsetSet($offset, $value): void
116 {
117 if ($offset === null)
118 {
119 // $list[] = 'foo' maps to $list->append('foo')
120 $this->append($value);
121 }
122 else
123 {
124 // Use the default implementation
125 parent::offsetSet($offset, $value);
126 }
127 }
128
129 /**
130 * Prepend a value to this list
131 *
132 * @param mixed $value
133 * @return mixed Normalized value
134 */
135 public function prepend($value)
136 {
137 $value = $this->normalizeValue($value);
138
139 array_unshift($this->items, $value);
140
141 return $value;
142 }
143
144 /**
145 * Remove all items matching given value
146 *
147 * @param mixed $value Original value
148 * @return integer Number of items removed
149 */
150 public function remove($value)
151 {
152 $keys = array_keys($this->items, $this->normalizeValue($value));
153 foreach ($keys as $k)
154 {
155 unset($this->items[$k]);
156 }
157
158 $this->items = array_values($this->items);
159
160 return count($keys);
161 }
162 }