本文整理汇总了PHP中SplStack::shift方法的典型用法代码示例。如果您正苦于以下问题:PHP SplStack::shift方法的具体用法?PHP SplStack::shift怎么用?PHP SplStack::shift使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SplStack
的用法示例。
在下文中一共展示了SplStack::shift方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: shift
/**
* @return ResourceInterface
*/
public function shift()
{
return $this->transform(parent::shift());
}
示例2: onRead
/**
* Called when new data received
*/
public function onRead()
{
if ($this->state === self::STATE_BODY) {
goto body;
}
if ($this->reqType === null) {
if ($this->requests->isEmpty()) {
$this->finish();
return;
}
$this->reqType = $this->requests->shift();
}
while (($line = $this->readLine()) !== null) {
if ($line !== '') {
if ($this->rawHeaders !== null) {
$this->rawHeaders[] = $line;
}
} else {
if (isset($this->headers['HTTP_CONTENT_LENGTH'])) {
$this->contentLength = (int) $this->headers['HTTP_CONTENT_LENGTH'];
} else {
$this->contentLength = -1;
}
if (isset($this->headers['HTTP_TRANSFER_ENCODING'])) {
$e = explode(', ', strtolower($this->headers['HTTP_TRANSFER_ENCODING']));
$this->chunked = in_array('chunked', $e, true);
} else {
$this->chunked = false;
}
if (isset($this->headers['HTTP_CONNECTION'])) {
$e = explode(', ', strtolower($this->headers['HTTP_CONNECTION']));
$this->keepalive = in_array('keep-alive', $e, true);
}
if (isset($this->headers['HTTP_CONTENT_TYPE'])) {
parse_str('type=' . strtr($this->headers['HTTP_CONTENT_TYPE'], [';' => '&', ' ' => '']), $p);
$this->contentType = $p['type'];
if (isset($p['charset'])) {
$this->charset = strtolower($p['charset']);
}
}
if ($this->contentLength === -1 && !$this->chunked && !$this->keepalive) {
$this->eofTerminated = true;
}
if ($this->reqType === 'HEAD') {
$this->requestFinished();
} else {
$this->state = self::STATE_BODY;
}
break;
}
if ($this->state === self::STATE_ROOT) {
$this->headers['STATUS'] = $line;
$e = explode(' ', $this->headers['STATUS']);
$this->responseCode = isset($e[1]) ? (int) $e[1] : 0;
$this->state = self::STATE_HEADERS;
} elseif ($this->state === self::STATE_HEADERS) {
$e = explode(': ', $line);
if (isset($e[1])) {
$k = 'HTTP_' . strtoupper(strtr($e[0], Generic::$htr));
if ($k === 'HTTP_SET_COOKIE') {
parse_str(strtr($e[1], [';' => '&', ' ' => '']), $p);
if (sizeof($p)) {
$this->cookie[$k = key($p)] =& $p;
$p['value'] = $p[$k];
unset($p[$k], $p);
}
}
if (isset($this->headers[$k])) {
if (is_array($this->headers[$k])) {
$this->headers[$k][] = $e[1];
} else {
$this->headers[$k] = [$this->headers[$k], $e[1]];
}
} else {
$this->headers[$k] = $e[1];
}
}
}
}
if ($this->state !== self::STATE_BODY) {
return;
// not enough data yet
}
body:
if ($this->eofTerminated) {
$body = $this->readUnlimited();
if ($this->chunkcb) {
$func = $this->chunkcb;
$func($body);
}
$this->body .= $body;
return;
}
if ($this->chunked) {
chunk:
if ($this->curChunkSize === null) {
// outside of chunk
//.........这里部分代码省略.........
示例3: count
<?php
$stack = new SplStack();
// errors
try {
$stack->pop();
} catch (RuntimeException $e) {
echo "Exception: " . $e->getMessage() . "\n";
}
try {
$stack->shift();
} catch (RuntimeException $e) {
echo "Exception: " . $e->getMessage() . "\n";
}
// data consistency
$a = 2;
$stack->push($a);
echo $stack->pop() . "\n";
// peakable
$stack->push(1);
$stack->push(2);
echo $stack->top() . "\n";
// iterable
foreach ($stack as $elem) {
echo "[{$elem}]\n";
}
// countable
$stack->push(NULL);
$stack->push(NULL);
echo count($stack) . "\n";
echo $stack->count() . "\n";
示例4: printOutput
function printOutput(SplStack $outputStack)
{
while ($outputStack->count() !== 0) {
echo $outputStack->shift();
}
echo PHP_EOL;
}