Mercurial > hg > isophonics-drupal-site
comparison vendor/zendframework/zend-stdlib/src/PriorityList.php @ 12:7a779792577d
Update Drupal core to v8.4.5 (via Composer)
author | Chris Cannam |
---|---|
date | Fri, 23 Feb 2018 15:52:07 +0000 |
parents | 4c8ae668cc8c |
children |
comparison
equal
deleted
inserted
replaced
11:bfffd8d7479a | 12:7a779792577d |
---|---|
60 * | 60 * |
61 * @return void | 61 * @return void |
62 */ | 62 */ |
63 public function insert($name, $value, $priority = 0) | 63 public function insert($name, $value, $priority = 0) |
64 { | 64 { |
65 if (!isset($this->items[$name])) { | 65 if (! isset($this->items[$name])) { |
66 $this->count++; | 66 $this->count++; |
67 } | 67 } |
68 | 68 |
69 $this->sorted = false; | 69 $this->sorted = false; |
70 | 70 |
83 * | 83 * |
84 * @throws \Exception | 84 * @throws \Exception |
85 */ | 85 */ |
86 public function setPriority($name, $priority) | 86 public function setPriority($name, $priority) |
87 { | 87 { |
88 if (!isset($this->items[$name])) { | 88 if (! isset($this->items[$name])) { |
89 throw new \Exception("item $name not found"); | 89 throw new \Exception("item $name not found"); |
90 } | 90 } |
91 | 91 |
92 $this->items[$name]['priority'] = (int) $priority; | 92 $this->items[$name]['priority'] = (int) $priority; |
93 $this->sorted = false; | 93 $this->sorted = false; |
129 * @param string $name | 129 * @param string $name |
130 * @return mixed | 130 * @return mixed |
131 */ | 131 */ |
132 public function get($name) | 132 public function get($name) |
133 { | 133 { |
134 if (!isset($this->items[$name])) { | 134 if (! isset($this->items[$name])) { |
135 return; | 135 return; |
136 } | 136 } |
137 | 137 |
138 return $this->items[$name]['data']; | 138 return $this->items[$name]['data']; |
139 } | 139 } |
143 * | 143 * |
144 * @return void | 144 * @return void |
145 */ | 145 */ |
146 protected function sort() | 146 protected function sort() |
147 { | 147 { |
148 if (!$this->sorted) { | 148 if (! $this->sorted) { |
149 uasort($this->items, [$this, 'compare']); | 149 uasort($this->items, [$this, 'compare']); |
150 $this->sorted = true; | 150 $this->sorted = true; |
151 } | 151 } |
152 } | 152 } |
153 | 153 |
159 * @return int | 159 * @return int |
160 */ | 160 */ |
161 protected function compare(array $item1, array $item2) | 161 protected function compare(array $item1, array $item2) |
162 { | 162 { |
163 return ($item1['priority'] === $item2['priority']) | 163 return ($item1['priority'] === $item2['priority']) |
164 ? ($item1['serial'] > $item2['serial'] ? -1 : 1) * $this->isLIFO | 164 ? ($item1['serial'] > $item2['serial'] ? -1 : 1) * $this->isLIFO |
165 : ($item1['priority'] > $item2['priority'] ? -1 : 1); | 165 : ($item1['priority'] > $item2['priority'] ? -1 : 1); |
166 } | 166 } |
167 | 167 |
168 /** | 168 /** |
169 * Get/Set serial order mode | 169 * Get/Set serial order mode |