當前位置: 首頁>>代碼示例>>PHP>>正文


PHP SplStack::shift方法代碼示例

本文整理匯總了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());
 }
開發者ID:treehouselabs,項目名稱:feeder,代碼行數:7,代碼來源:ResourceCollection.php

示例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
//.........這裏部分代碼省略.........
開發者ID:kakserpom,項目名稱:phpdaemon,代碼行數:101,代碼來源:Connection.php

示例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";
開發者ID:badlamer,項目名稱:hhvm,代碼行數:31,代碼來源:dllist_004.php

示例4: printOutput

function printOutput(SplStack $outputStack)
{
    while ($outputStack->count() !== 0) {
        echo $outputStack->shift();
    }
    echo PHP_EOL;
}
開發者ID:shikharsubedi,項目名稱:spoj,代碼行數:7,代碼來源:reversePolish.php


注:本文中的SplStack::shift方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。