当前位置: 首页>>代码示例>>PHP>>正文


PHP SplQueue::setIteratorMode方法代码示例

本文整理汇总了PHP中SplQueue::setIteratorMode方法的典型用法代码示例。如果您正苦于以下问题:PHP SplQueue::setIteratorMode方法的具体用法?PHP SplQueue::setIteratorMode怎么用?PHP SplQueue::setIteratorMode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SplQueue的用法示例。


在下文中一共展示了SplQueue::setIteratorMode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: when

 /**
  * Implements the when() method of the Promise interface.
  * 
  * @param callable $onResolved
  */
 public function when(callable $onResolved)
 {
     switch ($this->state) {
         case Awaitable::RESOLVED:
             try {
                 $onResolved(null, ...$this->result);
             } catch (\Throwable $ex) {
                 Loop::defer(function () use($ex) {
                     throw $ex;
                 });
             }
             break;
         case Awaitable::FAILED:
             try {
                 $onResolved($this->result);
             } catch (\Throwable $ex) {
                 Loop::defer(function () use($ex) {
                     throw $ex;
                 });
             }
             break;
         default:
             if (!$this->callbacks) {
                 $this->callbacks = new \SplQueue();
                 $this->callbacks->setIteratorMode(\SplQueue::IT_MODE_FIFO | \SplQueue::IT_MODE_DELETE);
             }
             $this->callbacks->enqueue($onResolved);
     }
 }
开发者ID:koolkode,项目名称:async,代码行数:34,代码来源:AwaitableTrait.php

示例2: __construct

 public function __construct()
 {
     parent::__construct();
     $this->scope = new EventEmitter();
     $this->queue = new \SplQueue();
     $this->queue->setIteratorMode(\SplQueue::IT_MODE_DELETE);
 }
开发者ID:inisire,项目名称:framework,代码行数:7,代码来源:EventDispatcher.php

示例3: __construct

 public function __construct(\Iterator $it)
 {
     $this->it = $it;
     $this->statement = new \SplQueue();
     $this->statement->setIteratorMode(\SplDoublyLinkedList::IT_MODE_DELETE);
     $this->blocks = new \SplStack();
 }
开发者ID:rafeca,项目名称:Spec-PHP,代码行数:7,代码来源:Transform.php

示例4: __construct

 /**
  * @param Zend_Log_Writer_Abstract $writer
  * @param int $flushPriority
  * @param int $limit - If greater than 0 will only buffer that many events
  */
 public function __construct(Zend_Log_Writer_Abstract $writer, $flushPriority = Zend_Log::DEBUG, $limit = 0)
 {
     $this->writer = $writer;
     $this->flushPriority = $flushPriority;
     $this->limit = $limit;
     $this->buffer = new SplQueue();
     $this->buffer->setIteratorMode(SplDoublyLinkedList::IT_MODE_FIFO | SplDoublyLinkedList::IT_MODE_DELETE);
     $this->flushed = false;
 }
开发者ID:SandeepUmredkar,项目名称:PortalSMIP,代码行数:14,代码来源:FingersCrossed.php

示例5: main

 /**
  * Copies for the audits and audits_logs table into the elastic search storage.
  *
  * @return bool
  */
 public function main()
 {
     $table = $this->loadModel('Audits');
     $table->hasMany('AuditDeltas');
     $table->schema()->columnType('created', 'string');
     $map = [];
     $meta = [];
     $featureList = function ($element) {
         list($k, $v) = explode(':', $element);
         (yield $k => $v);
     };
     if (!empty($this->params['type-map'])) {
         $map = explode(',', $this->params['type-map']);
         $map = collection($map)->unfold($featureList)->toArray();
     }
     if (!empty($this->params['extra-meta'])) {
         $meta = explode(',', $this->params['extra-meta']);
         $meta = collection($meta)->unfold($featureList)->toArray();
     }
     $from = (new Time($this->params['from']))->modify('midnight');
     $until = (new Time($this->params['until']))->modify('23:59:59');
     $currentId = null;
     $buffer = new \SplQueue();
     $buffer->setIteratorMode(\SplDoublyLinkedList::IT_MODE_DELETE);
     $queue = new \SplQueue();
     $queue->setIteratorMode(\SplDoublyLinkedList::IT_MODE_DELETE);
     $index = ConnectionManager::get('auditlog_elastic')->getConfig('index');
     $eventsFormatter = function ($audit) use($index, $meta) {
         return $this->eventFormatter($audit, $index, $meta);
     };
     $changesExtractor = [$this, 'changesExtractor'];
     $query = $table->find()->where(function ($exp) use($from, $until) {
         return $exp->between('Audits.created', $from, $until, 'datetime');
     })->where(function ($exp) {
         if (!empty($this->params['exclude-models'])) {
             $exp->notIn('Audits.model', explode(',', $this->params['exclude-models']));
         }
         if (!empty($this->params['models'])) {
             $exp->in('Audits.model', explode(',', $this->params['models']));
         }
         return $exp;
     })->matching('AuditDeltas')->order(['Audits.created', 'AuditDeltas.audit_id'])->bufferResults(false)->hydrate(false)->unfold(function ($audit) use($buffer, &$currentId) {
         if ($currentId && $currentId !== $audit['id']) {
             (yield collection($buffer)->toList());
         }
         $currentId = $audit['id'];
         $buffer->enqueue($audit);
     })->map($changesExtractor)->map($eventsFormatter)->unfold(function ($audit) use($queue) {
         $queue->enqueue($audit);
         if ($queue->count() >= 50) {
             (yield collection($queue)->toList());
         }
     });
     $query->each([$this, 'persistBulk']);
     // There are probably some un-yielded results, let's flush them
     $rest = collection(count($buffer) ? [collection($buffer)->toList()] : [])->map($changesExtractor)->map($eventsFormatter)->append($queue);
     $this->persistBulk($rest->toList());
     return true;
 }
