public function getInterfaces($returnClassScanners = false) { if ($returnClassScanners) { return $this->interfaceClassScanners; } $interfaces = $this->classScanner->getInterfaces(); foreach ($this->parentClassScanners as $pClassScanner) { $interfaces = array_merge($interfaces, $pClassScanner->getInterfaces()); } return $interfaces; }
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(); } } }
/** * 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; }