/** * Will call HttpUrlMapper::addAnnotatedController to add new mappings * from the @Controller annotated classes. Also, creates a new bean * definition for every one of them. * * (non-PHPdoc) * @see Ding\Bean\Lifecycle.ILifecycleListener::afterConfig() */ public function afterConfig() { foreach ($this->reflectionFactory->getClassesByAnnotation('controller') as $controller) { foreach ($this->_container->getBeansByClass($controller) as $name) { $annotations = $this->reflectionFactory->getClassAnnotations($controller); if (!$annotations->contains('requestmapping')) { continue; } $requestMappings = $annotations->getAnnotations('requestmapping'); foreach ($requestMappings as $map) { if ($map->hasOption('url')) { foreach ($map->getOptionValues('url') as $url) { HttpUrlMapper::addAnnotatedController($url, $name); } } } } } }
private function _inject($name, Annotation $annotation, $class = null, Annotation $named = null) { $ret = false; $required = true; if ($annotation->hasOption('required')) { $required = $annotation->getOptionSinglevalue('required') == 'true'; } if (!$annotation->hasOption('type')) { if ($class === null) { throw new InjectByTypeException($name, 'Unknown', "Missing type= specification"); } } else { $class = $annotation->getOptionSingleValue('type'); } $isArray = strpos(substr($class, -2), "[]") !== false; if ($isArray) { $class = substr($class, 0, -2); $ret = array(); } $candidates = $this->_container->getBeansByClass($class); if (empty($candidates)) { if ($required) { throw new InjectByTypeException($name, $class, "Did not find any candidates for injecting by type"); } else { return array(); } } if (!$isArray && count($candidates) > 1) { $preferredName = null; if ($named !== null) { if (!$named->hasOption('name')) { throw new InjectByTypeException($name, 'Unknown', "@Named needs the name= specification"); } $preferredName = $named->getOptionSingleValue('name'); } if ($preferredName !== null) { if (in_array($preferredName, $candidates)) { $candidates = array($preferredName); } else { throw new InjectByTypeException($name, 'Unknown', "Specified bean name in @Named not found"); } } else { $foundPrimary = false; $beans = $candidates; foreach ($beans as $beanName) { $beanCandidateDef = $this->_container->getBeanDefinition($beanName); if ($beanCandidateDef->isPrimaryCandidate()) { if ($foundPrimary) { throw new InjectByTypeException($name, $class, "Too many (primary) candidates for injecting by type"); } $foundPrimary = true; $candidates = array($beanName); } } } if (count($candidates) > 1) { throw new InjectByTypeException($name, $class, "Too many candidates for injecting by type"); } } if ($isArray) { $propertyValue = array(); foreach ($candidates as $value) { $ret[] = $value; } } else { $ret = array_shift($candidates); } return $ret; }