Go\Core\AdviceMatcher::getAdvicesForFunctions PHP Method

getAdvicesForFunctions() public method

Returns list of function advices for namespace
public getAdvicesForFunctions ( Go\ParserReflection\ReflectionFileNamespace $namespace, array $advisors ) : array
$namespace Go\ParserReflection\ReflectionFileNamespace
$advisors array List of advisor to match
return array
    public function getAdvicesForFunctions(ReflectionFileNamespace $namespace, array $advisors)
    {
        if (!$this->isInterceptFunctions || $namespace->getName() == 'no-namespace') {
            return [];
        }
        $advices = [];
        foreach ($advisors as $advisorId => $advisor) {
            if ($advisor instanceof Aop\PointcutAdvisor) {
                $pointcut = $advisor->getPointcut();
                $isFunctionAdvisor = $pointcut->getKind() & Aop\PointFilter::KIND_FUNCTION;
                if ($isFunctionAdvisor && $pointcut->getClassFilter()->matches($namespace)) {
                    $advices = array_merge_recursive($advices, $this->getFunctionAdvicesFromAdvisor($namespace, $advisor, $advisorId, $pointcut));
                }
            }
        }
        return $advices;
    }

Usage Example

Beispiel #1
0
 /**
  * Performs weaving of functions in the current namespace
  *
  * @param array|Advisor[] $advisors List of advisors
  * @param StreamMetaData $metadata Source stream information
  * @param ReflectionFileNamespace $namespace Current namespace for file
  *
  * @return boolean True if functions were processed, false otherwise
  */
 private function processFunctions(array $advisors, StreamMetaData $metadata, $namespace)
 {
     static $cacheDirSuffix = '/_functions/';
     $wasProcessedFunctions = false;
     $functionAdvices = $this->adviceMatcher->getAdvicesForFunctions($namespace, $advisors);
     $cacheDir = $this->cachePathManager->getCacheDir();
     if (!empty($functionAdvices) && $cacheDir) {
         $cacheDir = $cacheDir . $cacheDirSuffix;
         $fileName = str_replace('\\', '/', $namespace->getName()) . '.php';
         $functionFileName = $cacheDir . $fileName;
         if (!file_exists($functionFileName) || !$this->container->isFresh(filemtime($functionFileName))) {
             $dirname = dirname($functionFileName);
             if (!file_exists($dirname)) {
                 mkdir($dirname, $this->options['cacheFileMode'], true);
             }
             $source = new FunctionProxy($namespace, $functionAdvices);
             file_put_contents($functionFileName, $source, LOCK_EX);
             // For cache files we don't want executable bits by default
             chmod($functionFileName, $this->options['cacheFileMode'] & ~0111);
         }
         $content = 'include_once AOP_CACHE_DIR . ' . var_export($cacheDirSuffix . $fileName, true) . ';' . PHP_EOL;
         $metadata->source .= $content;
         $wasProcessedFunctions = true;
     }
     return $wasProcessedFunctions;
 }
All Usage Examples Of Go\Core\AdviceMatcher::getAdvicesForFunctions