public function buildBean(array &$arrConfig, $sNamespace = '*', BeanFactory $aBeanFactory = null) { $aPointcut = new Pointcut('default_pointcut'); $aPointcut->setAspect($this); $this->pointcuts()->add($aPointcut); $nAdviceIdx = 0; foreach ($arrConfig as $key => &$item) { if (!is_int($key)) { continue; } // jointpoint if (is_string($item)) { foreach (array('JointPointMethodDefine', 'JointPointCallFunction', 'JointPointNewObject') as $sJointpointClass) { if ($aJointPoint = call_user_func(array(__NAMESPACE__ . '\\jointpoint\\' . $sJointpointClass, 'createFromDeclare'), $item)) { $aPointcut->jointPoints()->add($aJointPoint); $aJointPoint->setPointcut($aPointcut); break; } } } else { if (is_callable($item, true)) { // 源文 $sSource = Type::reflectFunctionBody($item); $aRefFunc = is_array($item) ? new \ReflectionMethod($item[0], $item[1]) : new \ReflectionFunction($item); // 函数定义时声明的 access 和 static if ($aRefFunc instanceof \ReflectionMethod) { if ($aRefFunc->isPrivate()) { $sAccess = 'private'; } else { if ($aRefFunc->isProtected()) { $sAccess = 'protected'; } else { if ($aRefFunc->isPublic()) { $sAccess = 'public'; } } } $bStatic = $aRefFunc->isStatic(); $sAdviceName = $aRefFunc->getDeclaringClass()->getName() . '::' . $aRefFunc->getName(); } else { $sAdviceName = 'nameless_' . $nAdviceIdx++; $sAccess = 'private'; $bStatic = false; } // 函数定义 注释中的 @use 和 @advice $arrUseDeclare = array(); if ($sComment = $aRefFunc->getDocComment()) { $aDocComment = new DocComment($sComment); // @use $arrUseDeclare = $aDocComment->items('use') ?: array(); // @advice $sPosition = $aDocComment->item('advice') ?: Advice::after; } else { $sPosition = Advice::after; } $aAdvice = new Advice($sAdviceName, $sSource, $sPosition); $aAdvice->addPointcutName($aPointcut->name()); $aAdvice->setDefineFile($aRefFunc->getFileName()); $aAdvice->setAccess($sAccess); $aAdvice->setStatic($bStatic); foreach ($arrUseDeclare as &$sUseDclare) { $aAdvice->addUseDeclare($sUseDclare); } $aPointcut->advices()->add($aAdvice); $this->advices()->add($aAdvice); $aAdvice->setAspect($this); } } } $this->arrBeanConfig =& $arrConfig; }
protected function generateAdviceCalltype(GenerateStat $aStat, Advice $aAdvice) { // 只有在 目标函数 和 切入函数同时为 动态方法时,才通过 $this-> 调用 advice return (!$aAdvice->isStatic() and !$aStat->aExecutePoint->staticToken()) ? '$this->' : 'self::'; }
protected function compileAdviceCode(GenerateStat $aStat, Advice $aAdvice, Advice $aNextAroundAdvice = null) { return $aAdvice->source(); }