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


PHP SplQueue::unshift方法代码示例

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


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

示例1: unshift

 /**
  * 在开头添加 middleware
  *
  * @param  callbale  $callbale 一般为回调函数
  * @return \Lime\Middleware
  */
 public function unshift($callbale)
 {
     if ($callbale instanceof \Closure) {
         $callbale = $this->bindToThis($callbale);
     }
     $this->queue->unshift($callbale);
     return $this;
 }
开发者ID:icodechef,项目名称:Lime,代码行数:14,代码来源:Middleware.php

示例2: __invoke

 /**
  * @param Request $request
  * @param Response $response
  * @param callable[] ...$callables unshift callables (top priority)
  * @return Response
  */
 public function __invoke(Request $request, Response $response, ...$callables)
 {
     while ($callable = array_pop($callables)) {
         $this->queue->unshift($callable);
     }
     if ($this->queue->isEmpty()) {
         return $response;
     }
     $callable = $this->resolve($this->queue->dequeue());
     if (is_callable($callable)) {
         return call_user_func($callable, $request, $response, $this);
     } else {
         throw new \UnexpectedValueException();
     }
 }
开发者ID:assouan,项目名称:stretcher,代码行数:21,代码来源:Stretcher.php

示例3: unshift

 public function unshift($value)
 {
     if (!$value instanceof Task) {
         throw new \InvalidArgumentException("TaskQueue expects instance of Task only");
     }
     parent::unshift($value);
 }
开发者ID:nikita2206,项目名称:poller,代码行数:7,代码来源:TaskQueue.php

示例4: filterMetadataStack

 private function filterMetadataStack(\SplDoublyLinkedList $metadataStack)
 {
     $filteredMetadataStack = new \SplQueue();
     foreach ($metadataStack as $curProperty) {
         if ($curProperty instanceof PropertyMetadata) {
             $filteredMetadataStack->unshift($curProperty);
         }
     }
     return $filteredMetadataStack;
 }
开发者ID:dspinellis,项目名称:pixelbonus,代码行数:10,代码来源:FieldsExclusionStrategy.php

示例5: createAwait

 /**
  * @param resource $resource
  * @param \SplQueue $writeQueue
  *
  * @return \Icicle\Loop\Watcher\Io
  */
 private function createAwait($resource, \SplQueue $writeQueue) : Io
 {
     return Loop\await($resource, static function ($resource, bool $expired, Io $await) use($writeQueue) {
         /** @var \Icicle\Awaitable\Delayed $delayed */
         list($data, $previous, $peer, $delayed) = $writeQueue->shift();
         $length = strlen($data);
         if (0 === $length) {
             $delayed->resolve($previous);
         } else {
             $written = stream_socket_sendto($resource, substr($data, 0, self::MAX_PACKET_SIZE), 0, $peer);
             // Having difficulty finding a test to cover this scenario, but the check seems appropriate.
             if (false === $written || -1 === $written || 0 === $written) {
                 $message = 'Failed to write to datagram.';
                 if ($error = error_get_last()) {
                     $message .= sprintf(' Errno: %d; %s', $error['type'], $error['message']);
                 }
                 $delayed->reject(new FailureException($message));
                 return;
             }
             if ($length <= $written) {
                 $delayed->resolve($written + $previous);
             } else {
                 $data = substr($data, $written);
                 $written += $previous;
                 $writeQueue->unshift([$data, $written, $peer, $delayed]);
             }
         }
         if (!$writeQueue->isEmpty()) {
             $await->listen();
         }
     });
 }
开发者ID:icicleio,项目名称:socket,代码行数:38,代码来源:BasicDatagram.php

示例6: createAwait

 /**
  * @param resource $resource
  * @param \SplQueue $writeQueue
  *
  * @return \Icicle\Loop\Watcher\Io
  */
 private function createAwait($resource, \SplQueue $writeQueue) : Io
 {
     return Loop\await($resource, static function ($resource, bool $expired, Io $await) use($writeQueue) {
         /** @var \Icicle\Awaitable\Delayed $delayed */
         list($data, $previous, $timeout, $delayed) = $writeQueue->shift();
         if ($expired) {
             $delayed->reject(new TimeoutException('Writing to the socket timed out.'));
             return;
         }
         $length = strlen($data);
         if (0 === $length) {
             $delayed->resolve($previous);
         } else {
             // Error reporting suppressed since fwrite() emits E_WARNING if the pipe is broken or the buffer is full.
             $written = @fwrite($resource, $data, self::CHUNK_SIZE);
             if (false === $written || 0 === $written) {
                 $message = 'Failed to write to stream.';
                 if ($error = error_get_last()) {
                     $message .= sprintf(' Errno: %d; %s', $error['type'], $error['message']);
                 }
                 $delayed->reject(new FailureException($message));
                 return;
             }
             if ($length <= $written) {
                 $delayed->resolve($written + $previous);
             } else {
                 $data = substr($data, $written);
                 $written += $previous;
                 $writeQueue->unshift([$data, $written, $timeout, $delayed]);
             }
         }
         if (!$writeQueue->isEmpty()) {
             list(, , $timeout) = $writeQueue->bottom();
             $await->listen($timeout);
         }
     });
 }
开发者ID:icicleio,项目名称:stream,代码行数:43,代码来源:WritablePipe.php


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