/** * * @param Component $component * @param array $compoentAnnotations * @throws OutjectionException when error happened while outjection property */ public function handle($component, $compoentAnnotations) { $properties = $compoentAnnotations['properties']; foreach ($properties as $property => $propertyDefinition) { $annotations = $propertyDefinition['annotations']; $outAnnotation = AnnotationManager::instance()->getAnnotation($annotations, self::OUT_ANNOTATION, $this->getTargetReflection($component, $property)); if (null !== $outAnnotation) { $outjectKey = $outAnnotation->value === null ? $property : $outAnnotation->value; if ($outAnnotation->required && $component->{$property} === null) { $class = get_class($component); throw new OutjectionException("{$class}::{$property} outjection value is required."); } Scopes::instance()->setToScope($outAnnotation->scope, $outjectKey, $component->{$property}); } } }
/** * * @param array $definitions * @param ReflectionMethod $target * @param array $reflectionParameters * @param array $parameters * @return array */ private function requestParameterized($definitions, $target, $reflectionParameters, $parameters) { $annotation = AnnotationManager::instance()->getAnnotation($definitions['annotations'], self::REQUEST_PARAMETERIZED_ANNOTATION, $target); if (null !== $annotation) { $startIndex = $annotation->required ? 0 : count($parameters); for ($i = $startIndex; $i < count($reflectionParameters); $i++) { $reflectionParameter = $reflectionParameters[$i]; $paramName = $reflectionParameter->getName(); $paramValue = Request::instance()->get($paramName); if ($paramValue === null && $reflectionParameter->isDefaultValueAvailable()) { $paramValue = $reflectionParameter->getDefaultValue(); } elseif ($paramValue === null && !$reflectionParameter->isOptional()) { throw new InjectionException("No request parameter for\r\n {$reflectionParameter->getDeclaringClass()->getName()}::{$reflectionParameter->getDeclaringFunction()->getName()}#{$paramName}"); } $parameters[] = $paramValue; } return $parameters; } }
/** * Singleton constructor. */ private function __construct() { $this->annotationManager = AnnotationManager::instance(); }
/** * * @param string $componentName name of component * @throws ComponentException if component name not found * @return int scope type */ public static function getComponentScope($component) { $component = self::getFullyQualifiedName($component); if (isset(Deployment::instance()->components[$component])) { $componentDefinition = Deployment::instance()->components[$component]; $componentAnnotations = $componentDefinition['annotations']; $scopeAnnotation = AnnotationManager::instance()->getAnnotation($componentAnnotations, 'Scope', $component); if (null !== $scopeAnnotation) { return $scopeAnnotation->value; } return ScopeType::UNSPECIFIED; } throw new ComponentException("Undefined component: {$component}"); }