public static function createFromToken(FunctionDefine $aFunctionDefine, Aspect $aAspect) { if (!($aClassDefine = $aFunctionDefine->belongsClass())) { throw new Exception("传入的 \$aFunctionDefine 参数无效,必须是一个类方法的定义Token"); } if (!($aDocToken = $aFunctionDefine->docToken())) { throw new Exception("传入了无效Advice %s::%s() :没有DocComment申明。", array($aClassDefine->fullName(), $aFunctionDefine->name())); } $aDocComment = $aDocToken->docComment(); $sPosition = null; if ($aDocComment->hasItem('advice')) { $sPosition = $aDocComment->item('advice'); $sPosition = trim($sPosition); $sPosition = strtolower($sPosition); } if (!$sPosition) { $sPosition = self::after; } $aAdvice = new self($aFunctionDefine->name(), $aFunctionDefine->bodySource(), $sPosition, $aFunctionDefine); $aAdvice->aDefineAspect = $aAspect; // for pointcut foreach ($aDocComment->itemIterator('for') as $sPointcutName) { if (!($aPointcut = $aAspect->pointcuts()->getByName($sPointcutName))) { throw new Exception("定义Aspect %s 的 Advice %s 时,申明了一个不存在的 Pointcut: %s 。", array($sAspectName, $aAdvice->name(), $sPointcutName)); } $aAdvice->arrForPointcuts[] = $sPointcutName; } return $aAdvice; }