开发者ID:lorenzo,项目名称:audit-stash,代码行数:64,代码来源:ElasticImportTask.php

示例6: __construct

 /**
  * {@inheritdoc}
  */
 public function __construct($queue = null)
 {
     parent::setIteratorMode(\SplDoublyLinkedList::IT_MODE_FIFO & \SplDoublyLinkedList::IT_MODE_DELETE);
     if (null !== $queue) {
         foreach ($queue as $item) {
             $this->enqueue($item);
         }
     }
 }
开发者ID:liuggio,项目名称:spawn,代码行数:12,代码来源:SplQueue.php

示例7: __construct

 /**
  * Create a new uv loop.
  * 
  * @param LoopConfig $config
  */
 public function __construct(LoopConfig $config = null)
 {
     parent::__construct($config);
     //         $this->loop = $loop ?? \uv_loop_new();
     // TODO: Investigate why new uv loops cannot be deleted (segfault) and leak file descriptors...
     $this->loop = \uv_default_loop();
     $this->dispose = new \SplQueue();
     $this->dispose->setIteratorMode(\SplQueue::IT_MODE_FIFO | \SplQueue::IT_MODE_DELETE);
     $this->config->setHostResolver(new Resolver($this));
     $this->config->setFilesystem(new Filesystem($this, $this->config->getFilesystemObserver()));
     if (\defined('PHP_ZTS') && \PHP_ZTS) {
         // TODO: Implement a pool based on uv_queue_work() if ZTS is enabled (unusable: "zend_mm_heap corrupted").
     }
     $this->delayCallback = function ($event) {
         $watcher = $this->timerWatchers[(int) $event] ?? null;
         if ($watcher) {
             $this->info[Watcher::TYPE_DELAY]--;
             unset($this->timerWatchers[(int) $event], $this->watchers[$watcher->id], $this->enable[$watcher->id]);
             if ($watcher->referenced) {
                 $this->watchersReferenced--;
             }
             $watcher->event = null;
             $this->dispose->enqueue($event);
             ($watcher->callback)($watcher->id, $watcher->data);
         }
     };
     $this->repeatCallback = function ($event) {
         $watcher = $this->timerWatchers[(int) $event] ?? null;
         if ($watcher) {
             ($watcher->callback)($watcher->id, $watcher->data);
         }
     };
     $this->streamCallback = function ($event, int $status, int $events) {
         $id = (int) $event;
         if (($events === 0 || $events & \UV::READABLE) && isset($this->readWatchers[$id])) {
             foreach ($this->readWatchers[$id] as $watcher) {
                 ($watcher->callback)($watcher->id, $watcher->stream, $watcher->data);
             }
         }
         if (($events === 0 || $events & \UV::WRITABLE) && isset($this->writeWatchers[$id])) {
             foreach ($this->writeWatchers[$id] as $watcher) {
                 ($watcher->callback)($watcher->id, $watcher->stream, $watcher->data);
             }
         }
     };
     $this->signalCallback = function ($event, int $signo) {
         if (isset($this->signalWatchers[$signo])) {
             foreach ($this->signalWatchers[$signo] as $watcher) {
                 ($watcher->callback)($watcher->id, $watcher->signo, $watcher->data);
             }
         }
     };
 }
开发者ID:koolkode,项目名称:async,代码行数:58,代码来源:UvLoop.php

示例8: iterate_queue_with_mode

function iterate_queue_with_mode($mode)
{
    $x = new SplQueue();
    $x->setIteratorMode($mode);
    $x->push(1);
    $x->push(2);
    $x->push(3);
    foreach ($x as $y) {
        var_dump($y);
    }
    var_dump(count($x));
}
开发者ID:badlamer,项目名称:hhvm,代码行数:12,代码来源:queue_iteration.php

