當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。