Esempio n. 1
0
 /**
  * @param ModuleEvent $event
  * @throws Exception
  */
 public function onMergeConfig(ModuleEvent $event)
 {
     // do not parse annotations if config cache is enabled.
     $config = $event->getConfigListener()->getMergedConfig(false);
     $annotationReader = AnnotationReaderFactory::factory($config['zf_annotation']);
     $parser = ClassParserFactory::factory($config, $event->getTarget()->getEventManager(), $annotationReader);
     $scanner = new DirectoryScanner();
     $classesToParse = [];
     $modules = $event->getTarget()->getLoadedModules();
     $modulesAllowedToScan = $config['zf_annotation']['scan_modules'];
     foreach ($modules as $module) {
         $parts = explode('\\', get_class($module));
         $modName = array_shift($parts);
         if (!empty($modulesAllowedToScan) && !in_array($modName, $modulesAllowedToScan)) {
             continue;
         }
         $ref = new ReflectionClass($module);
         $dir = dirname($ref->getFileName());
         foreach ($scanner->scan($dir) as $class) {
             $classesToParse[] = $class;
         }
     }
     $parsedConfig = $parser->parse($classesToParse);
     $event->getConfigListener()->setMergedConfig(array_replace_recursive($parsedConfig, $config));
 }
 public function testCanCreateViaStaticMethod()
 {
     $eventManager = new EventManager();
     $annotationReader = AnnotationReaderFactory::factory($this->config['zf_annotation']);
     $this->assertInstanceOf(ClassParser::class, ClassParserFactory::factory($this->config, $eventManager, $annotationReader));
 }