示例#1
0
文件: Token.php 项目: JeCat/framework
 public function cloneOf(self $aOther)
 {
     $this->nType = $aOther->nType;
     $this->setSourceCode($aOther->sourceCode());
     $this->setTargetCode($aOther->targetCode());
     $this->setPosition($aOther->position());
     $this->setBelongsClass($aOther->belongsClass());
     $this->setBelongsFunction($aOther->belongsFunction());
     $this->setBelongsNamespace($aOther->belongsNamespace());
     $this->setLine($aOther->line());
     $this->sType = $this->tokenTypeName();
 }
 public function matchExecutionPoint(Token $aToken)
 {
     $bIsPattern = $this->weaveMethodIsPattern();
     // 模糊匹配每个方法
     if ($bIsPattern and $aToken instanceof FunctionDefine) {
         // 必须是一个类方法
         if (!($aClass = $aToken->belongsClass())) {
             return false;
         }
         if (!$this->matchClass($aClass->fullName())) {
             return false;
         }
         return preg_match($this->weaveMethodNameRegexp(), $aToken->name()) ? true : false;
     } else {
         if (!$bIsPattern and $aToken instanceof ClosureToken) {
             // 必须是一个 "}"
             if ($aToken->tokenType() != Token::T_BRACE_CLOSE) {
                 return false;
             }
             // 必须成对
             if (!$aToken->theOther()) {
                 return false;
             }
             $aClass = $aToken->theOther()->belongsClass();
             if (null === $aClass) {
                 return false;
             }
             // 必须做为 class 的结束边界
             if ($aToken->theOther() !== $aClass->bodyToken()) {
                 return false;
             }
             if (!$this->matchClass($aClass->fullName())) {
                 return false;
             }
             return true;
         }
     }
 }
示例#3
0
 public function matchWeaveMethod(Token $aToken)
 {
     if (!($aClass = $aToken->belongsClass()) or $aMethod = $aToken->belongsFunction()) {
         return false;
     }
     if ($aClass->fullName() != $this->weaveClass()) {
         return false;
     }
     return preg_match($this->weaveMethodNameRegexp(), $aMethod->name());
 }