本文整理匯總了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;
}
示例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();
}
}
示例3: unshift
public function unshift($value)
{
if (!$value instanceof Task) {
throw new \InvalidArgumentException("TaskQueue expects instance of Task only");
}
parent::unshift($value);
}
示例4: filterMetadataStack
private function filterMetadataStack(\SplDoublyLinkedList $metadataStack)
{
$filteredMetadataStack = new \SplQueue();
foreach ($metadataStack as $curProperty) {
if ($curProperty instanceof PropertyMetadata) {
$filteredMetadataStack->unshift($curProperty);
}
}
return $filteredMetadataStack;
}
示例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();
}
});
}
示例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);
}
});
}