本文整理汇总了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);
}
});
}