示例9: getUserMemberOf

 /**
  * Load memberOf for the current user - 1 LDAP query
  *
  * @param Manager $ldap
  * @param array $userData
  * @param array $allowedGroups
  * @return array (groupDn => groupName)
  */
 protected function getUserMemberOf(Manager $ldap, array $userData, array $allowedGroups)
 {
     $memberOf = array();
     $processed = array();
     $iterator = new \SplQueue();
     $iterator->setIteratorMode(\SplQueue::IT_MODE_DELETE);
     // Load membership
     $raw = $ldap->search(null, Utils::getUserLookup($userData['username']), true, array('memberof'));
     if (!$raw->current() instanceof Node) {
         return array();
     }
     $attrs = $raw->current()->getAttributes();
     if (!array_key_exists('memberOf', $attrs) || !$attrs['memberOf'] instanceof NodeAttribute) {
         return array();
     }
     // Post process all groups into memberOf array, put them into iterator for inheritance loading
     foreach ($attrs['memberOf'] as $groupDn) {
         $memberOf[$groupDn] = Utils::loadNameFromDn($groupDn);
         if (isset($processed[$groupDn])) {
             continue;
         }
         $iterator->enqueue($groupDn);
         $processed[$groupDn] = true;
     }
     // Loop iterator & load all inherits
     while (!$iterator->isEmpty()) {
         $groupDn = $iterator->dequeue();
         $inherits = $this->getGroupMemberOf($ldap, $groupDn);
         foreach ($inherits as $one) {
             /** @var Node $one */
             if (isset($processed[$one->getDn()])) {
                 continue;
             }
             $processed[$one->getDn()] = true;
             $iterator->enqueue($one->getDn());
             $memberOf[$one->getDn()] = Utils::loadNameFromDn($one->getDn());
         }
     }
     return $memberOf;
 }
开发者ID:foglcz,项目名称:ldap-authenticator,代码行数:48,代码来源:GroupsLoader.php

示例10: SplQueue

<?php

$queue = new SplQueue();
try {
    $queue->setIteratorMode(SplDoublyLinkedList::IT_MODE_LIFO);
} catch (Exception $e) {
    echo $e->getMessage();
}
开发者ID:badlamer,项目名称:hhvm,代码行数:8,代码来源:SplQueue_setIteratorMode.php

示例11: serveronly

/* SPL QUEUE  */
$qoperatingsystems = new SplQueue();
$qoperatingsystems->push(array('Windows 7', 'desktop', 'NT', 56.11));
$qoperatingsystems->push(array('Windows XP', 'desktop', 'NT', 10.59));
$qoperatingsystems->push(array('Windows 8', 'desktop', 'NT', 2.88));
$qoperatingsystems->push(array('Windows 8.1', 'desktop', 'NT', 11.15));
$qoperatingsystems->push(array('Windows 10', 'desktop', 'NT', 9));
$qoperatingsystems->push(array('Windows Vista', 'desktop', 'NT', 0));
$qoperatingsystems->push(array('Mac OS X 11', 'desktop', 'Unix', 2.66));
$qoperatingsystems->push(array('Mac OS X 10', 'desktop', 'Unix', 2.45));
$qoperatingsystems->push(array('Linux Mint', 'desktop', 'Linux', 0));
$qoperatingsystems->push(array('Linux Debian', 'desktop', 'Linux', 0));
$qoperatingsystems->push(array('Android', 'mobile', 'Linux', 48.12));
$qoperatingsystems->push(array('iOS', 'mobile', 'Unix', 34.71));
echo "\nSPL QUEUE ARRAY FOR LOOP: FIFO\n";
$qoperatingsystems->setIteratorMode(SplDoublyLinkedList::IT_MODE_FIFO);
for ($qoperatingsystems->rewind(); $qoperatingsystems->valid(); $qoperatingsystems->next()) {
    echo $qoperatingsystems->current()[0] . "\n";
    echo $qoperatingsystems->current()[1] . "\n";
    echo $qoperatingsystems->current()[2] . "\n";
    echo $qoperatingsystems->current()[3] . "\n";
}
/* ------------------BASIC OPERATIONS------------------ */
// SORT
// BY LANGUAGE RANKING
usort($nlanguages, function ($a, $b) {
    return $b[2] - $a[2];
});
// FILTER
// BY DATABASE SIZE
function serveronly($var)
开发者ID:ParfaitG,项目名称:DATA_STRUCTURES,代码行数:31,代码来源:DataStructures.php

示例12: SplQueue

<?php

