/** * @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)); }
/** * * @param string $class * @param array $config * @return ClassAnnotationHolder */ public function parse($class, array $config = array()) { $annotationReader = AnnotationReaderFactory::factory(['annotations' => [], 'cache' => null, 'cache_debug' => false, 'ignored_annotations' => ['events'], 'namespaces' => ['ZfAnnotation\\Annotation' => __DIR__ . '/../../src']]); $eventManager = new EventManager(); $parser = new ClassParser($config, $annotationReader, $eventManager); return $this->handleClassAnnotations($parser->parseClass($class), $config); }
/** * * @param array $config * @param EventManagerInterface $eventManager * @param Reader $annotationReader * @return ClassParser */ public static function factory(array $config, EventManagerInterface $eventManager, Reader $annotationReader = null) { if (null === $annotationReader) { $annotationReader = AnnotationReaderFactory::factory($config['zf_annotation']); } $parser = new ClassParser($config, $annotationReader, $eventManager); foreach ($config['zf_annotation']['event_listeners'] as $listener) { $parser->attach(new $listener()); } return $parser; }
public function testCanCreateViaStaticMethod() { $eventManager = new EventManager(); $annotationReader = AnnotationReaderFactory::factory($this->config['zf_annotation']); $this->assertInstanceOf(ClassParser::class, ClassParserFactory::factory($this->config, $eventManager, $annotationReader)); }
public function testCreatesCachedReader() { $config = $this->config; $config['zf_annotation']['cache'] = sys_get_temp_dir(); $this->assertInstanceOf(CachedReader::class, AnnotationReaderFactory::factory($config['zf_annotation'])); }