예제 #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;
 }
예제 #2
0
 /**
  * Check that list of advices for fields works correctly
  */
 public function testGetSinglePropertyAdviceForClassFromAdvisor()
 {
     $propName = 'adviceMatcher';
     // $this->adviceMatcher;
     $pointcut = $this->getMock(Pointcut::class);
     $pointcut->expects($this->any())->method('getClassFilter')->will($this->returnValue(TruePointFilter::getInstance()));
     $pointcut->expects($this->any())->method('matches')->will($this->returnCallback(function ($point) use($propName) {
         return $point->name === $propName;
     }));
     $pointcut->expects($this->any())->method('getKind')->will($this->returnValue(Pointcut::KIND_PROPERTY));
     $advice = $this->getMock(Advice::class);
     $advisor = new DefaultPointcutAdvisor($pointcut, $advice);
     $advices = $this->adviceMatcher->getAdvicesForClass($this->reflectionClass, array($advisor));
     $this->assertArrayHasKey(AspectContainer::PROPERTY_PREFIX, $advices);
     $this->assertArrayHasKey($propName, $advices[AspectContainer::PROPERTY_PREFIX]);
     $this->assertCount(1, $advices[AspectContainer::PROPERTY_PREFIX]);
 }
예제 #3
0
 /**
  * Performs weaving of functions in the current namespace
  *
  * @param StreamMetaData $metadata Source stream information
  * @param ParsedFileNamespace $namespace Current namespace for file
  */
 private function processFunctions(StreamMetaData $metadata, $namespace)
 {
     $functionAdvices = $this->adviceMatcher->getAdvicesForFunctions($namespace);
     if ($functionAdvices && $this->options['cacheDir']) {
         $cacheDirSuffix = '/_functions/';
         $cacheDir = $this->options['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, 0770, true);
             }
             $source = new FunctionProxy($namespace, $functionAdvices);
             file_put_contents($functionFileName, $source);
         }
         $content = 'include_once AOP_CACHE_DIR . ' . var_export($cacheDirSuffix . $fileName, true) . ';' . PHP_EOL;
         $metadata->source .= $content;
     }
 }