当前位置: 首页>>代码示例>>PHP>>正文


PHP Token::getBlockLevel方法代码示例

本文整理汇总了PHP中Token::getBlockLevel方法的典型用法代码示例。如果您正苦于以下问题:PHP Token::getBlockLevel方法的具体用法?PHP Token::getBlockLevel怎么用?PHP Token::getBlockLevel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Token的用法示例。


在下文中一共展示了Token::getBlockLevel方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testBlockLevelAccessors

 /**
  * @covers spriebsch\PHPca\Token::__construct
  * @covers spriebsch\PHPca\Token::setBlockLevel
  * @covers spriebsch\PHPca\Token::getBlockLevel
  */
 public function testBlockLevelAccessors()
 {
     $t = new Token(T_OPEN_TAG, '<?php');
     $t->setBlockLevel(3);
     $this->assertEquals(3, $t->getBlockLevel());
 }
开发者ID:spriebsch,项目名称:phpca,代码行数:11,代码来源:TokenTest.php

示例2: seekMatchingCurlyBrace

 /**
  * Seeks to the matching curly brace.
  *
  * @param Token $token
  */
 public function seekMatchingCurlyBrace(Token $token)
 {
     $id = $token->getId();
     $level = $token->getBlockLevel();
     if ($id != T_OPEN_CURLY && $id != T_CLOSE_CURLY) {
         throw new Exception($token->getName() . ' is not a curly brace');
     }
     // Forward search
     if ($id == T_OPEN_CURLY) {
         $this->next();
         while ($this->valid()) {
             $token = $this->current()->getId();
             $closeLevel = $this->current()->getBlockLevel();
             if ($token == T_CLOSE_CURLY && $closeLevel == $level) {
                 return;
             }
             $this->next();
         }
     }
     // Backward search
     if ($id == T_CLOSE_CURLY) {
         $this->prev();
         while ($this->valid()) {
             $token = $this->current()->getId();
             $openLevel = $this->current()->getBlockLevel();
             if ($token == T_OPEN_CURLY && $level == $openLevel) {
                 return;
             }
             $this->prev();
         }
     }
     // This should be impossible since in a syntactically valid
     // PHP file, every opened curly brace must be closed.
     throw new Exception('No matching curly brace found');
 }
开发者ID:spriebsch,项目名称:phpca,代码行数:40,代码来源:File.php

示例3: tokenize


//.........这里部分代码省略.........
             // If we encounter the opening curly brace of a class (this happens
             // when $waitForClassBegin is true), we remember the block level of
             // this brace so that we can end the class when we encounter the
             // matching closing tag.
             if ($waitForClassBegin) {
                 $classCurlyLevel = $level;
                 $waitForClassBegin = false;
             }
             // If we encounter the opening curly brace of an interface (this happens
             // when $waitForInterfaceBegin is true), we remember the block level of
             // this brace so that we can end the interface when we encounter the
             // matching closing tag.
             if ($waitForInterfaceBegin) {
                 $interfaceCurlyLevel = $level;
                 $waitForInterfaceBegin = false;
             }
             // If we encounter the opening curly brace of a class (this happens
             // when $waitForClassBegin is true), we remember the block level of
             // this brace so that we can end the class when we encounter the
             // matching closing tag.
             if ($waitForFunctionBegin) {
                 $functionCurlyLevel = $level;
                 $waitForFunctionBegin = false;
             }
         }
         // Since we assemble any new namespace name in $newNamespace,
         // we can safely always set the $namespace.
         $tokenObj->setNamespace($namespace);
         if ($namespaceStarted) {
             $namespaceStarted = false;
             $namespace = $newNamespace;
             $newNamespace = '';
         }
         // This also sets the class when we are outside the class,
         // which is harmless because we then just set an emtpy string.
         if (!$waitForClassBegin) {
             if (substr($class, 0, 1) == '\\' || $namespace == '\\') {
                 $classname = $class;
             } else {
                 if ($class != '') {
                     $classname = $namespace . '\\' . $class;
                 } else {
                     $classname = '';
                 }
             }
             $tokenObj->setClass($classname);
         }
         // This also sets the interface when we are outside the interface,
         // which is harmless because we then just set an emtpy string.
         if (!$waitForInterfaceBegin) {
             if (substr($interface, 0, 1) == '\\' || $namespace == '\\') {
                 $interfaceName = $interface;
             } else {
                 if ($interface != '') {
                     $interfaceName = $namespace . '\\' . $interface;
                 } else {
                     $interfaceName = '';
                 }
             }
             $tokenObj->setInterface($interfaceName);
         }
         // This also sets the function when we are outside the function,
         // which is harmless because we then just set an emtpy string.
         if (!$waitForFunctionBegin) {
             $tokenObj->setFunction($function);
         }
         $tokenObj->setBlockLevel($level);
         // Closing curly decreases the block level. We do this *after*
         // we have set the block leven in the current token, so that
         // the closing curly's level matches the level of its opening brace.
         if ($tokenObj->getId() == T_CLOSE_CURLY) {
             $level--;
             // We get away with not dealing with namespace ends, since
             // non-namespaced code is not allowed when there is at least
             // one namespace in a file. So any namespace either implicitly
             // ends at the end of a file, or another namespace starts,
             // implicitly "ending" the previous namespace.
             // If we are inside a class and the closing brace matches the
             // opening brace of that class, the block/class has ended.
             if ($class != '' && $tokenObj->getBlockLevel() == $classCurlyLevel) {
                 $class = '';
                 $classCurlyLevel = 0;
             }
             // If we are inside an interface and the closing brace matches the
             // opening brace of that interface, the block/interface has ended.
             if ($interface != '' && $tokenObj->getBlockLevel() == $interfaceCurlyLevel) {
                 $interface = '';
                 $interfaceCurlyLevel = 0;
             }
             // If we are inside a function and the closing brace matches the
             // opening brace of that function, the block/function has ended.
             if ($function != '' && $tokenObj->getBlockLevel() == $functionCurlyLevel) {
                 $function = '';
                 $functionCurlyLevel = 0;
             }
         }
         $file->add($tokenObj);
     }
     return $file;
 }
开发者ID:spriebsch,项目名称:phpca,代码行数:101,代码来源:Tokenizer.php


注:本文中的Token::getBlockLevel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。