| [ Index ] |
PHP Cross Reference of phpBB-3.3.14-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Zend Framework (http://framework.zend.com/) 4 * 5 * @link http://github.com/zendframework/zend-eventmanager for the canonical source repository 6 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 7 * @license https://github.com/zendframework/zend-eventmanager/blob/master/LICENSE.md 8 */ 9 10 namespace Zend\EventManager\Filter; 11 12 use Zend\EventManager\Exception; 13 use Zend\Stdlib\FastPriorityQueue; 14 15 /** 16 * Specialized priority queue implementation for use with an intercepting 17 * filter chain. 18 * 19 * Allows removal 20 */ 21 class FilterIterator extends FastPriorityQueue 22 { 23 /** 24 * Does the queue contain a given value? 25 * 26 * @param mixed $datum 27 * @return bool 28 */ 29 public function contains($datum) 30 { 31 foreach ($this as $item) { 32 if ($item === $datum) { 33 return true; 34 } 35 } 36 return false; 37 } 38 39 /** 40 * Insert a value into the queue. 41 * 42 * Requires a callable. 43 * 44 * @param callable $value 45 * @param mixed $priority 46 * @return void 47 * @throws Exception\InvalidArgumentException for non-callable $value. 48 */ 49 public function insert($value, $priority) 50 { 51 if (! is_callable($value)) { 52 throw new Exception\InvalidArgumentException(sprintf( 53 '%s can only aggregate callables; received %s', 54 __CLASS__, 55 (is_object($value) ? get_class($value) : gettype($value)) 56 )); 57 } 58 parent::insert($value, $priority); 59 } 60 61 /** 62 * Remove a value from the queue 63 * 64 * This is an expensive operation. It must first iterate through all values, 65 * and then re-populate itself. Use only if absolutely necessary. 66 * 67 * @param mixed $datum 68 * @return bool 69 */ 70 public function remove($datum) 71 { 72 $this->setExtractFlags(self::EXTR_BOTH); 73 74 // Iterate and remove any matches 75 $removed = false; 76 $items = []; 77 $this->rewind(); 78 while (! $this->isEmpty()) { 79 $item = $this->extract(); 80 if ($item['data'] === $datum) { 81 $removed = true; 82 continue; 83 } 84 $items[] = $item; 85 } 86 87 // Repopulate 88 foreach ($items as $item) { 89 $this->insert($item['data'], $item['priority']); 90 } 91 92 $this->setExtractFlags(self::EXTR_DATA); 93 return $removed; 94 } 95 96 /** 97 * Iterate the next filter in the chain 98 * 99 * Iterates and calls the next filter in the chain. 100 * 101 * @param mixed $context 102 * @param array $params 103 * @param FilterIterator $chain 104 * @return mixed 105 */ 106 public function next($context = null, array $params = [], $chain = null) 107 { 108 if (empty($context) || ($chain instanceof FilterIterator && $chain->isEmpty())) { 109 return; 110 } 111 112 //We can't extract from an empty heap 113 if ($this->isEmpty()) { 114 return; 115 } 116 117 $next = $this->extract(); 118 return $next($context, $params, $chain); 119 } 120 }
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 |