/** * offsetSet() * * @param int $priority * @param \Zend\Controller\Action\Helper\AbstractHelper $helper * @return \Zend\Controller\Action\HelperBroker\PriorityStack */ public function offsetSet($priority, $helper) { $priority = (int) $priority; if (!$helper instanceof Helper\AbstractHelper) { throw new Exception('$helper must extend Zend\\Controller\\Action\\Helper\\AbstractHelper'); } if (array_key_exists($helper->getName(), $this->_helpersByNameRef)) { // remove any object with the same name $this->offsetUnset($helper->getName()); } if (array_key_exists($priority, $this->_helpersByPriority)) { $priority = $this->getNextFreeHigherPriority($priority); // ensures LIFO } $this->_helpersByPriority[$priority] = $helper; $this->_helpersByNameRef[$helper->getName()] = $helper; if ($priority == ($nextFreeDefault = $this->getNextFreeHigherPriority($this->_nextDefaultPriority))) { $this->_nextDefaultPriority = $nextFreeDefault; } krsort($this->_helpersByPriority); // always make sure priority and LIFO are both enforced return $this; }
/** * offsetSet() * * @param int $priority * @param \Zend\Controller\Action\Helper\AbstractHelper $helper * @return \Zend\Controller\Action\HelperBroker\PriorityStack */ public function offsetSet($priority, $helper) { $priority = (int) $priority; if (!$helper instanceof Helper\AbstractHelper) { throw new Exception('$helper must extend Zend\\Controller\\Action\\Helper\\AbstractHelper'); } if (array_key_exists($helper->getName(), $this->_helpersByNameRef)) { // remove any object with the same name to retain BC compailitbility // @todo At ZF 2.0 time throw an exception here. $this->offsetUnset($helper->getName()); } if (array_key_exists($priority, $this->_helpersByPriority)) { $priority = $this->getNextFreeHigherPriority($priority); // ensures LIFO trigger_error("A helper with the same priority already exists, reassigning to {$priority}", E_USER_WARNING); } $this->_helpersByPriority[$priority] = $helper; $this->_helpersByNameRef[$helper->getName()] = $helper; if ($priority == ($nextFreeDefault = $this->getNextFreeHigherPriority($this->_nextDefaultPriority))) { $this->_nextDefaultPriority = $nextFreeDefault; } krsort($this->_helpersByPriority); // always make sure priority and LIFO are both enforced return $this; }