本文整理汇总了PHP中SplStack::isEmpty方法的典型用法代码示例。如果您正苦于以下问题:PHP SplStack::isEmpty方法的具体用法?PHP SplStack::isEmpty怎么用?PHP SplStack::isEmpty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SplStack
的用法示例。
在下文中一共展示了SplStack::isEmpty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: clearCachesOfRegisteredPageIds
/**
* Walks through the pageIdStack, collects all pageIds
* as array and passes them on to clearPageCache.
*
* @return void
*/
public function clearCachesOfRegisteredPageIds()
{
if (!$this->pageIdStack->isEmpty()) {
$pageIds = array();
while (!$this->pageIdStack->isEmpty()) {
$pageIds[] = (int) $this->pageIdStack->pop();
}
$pageIds = array_values(array_unique($pageIds));
$this->clearPageCache($pageIds);
}
}
示例2: enterNode
public function enterNode(Node $node)
{
if ($node instanceof Node\Stmt\Foreach_) {
$this->checkNestedByReferenceForeach($node);
$this->foreachStack->push($node);
} elseif (!$this->foreachStack->isEmpty()) {
$this->checkInternalArrayPointerAccessInByValueForeach($node);
$this->checkArrayModificationByFunctionInByReferenceForeach($node);
$this->checkAddingToArrayInByReferenceForeach($node);
}
}
示例3: _checkLevel
/**
* @param \PHP\Manipulator\Token $token
*/
protected function _checkLevel(Token $token)
{
if ($this->isOpeningCurlyBrace($token)) {
$this->_level++;
$this->_maxLevel = max(array($this->_level, $this->_maxLevel));
}
if ($this->isClosingCurlyBrace($token)) {
$this->_level--;
if (!$this->_classStack->isEmpty() && $this->_level === $this->_classStack[count($this->_classStack) - 1]) {
$this->_classStack->pop();
}
}
}
示例4: build
/**
* Converts the current expression into a single matcher, applying
* coordination operators to operands according to their binding rules
*
* @throws \RuntimeException
* @return \Hamcrest_Matcher
*/
public function build()
{
// Apply Shunting Yard algorithm to convert the infix expression
// into Reverse Polish Notation. Since we have a very limited
// set of operators and binding rules, the implementation becomes
// really simple
$ops = new \SplStack();
$rpn = array();
foreach ($this->parts as $token) {
if ($token instanceof Operator) {
while (!$ops->isEmpty() && $token->compare($ops->top()) <= 0) {
$rpn[] = $ops->pop();
}
$ops->push($token);
} else {
$rpn[] = $token;
}
}
// Append the remaining operators
while (!$ops->isEmpty()) {
$rpn[] = $ops->pop();
}
// Walk the RPN expression to create AnyOf and AllOf matchers
$stack = new \splStack();
foreach ($rpn as $token) {
if ($token instanceof Operator) {
// Our operators always need two operands
if ($stack->count() < 2) {
throw new \RuntimeException('Unable to build a valid expression. Not enough operands available.');
}
$operands = array($stack->pop(), $stack->pop());
// Check what kind of matcher we need to create
if ($token->getKeyword() === 'OR') {
$matcher = new \Hamcrest_Core_AnyOf($operands);
} else {
// AND, BUT
$matcher = new \Hamcrest_Core_AllOf($operands);
}
$stack->push($matcher);
} else {
$stack[] = $token;
}
}
if ($stack->count() !== 1) {
throw new \RuntimeException('Unable to build a valid expression. The RPN stack should have just one item.');
}
return $stack->pop();
}
示例5: stackedCoroutine
/**
* Resolves yield calls tree
* and gives a return value if outcome of yield is CoroutineReturnValue instance
*
* @param \Generator $coroutine nested coroutine tree
* @return \Generator
*/
private static function stackedCoroutine(\Generator $coroutine)
{
$stack = new \SplStack();
while (true) {
$value = $coroutine->current();
// nested generator/coroutine
if ($value instanceof \Generator) {
$stack->push($coroutine);
$coroutine = $value;
continue;
}
// coroutine end or value is a value object instance
if (!$coroutine->valid() || $value instanceof CoroutineReturnValue) {
// if till this point, there are no coroutines in a stack thatn stop here
if ($stack->isEmpty()) {
return;
}
$coroutine = $stack->pop();
$value = $value instanceof CoroutineReturnValue ? $value->getValue() : null;
$coroutine->send($value);
continue;
}
$coroutine->send((yield $coroutine->key() => $value));
}
}
示例6: reset
/**
* Resets the suites tree with a new root
*
* @static
* @param \DrSlump\Spec\TestSuite
*/
public static function reset(Spec\TestSuite $root)
{
while (!self::$suites->isEmpty()) {
self::$suites->pop();
}
self::$suites->push($root);
}
示例7: LoadV2
/**
* 加载指定目录下的配置并生成[绝对路径=>配置]
* (备用)
*
* @param $filePath
* @param string $ext
*/
private function LoadV2($filePath, $ext = '.php')
{
$resConfig = [];
$split = '.';
if (file_exists($filePath)) {
$key = basename($filePath, $ext);
$configs = (include $filePath);
$keyStack = new \SplStack();
$keyStack->push([$key, $configs]);
$whileCount = 0;
//防止意外进入死循环,限制最多循环1024层
while (!$keyStack->isEmpty() && $whileCount < 1024) {
$whileCount++;
$pair = $keyStack->pop();
foreach ($pair[1] as $pairKey => $pairVal) {
if (is_array($pairVal)) {
$keyStack->push([$pair[0] . $split . $pairKey, $pairVal]);
} else {
$resConfig[$pair[0] . $split . $pairKey] = $pairVal;
}
}
}
}
return $resConfig;
}
示例8: leaveNode
/**
* {@inheritdoc}
*/
public function leaveNode(Node $node)
{
if ($this->argumentModificationStack->isEmpty()) {
return;
}
if ($node instanceof Node\FunctionLike) {
$this->argumentModificationStack->pop();
return;
}
foreach ($this->possiblyArgumentModifyingClasses as $class) {
if ($node instanceof $class) {
$this->argumentModificationStack->pop();
$this->argumentModificationStack->push(true);
return;
}
}
}
示例9: stackedCoroutine
function stackedCoroutine(Generator $gen)
{
$stack = new SplStack();
$exception = null;
for (;;) {
try {
if ($exception) {
$gen->throw($exception);
$exception = null;
continue;
}
$value = $gen->current();
if ($value instanceof Generator) {
$stack->push($gen);
$gen = $value;
continue;
}
$isReturnValue = $value instanceof CoroutineReturnValue;
if (!$gen->valid() || $isReturnValue) {
if ($stack->isEmpty()) {
return;
}
$gen = $stack->pop();
$gen->send($isReturnValue ? $value->getValue() : NULL);
continue;
}
if ($value instanceof CoroutinePlainValue) {
$value = $value->getValue();
}
try {
$sendValue = (yield $gen->key() => $value);
} catch (Exception $e) {
$gen->throw($e);
continue;
}
$gen->send($sendValue);
} catch (Exception $e) {
if ($stack->isEmpty()) {
throw $e;
}
$gen = $stack->pop();
$exception = $e;
}
}
}
示例10: hasOperatorInStack
/**
* Determine if there is operator token in operator stack
*
* @return boolean
*/
private function hasOperatorInStack()
{
$hasOperatorInStack = false;
if (!$this->operatorStack->isEmpty()) {
$top = $this->operatorStack->top();
if ($top instanceof Operator) {
$hasOperatorInStack = true;
}
}
return $hasOperatorInStack;
}
示例11: hasOperatorInStack
/**
* Determine if there is operator token in operato stack
*
* @return boolean
*/
private function hasOperatorInStack()
{
$hasOperatorInStack = false;
if (!$this->operatorStack->isEmpty()) {
$top = $this->operatorStack->top();
if (Token::T_OPERATOR == $top->getType()) {
$hasOperatorInStack = true;
}
}
return $hasOperatorInStack;
}
示例12: __unset
/**
* To remove a property from the instance.
*
* Data management : In PHP7, \Closure::bind(), \Closure::bindTo() and \Closure::call()
* can not change the scope about non real closure (all closures obtained by \ReflectionMethod::getClosure()) to avoid
* error due to compilation pass with self::
*
* Thise change does not impact rebinding of $this, but the scope stay unchanged, and private or protected attributes
* or method are not available in this closure (the scope differ).
*
* So we use magic call to restore this behavior during a calling
*
* @param string $name
*
* @throws \ErrorException of the property is not accessible
*/
public function __unset(string $name)
{
if (!$this->callerStatedClassesStack->isEmpty() && property_exists($this, $name)) {
unset($this->{$name});
return;
}
if ($this->isPublicProperty($name)) {
unset($this->{$name});
return;
}
throw new \ErrorException('Error: Cannot access private property ' . get_class($this) . '::' . $name);
}
示例13: getTotal
/**
* get the total executed time
*
* @return float
*/
public function getTotal()
{
$ret_total = $this->total;
// if there is still stuff on the stack, the first item is the oldest, so use that
// to calculate the total time...
if (!$this->stack_started->isEmpty()) {
$profile_map = $this->stack_started->top();
$ret_total += $this->getTime($profile_map['start'], microtime(true));
}
//if
return $ret_total;
}
示例14: top
/**
* @param bool $pop
* @return Item|null
*/
public function top($pop = false)
{
if ($this->items->isEmpty()) {
return null;
}
if ($pop) {
return $this->items->pop();
}
while ($top = $this->items->top()) {
/** @var Item $top */
// WARNING Non-parallel code for the stack may be modified by other code
if ($top->getState() instanceof StateStopped) {
$this->handle($this->items->pop());
if ($this->items->isEmpty()) {
return null;
}
} else {
return $top;
}
}
return null;
}
示例15: toPostfix
/**
* Conversão de Formato Infixo para Posfixo
* @return array Fila de Tokens para Cálculo Posfixo
*/
public function toPostfix()
{
/* Analisador Léxico */
$lexer = $this->getLexer();
/* Pilha para Conversão */
$stack = new \SplStack();
/* Notação Polonesa Reversa */
$postfix = array();
/* Execução */
while (($token = $lexer->getToken()) != null) {
/* Analisador Sintático */
if ($token->isA('T_NUMBER') || $token->isA('T_FLOAT') || $token->isA('T_VAR') || $token->isA('T_DEF') || $token->isA('T_BLOCKDEF')) {
$postfix[] = $token;
} elseif ($token->isA('T_OPERATOR') || $token->isA('T_ASSIGN')) {
/* @todo Melhorar Pesquisa */
$found = false;
while (!$found) {
if ($stack->isEmpty()) {
$stack->push($token);
$found = true;
} else {
if ($stack->top()->isA('T_OB')) {
$stack->push($token);
$found = true;
} elseif ($this->precedence($token, $stack->top()) > 0) {
$stack->push($token);
$found = true;
} else {
$postfix[] = $stack->pop();
}
}
}
} elseif ($token->isA('T_OB')) {
$stack->push($token);
} elseif ($token->isA('T_CB')) {
while (!$stack->isEmpty() && !$stack->top()->isA('T_OB')) {
$postfix[] = $stack->pop();
}
$stack->pop();
} else {
$format = "Invalid Token '%s' @column %d";
$message = sprintf($format, $token->getType(), $token->getPosition());
throw new Exception($message);
}
}
/* Tokens Restantes na Pilha */
while (!$stack->isEmpty()) {
$postfix[] = $stack->pop();
}
return $postfix;
}