$queue = new SplQueue();
$queue->push(1);
$queue->push(2);
$queue->push(4);
$queue->push(3);
$queue->setIteratorMode(SplQueue::IT_MODE_DELETE);
foreach ($queue as $k => $v) {
    printf("%s => %s\n", $k, $v);
}
开发者ID:Eldahar,项目名称:PHP_Library,代码行数:11,代码来源:SplQueue.php

示例13: tee

/**
 * Return n independent iterators from a single iterable, useful when you
 * dealing with no rewind iterator, but need to traverse more that 1 time.
 */
function tee($iterable, $n = 2)
{
    $iter = iter($iterable);
    $deques = array_map(function ($_) {
        $queue = new \SplQueue();
        $queue->setIteratorMode(\SplQueue::IT_MODE_DELETE);
        return $queue;
    }, \range(0, $n - 1));
    return \array_map(function ($locdeque) use($iter, $deques) {
        while (true) {
            // in case the local deque is empty we will fecth data from
            // original iterator, and pass them to all dequeues.
            if ($locdeque->isEmpty()) {
                if (!$iter->valid()) {
                    return;
                }
                $newval = $iter->current();
                foreach ($deques as $d) {
                    $d->enqueue($newval);
                }
                $iter->next();
            }
            (yield $locdeque->dequeue());
        }
    }, $deques);
}
开发者ID:syaiful6,项目名称:itertools,代码行数:30,代码来源:itertools.php

示例14: __construct

 public function __construct()
 {
     $this->handlers = [];
     $this->signalQueue = new \SplQueue();
     $this->signalQueue->setIteratorMode(\SplQueue::IT_MODE_DELETE);
 }
开发者ID:meckhardt,项目名称:ko-process,代码行数:6,代码来源:SignalHandler.php

示例15: execute

 /**
  * executes the container a optional array may be passed to this method that keeps additional parameters
  * which will be passed after the actor as parameters to each entity call.
  *
  * @param array $executeArguments
  * @throws QueueException|FatalQueueException
  */
 public function execute(array $executeArguments = [])
 {
     $priorities = array_combine(array_keys($this->items), array_column($this->items, 'priority'));
     $priorityStack = new \SplQueue();
     $priorityStack->setIteratorMode(\SplQueue::IT_MODE_DELETE);
     array_map([$priorityStack, 'enqueue'], array_keys($priorities));
     foreach ($priorityStack as $dequeuedItem) {
         if (is_int($priorities[$dequeuedItem])) {
             continue;
         }
         if (!array_key_exists(current($priorities[$dequeuedItem]), $priorities)) {
             throw new QueueException(sprintf('Foundry container item with name `%s` points to an unavailable container item with name `%s`', $dequeuedItem, current($priorities[$dequeuedItem])));
         }
         if (current($priorities[$dequeuedItem]) === $dequeuedItem) {
             throw new QueueException(sprintf('Foundry container item with name `%s` points to `%s`, self-recursion detected', $dequeuedItem, current($priorities[$dequeuedItem])));
         }
         if (is_array($priorities[current($priorities[$dequeuedItem])]) && current($priorities[current($priorities[$dequeuedItem])]) === $dequeuedItem) {
             throw new QueueException(sprintf('Foundry container item with name `%s` points to `%s` which points to `%s`, recursion detected', $dequeuedItem, current($priorities[$dequeuedItem]), current($priorities[current($priorities[$dequeuedItem])])));
         }
         if (!is_int($priorities[current($priorities[$dequeuedItem])])) {
             $priorityStack->enqueue($dequeuedItem);
             continue;
         }
         if ('before' === key($priorities[$dequeuedItem])) {
             $priorities[$dequeuedItem] = $priorities[current($priorities[$dequeuedItem])] - 1;
         } else {
             if ('after' === key($priorities[$dequeuedItem])) {
                 $priorities[$dequeuedItem] = $priorities[current($priorities[$dequeuedItem])] + 1;
             }
         }
     }
     asort($priorities);
     $priorityStack->setIteratorMode(\SplQueue::IT_MODE_KEEP);
     array_map([$priorityStack, 'enqueue'], array_keys($priorities));
     array_unshift($executeArguments, new Actor($priorityStack));
     foreach ($priorityStack as $current) {
         if (false !== $this->closureBinding && $this->items[$current]['callable'] instanceof \Closure) {
             $callable = call_user_func_array([$this->items[$current]['callable'], 'bindTo'], $this->closureBinding);
         } else {
             $callable = $this->items[$current]['callable'];
         }
         try {
             call_user_func_array($callable, $executeArguments);
         } catch (\LogicException $exception) {
             throw new QueueException('Callable logic execution failed', 0, $exception);
         } catch (\RuntimeException $exception) {
             throw new FatalQueueException('Callable logic ends in fatal state', 500, $exception);
         }
     }
 }
开发者ID:nh-gear,项目名称:foundry,代码行数:57,代码来源:Container.php


注:本文中的SplQueue::setIteratorMode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。