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();
}
}
}