File indexing completed on 2024-06-16 05:30:00
0001 <?php 0002 /** 0003 * Zend Framework 0004 * 0005 * LICENSE 0006 * 0007 * This source file is subject to the new BSD license that is bundled 0008 * with this package in the file LICENSE.txt. 0009 * It is also available through the world-wide-web at this URL: 0010 * http://framework.zend.com/license/new-bsd 0011 * If you did not receive a copy of the license and are unable to 0012 * obtain it through the world-wide-web, please send an email 0013 * to license@zend.com so we can send you a copy immediately. 0014 * 0015 * @category Zend 0016 * @package Zend_EventManager 0017 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0018 * @license http://framework.zend.com/license/new-bsd New BSD License 0019 */ 0020 0021 // require_once 'Zend/Stdlib/CallbackHandler.php'; 0022 // require_once 'Zend/Stdlib/SplPriorityQueue.php'; 0023 0024 /** 0025 * Specialized priority queue implementation for use with an intercepting 0026 * filter chain. 0027 * 0028 * Allows removal 0029 * 0030 * @category Zend 0031 * @package Zend_EventManager 0032 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0033 * @license http://framework.zend.com/license/new-bsd New BSD License 0034 */ 0035 class Zend_EventManager_Filter_FilterIterator extends Zend_Stdlib_SplPriorityQueue 0036 { 0037 /** 0038 * Does the queue contain a given value? 0039 * 0040 * @param mixed $datum 0041 * @return bool 0042 */ 0043 public function contains($datum) 0044 { 0045 $chain = clone $this; 0046 foreach ($chain as $item) { 0047 if ($item === $datum) { 0048 return true; 0049 } 0050 } 0051 return false; 0052 } 0053 0054 /** 0055 * Remove a value from the queue 0056 * 0057 * This is an expensive operation. It must first iterate through all values, 0058 * and then re-populate itself. Use only if absolutely necessary. 0059 * 0060 * @param mixed $datum 0061 * @return bool 0062 */ 0063 public function remove($datum) 0064 { 0065 $this->setExtractFlags(self::EXTR_BOTH); 0066 0067 // Iterate and remove any matches 0068 $removed = false; 0069 $items = array(); 0070 $this->rewind(); 0071 while (!$this->isEmpty()) { 0072 $item = $this->extract(); 0073 if ($item['data'] === $datum) { 0074 $removed = true; 0075 continue; 0076 } 0077 $items[] = $item; 0078 } 0079 0080 // Repopulate 0081 foreach ($items as $item) { 0082 $this->insert($item['data'], $item['priority']); 0083 } 0084 0085 $this->setExtractFlags(self::EXTR_DATA); 0086 return $removed; 0087 } 0088 0089 /** 0090 * Iterate the next filter in the chain 0091 * 0092 * Iterates and calls the next filter in the chain. 0093 * 0094 * @param mixed $context 0095 * @param array $params 0096 * @param Zend_EventManager_Filter_FilterIterator $chain 0097 * @return mixed 0098 */ 0099 public function next($context = null, array $params = array(), $chain = null) 0100 { 0101 if (empty($context) || $chain->isEmpty()) { 0102 return; 0103 } 0104 0105 $next = $this->extract(); 0106 if (!$next instanceof Zend_Stdlib_CallbackHandler) { 0107 return; 0108 } 0109 0110 $return = call_user_func($next->getCallback(), $context, $params, $chain); 0111 return $return; 0112 } 0113 }