/** * Seed middleware stack with first callable * * @param callable $kernel The last item to run as middleware * * @throws RuntimeException if the stack is seeded more than once */ protected function seedMiddlewareStack(callable $kernel = null) { if (!is_null($this->stack)) { throw new RuntimeException('MiddlewareStack can only be seeded once.'); } if ($kernel === null) { $kernel = $this; } $this->stack = new SplStack(); $this->stack->setIteratorMode(SplDoublyLinkedList::IT_MODE_LIFO | SplDoublyLinkedList::IT_MODE_KEEP); $this->stack[] = $kernel; }
/** * Validates the section record, determines the section parent and * the data format. * * @internal * @param Array &$section The section record. */ private function _validateSection(array &$section) { // Verify the value of the "order" attribute. if ($section['order'] != 'asc' && $section['order'] != 'desc') { throw new Opt_InvalidAttributeType_Exception('order', $node->getXmlName(), '"asc" or "desc"'); } // Determine the parent of the specified section. // if the attribute is not set, the default behaviour is to find the nearest // top-level and active section and link to it. Otherwise we must check if // the chosen section exists and is active. // Note that "parent" is ignored when we set "datasource" if (is_null($section['parent'])) { if (self::$_stack->count() > 0) { $section['parent'] = self::$_stack->top(); } } elseif ($section['parent'] != '') { if (is_null(self::getSection($section['parent']))) { $exception = new Opt_SectionNotFound_Exception('parent', $section['parent']); $sections = array(); self::$_stack->setIteratorMode(SplDoublyLinkedList::IT_MODE_LIFO | SplDoublyLinkedList::IT_MODE_KEEP); foreach (self::$_stack as $up) { $sections[] = $up; } $exception->setData($sections); throw $exception; } } else { // For the situation, if we had 'parent=""' in the template. $section['parent'] = null; } $section['nesting'] = self::countSections() + 1; // Now we need to obtain the information about the data format. $section['format'] = $this->_compiler->getFormat($section['name']); if (!$section['format']->supports('section')) { throw new Opt_FormatNotSupported_Exception($section['format']->getName(), 'section'); } }
/** * Close the channel, this operation will terminate all receivers that cannot receive any data. * * Closing a closed channel has no effect and does not throw an error! * * @param \Throwable $e Error will be propagated to all receivers that cannot receive a buffered value anymore. */ public function close(\Throwable $e = null) { if ($this->closed) { return; } $this->closed = $e ?? true; if ($this->generator) { $this->generator->cancel($e ?? new \RuntimeException('Channel closed')); } // Dispose of queued receivers that cannot receive a value from the channel. $sources = ($this->senders ? $this->countActiveSubscriptions($this->senders) : 0) + ($this->buffer ? $this->buffer->count() : 0); $sinks = $this->receivers ? $this->countActiveSubscriptions($this->receivers) : 0; $fails = new \SplStack(); $fails->setIteratorMode(\SplStack::IT_MODE_LIFO | \SplStack::IT_MODE_DELETE); while ($sinks > $sources) { $receiver = $this->receivers->pop(); if ($receiver->active) { $sinks--; $fails->push($receiver); } } foreach ($fails as $subscription) { if ($e) { $subscription->fail($e); } else { $subscription->resolve($subscription->data); } } }
<?php $stack = new SplStack(); try { $stack->setIteratorMode(SplDoublyLinkedList::IT_MODE_FIFO); } catch (Exception $e) { echo $e->getMessage(); }