public function compile() { /* @var $classScanner \Zend\Code\Scanner\DerivedClassScanner */ foreach ($this->directoryScanner->getClasses() as $class) { $this->processClass($class); } }
public function testCreatesClass() { $ds = new DirectoryScanner(); $ds->addDirectory(__DIR__ . '/TestAsset'); $ads = new AggregateDirectoryScanner(); $ads->addDirectoryScanner($ds); $c = $ads->getClass('ZendTest\\Code\\Scanner\\TestAsset\\MapperExample\\RepositoryB'); $this->assertEquals('ZendTest\\Code\\Scanner\\TestAsset\\MapperExample\\RepositoryB', $c->getName()); }
public function processClass($className) { $strategy = $this->introspectionStrategy; $sClass = $this->directoryScanner->getClass($className, true, true); if (!$sClass->isInstantiable()) { return; } // determine supertypes $superTypes = array(); if (($parentClasses = $sClass->getParentClasses()) !== null) { $superTypes = array_merge($superTypes, $parentClasses); } if (($interfaces = $sClass->getInterfaces())) { $superTypes = array_merge($superTypes, $interfaces); } $className = $sClass->getName(); $this->classes[$className] = array( 'superTypes' => $superTypes, 'instantiator' => null, 'methods' => array(), 'parameters' => array() ); $def = &$this->classes[$className]; if ($def['instantiator'] == null) { if ($sClass->isInstantiable()) { $def['instantiator'] = '__construct'; } } if ($sClass->hasMethod('__construct')) { $mScanner = $sClass->getMethod('__construct'); if ($mScanner->isPublic() && $mScanner->getNumberOfParameters() > 0) { $def['methods']['__construct'] = true; $this->processParams($def, $sClass, $mScanner); } } foreach ($sClass->getMethods(true) as $mScanner) { if (!$mScanner->isPublic()) { continue; } $methodName = $mScanner->getName(); if ($mScanner->getName() === '__construct') { continue; } if ($strategy->getUseAnnotations() == true) { $annotations = $mScanner->getAnnotations($strategy->getAnnotationManager()); if (($annotations instanceof AnnotationCollection) && $annotations->hasAnnotation('Zend\Di\Definition\Annotation\Inject')) { $def['methods'][$methodName] = true; $this->processParams($def, $sClass, $mScanner); continue; } } $methodPatterns = $this->introspectionStrategy->getMethodNameInclusionPatterns(); // matches a method injection pattern? foreach ($methodPatterns as $methodInjectorPattern) { preg_match($methodInjectorPattern, $methodName, $matches); if ($matches) { $def['methods'][$methodName] = false; // check ot see if this is required? $this->processParams($def, $sClass, $mScanner); continue 2; } } } $interfaceInjectorPatterns = $this->introspectionStrategy->getInterfaceInjectionInclusionPatterns(); // matches the interface injection pattern /** @var $sInterface \Zend\Code\Scanner\ClassScanner */ foreach ($sClass->getInterfaces(true) as $sInterface) { foreach ($interfaceInjectorPatterns as $interfaceInjectorPattern) { preg_match($interfaceInjectorPattern, $sInterface->getName(), $matches); if ($matches) { foreach ($sInterface->getMethods(true) as $sMethod) { if ($sMethod->getName() === '__construct') { // ctor not allowed in ifaces continue; } $def['methods'][$sMethod->getName()] = true; $this->processParams($def, $sClass, $sMethod); } continue 2; } } } }