Inheritance: implements ScannerInterface
Ejemplo n.º 1
0
 public function compileScannerInjectionMethods(ClassScanner $scannerClass)
 {
     $data      = array();
     $className = $scannerClass->getName();
     foreach ($scannerClass->getMethods(true) as $scannerMethod) {
         $methodName = $scannerMethod->getName();
         
         // determine initiator & constructor dependencies
         if ($methodName === '__construct' && $scannerMethod->isPublic()) {
             $params = $scannerMethod->getParameters(true);
             if ($params) {
                 $data[$methodName] = array();
                 foreach ($params as $param) {
                     $data[$methodName][$param->getName()] = $param->getClass();
                 }
             }
         }
         
         // scan for setter injection
         if (preg_match('#^set[A-Z]#', $methodName)) {
             $data[$methodName] = $scannerMethod->getParameters();
             $params = $scannerMethod->getParameters(true);
             $data[$methodName] = array();
             foreach ($params as $param) {
                 $data[$methodName][$param->getName()] = $param->getClass();
             }
         }
     }
     return $data;
 }
Ejemplo n.º 2
0
 public function handleClassAnnotation(Service $annotation, ClassScanner $class)
 {
     if (!$annotation->getName()) {
         $annotation->setName($class->getName());
     }
     switch ($annotation->getType()) {
         case 'invokable':
             $this->definitions[$annotation->getServiceManager()]['invokables'][$annotation->getName()] = $class->getName();
             break;
         case 'factory':
             if (!in_array(FactoryInterface::class, $class->getInterfaces())) {
                 throw new InvalidAnnotationException('Service factory class must implement "' . FactoryInterface::class . '".');
             }
             $this->definitions[$annotation->getServiceManager()]['factories'][$annotation->getName()] = $class->getName();
             break;
         case 'abstractFactory':
             if (!in_array(AbstractFactoryInterface::class, $class->getInterfaces())) {
                 throw new InvalidAnnotationException('Abstract service factory class must implement "' . AbstractFactoryInterface::class . '".');
             }
             $this->definitions[$annotation->getServiceManager()]['abstract_factories'][] = $class->getName();
             break;
         case 'initializer':
             if (!in_array(InitializerInterface::class, $class->getInterfaces())) {
                 throw new InvalidAnnotationException('Initializer must implement "' . InitializerInterface::class . '".');
             }
             $this->definitions[$annotation->getServiceManager()]['initializers'][] = $class->getName();
             break;
         case 'delegator':
             if (!in_array(DelegatorFactoryInterface::class, $class->getInterfaces())) {
                 throw new InvalidAnnotationException('Delegator must implement "' . DelegatorFactoryInterface::class . '".');
             }
             if (empty($annotation->getFor())) {
                 throw new InvalidAnnotationException('Delegator annotation must contain "for" option.');
             }
             if (!isset($this->definitions[$annotation->getServiceManager()]['delegators'][$annotation->getFor()])) {
                 $this->definitions[$annotation->getServiceManager()]['delegators'][$annotation->getFor()] = array();
             }
             $this->definitions[$annotation->getServiceManager()]['delegators'][$annotation->getFor()][] = $class->getName();
             break;
         default:
             throw new InvalidAnnotationException('Service annotation must have "type" property value. Seen in ' . $class->getName());
     }
     $allowedToShareAndAlias = array('invokable', 'factory');
     if (in_array($annotation->getType(), $allowedToShareAndAlias)) {
         if (is_bool($annotation->getShared())) {
             $this->definitions[$annotation->getServiceManager()]['shared'][$annotation->getName()] = $annotation->getShared();
         }
         foreach ($annotation->getAliases() as $alias) {
             $this->definitions[$annotation->getServiceManager()]['aliases'][$alias] = $annotation->getName();
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * Retrieve class footprint from class scanner
  *
  * @param ClassScanner $class
  *
  * @return ClassFootprint
  */
 protected function getClassFootprint(ClassScanner $class)
 {
     $footprint = new ClassFootprint();
     if ($class->isInterface()) {
         $footprint->setType(ClassFootprint::TYPE_INTERFACE);
     } elseif ($class->isTrait()) {
         $footprint->setType(ClassFootprint::TYPE_TRAIT);
     }
     $footprint->setParent($class->getParentClass());
     foreach ($class->getConstants(false) as $constant) {
         $footprint->addConstant($constant->getName(), $constant->getValue());
     }
     foreach ($class->getInterfaces() as $interface) {
         $footprint->addInterface($interface);
     }
     return $footprint;
 }
Ejemplo n.º 4
0
 /**
  * @param  string $name
  * @return bool
  */
 public function hasMethod($name)
 {
     if ($this->classScanner->hasMethod($name)) {
         return true;
     }
     foreach ($this->parentClassScanners as $pClassScanner) {
         if ($pClassScanner->hasMethod($name)) {
             return true;
         }
     }
     return false;
 }
Ejemplo n.º 5
0
 /**
  * 
  * @param ClassScanner $class
  * @return ClassAnnotationHolder
  */
 public function parseClass(ClassScanner $class)
 {
     $classAnnotationHolder = new ClassAnnotationHolder($class);
     $classAnnotations = $class->getAnnotations($this->annotationManager);
     if ($classAnnotations instanceof AnnotationCollection) {
         foreach ($classAnnotations as $annotation) {
             $classAnnotationHolder->addAnnotation($annotation);
         }
     } else {
         $classAnnotations = new AnnotationCollection(array());
     }
     foreach ($class->getMethods() as $method) {
         // zf can't process abstract methods for now, wrap with "try" block
         $methodAnnotationHolder = new MethodAnnotationHolder($method);
         $methodAnnotations = $method->getAnnotations($this->annotationManager);
         if ($methodAnnotations instanceof AnnotationCollection) {
             foreach ($methodAnnotations as $annotation) {
                 $methodAnnotationHolder->addAnnotation($annotation);
             }
         }
         $classAnnotationHolder->addMethod($methodAnnotationHolder);
     }
     return $classAnnotationHolder;
 }
Ejemplo n.º 6
0
 /**
  * @param ClassScanner $classScanner
  * @param ClassScanner[] $allClasses
  * @return array | false
  */
 protected function collectDataForClass(ClassScanner $classScanner, array $allClasses)
 {
     if ($classScanner->isInterface() || $classScanner->isAbstract()) {
         return false;
     }
     $classArr = array('properties' => array());
     $classArr = array_merge($classArr, $this->processClassAnnotations($classScanner));
     return array_merge($classArr, $this->processPropertiesAnnotations($classScanner, $allClasses));
 }
Ejemplo n.º 7
0
 /**
  * @param AnnotationInterface $annotation
  * @param ClassScanner $class
  * @throws InvalidArgumentException
  */
 public function annotationToRouteConfig(AnnotationInterface $annotation, ClassScanner $class, MethodScanner $method = null)
 {
     $method = $method ?: 'index';
     $annotation = $this->guessMissingFields($annotation, $method, $class->getName());
     $routeConfig = $this->getRouteConfig($annotation);
     if ($annotation->getExtends()) {
         $tmp = array();
         $ref =& $this->getReferenceForPath(explode('/', $annotation->getExtends()), $tmp);
         $ref = $routeConfig;
         return $tmp;
     } else {
         return $routeConfig;
     }
 }