public static function createFromToken(ClassDefine $aClassToken, $sAspectFilepath = null) { $sAspectName = $aClassToken->fullName(); $aTokenPool = $aClassToken->parent(); $aAspect = new self($sAspectName); // 先定义 pointcut foreach ($aTokenPool->functionIterator($sAspectName) as $aMethodToken) { if (!($aDocCommentToken = $aMethodToken->docToken()) or !($aDocComment = $aDocCommentToken->docComment())) { continue; } // pointcut if ($aDocComment->hasItem('pointcut')) { $aPointcut = Pointcut::createFromToken($aMethodToken); $aAspect->pointcuts()->add($aPointcut); } } // 然后定义 advice foreach ($aTokenPool->functionIterator($sAspectName) as $aMethodToken) { if (!($aDocCommentToken = $aMethodToken->docToken()) or !($aDocComment = $aDocCommentToken->docComment())) { continue; } if ($aDocComment->hasItem('advice')) { $aAdvice = Advice::createFromToken($aMethodToken, $aAspect); $aAspect->addAdvice($aAdvice); } } $aAspect->sAspectName = $sAspectName; if ($sAspectFilepath) { $aAspect->setAspectFilepath(FSO::tidyPath($sAspectFilepath)); } return $aAspect; }
/** * @return AOP */ public function registerBean(array $arrConfig, $sAspectDefineFile = null) { if (empty($arrConfig['class'])) { $arrConfig['class'] = 'aspect'; } $aAspect = BeanFactory::singleton()->createBean($arrConfig); if ($sAspectDefineFile) { $aAspect->setAspectFilepath(FSO::tidyPath($sAspectDefineFile)); } $this->aspects()->add($aAspect); $this->aPointcutIterator = null; $this->aJointPointIterator = null; return $this; }
public function serialize() { return FSO::tidyPath($this->aRootFolder->path()); }