本文整理汇总了PHP中SplStack::setIteratorMode方法的典型用法代码示例。如果您正苦于以下问题:PHP SplStack::setIteratorMode方法的具体用法?PHP SplStack::setIteratorMode怎么用?PHP SplStack::setIteratorMode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SplStack
的用法示例。
在下文中一共展示了SplStack::setIteratorMode方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: seedMiddlewareStack
/**
* 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;
}
示例2: _validateSection
/**
* 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');
}
}
示例3: close
/**
* 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);
}
}
}
示例4: SplStack
<?php
$stack = new SplStack();
try {
$stack->setIteratorMode(SplDoublyLinkedList::IT_MODE_FIFO);
} catch (Exception $e) {
echo $e->getMessage();
}