src/mg/Ding/Bean/Provider/Annotation.php
private function _getBeanDefinition($name, $class, Collection $annotations, $fBean = false, $fMethod = false)
    {
        $def = $this->_getParentBeanDefinition($class);
        if ($def === null) {
            $def = new BeanDefinition($name);
        } else {
            $def = $def->makeChildBean($name);
        }
        if ($fBean) {
            $def->setFactoryBean($fBean);
            $def->setFactoryMethod($fMethod);
        }
        $rClass = $this->reflectionFactory->getClass($class);
        if ($rClass->isAbstract()) {
            $def->makeAbstract();
        } else {
            $def->makeConcrete();
        }
        $def->setClass($class);
        foreach ($this->_validBeanAnnotations as $beanAnnotationName) {
            if ($annotations->contains($beanAnnotationName)) {
                $beanAnnotation = $annotations->getSingleAnnotation($beanAnnotationName);
                break;
            }
        }
        if ($beanAnnotation->hasOption('class')) {
            $def->setClass($beanAnnotation->getOptionSingleValue('class'));
        }
        if ($beanAnnotation->hasOption('name')) {
            $names = $beanAnnotation->getOptionValues('name');
            foreach ($names as $alias) {
                $def->addAlias($alias);
            }
        }
        $def->setName($name);
        if ($annotations->contains('scope')) {
            $annotation = $annotations->getSingleAnnotation('scope');
            if ($annotation->hasOption('value')) {
                $scope = $annotation->getOptionSingleValue('value');
                if ($scope == 'singleton') {
                    $def->setScope(BeanDefinition::BEAN_SINGLETON);
                } else if ($scope == 'prototype') {
                    $def->setScope(BeanDefinition::BEAN_PROTOTYPE);
                } else {
                    throw new BeanFactoryException("Invalid bean scope: $scope");
                }
            }
        } else if ($annotations->contains('singleton')) {
            $def->setScope(BeanDefinition::BEAN_SINGLETON);
        } else if ($annotations->contains('prototype')) {
            $def->setScope(BeanDefinition::BEAN_PROTOTYPE);
        }
        $isPrimary = $annotations->contains('primary');
        if (!$isPrimary) {
            if ($beanAnnotation->hasOption('primary')) {
                $isPrimary = $beanAnnotation->getOptionSingleValue('primary') == 'true';
            }
        }
        if ($isPrimary) {
            $def->markAsPrimaryCandidate();
        }
        if ($annotations->contains('initmethod')) {
            $annotation = $annotations->getSingleAnnotation('initmethod');
            if ($annotation->hasOption('method')) {
                $def->setInitMethod($annotation->getOptionSingleValue('method'));
            }
        }
        if ($annotations->contains('destroymethod')) {
            $annotation = $annotations->getSingleAnnotation('destroymethod');
            if ($annotation->hasOption('method')) {
                $def->setDestroyMethod($annotation->getOptionSingleValue('method'));
            }
        }
        return $def;
    }
private function _getBeanDefinition($name, $class, Collection $annotations, $fBean = false, $fMethod = false)
    {
        $def = $this->_getParentBeanDefinition($class);
        if ($def === null) {
            $def = new BeanDefinition($name);
        } else {
            $def = $def->makeChildBean($name);
        }
        if ($fBean) {
            $def->setFactoryBean($fBean);
            $def->setFactoryMethod($fMethod);
        }
        $rClass = $this->reflectionFactory->getClass($class);
        if ($rClass->isAbstract()) {
            $def->makeAbstract();
        } else {
            $def->makeConcrete();
        }
        $def->setClass($class);
        foreach ($this->_validBeanAnnotations as $beanAnnotationName) {
            if ($annotations->contains($beanAnnotationName)) {
                $beanAnnotation = $annotations->getSingleAnnotation($beanAnnotationName);
                break;
            }
        }
        if ($beanAnnotation->hasOption('class')) {
            $def->setClass($beanAnnotation->getOptionSingleValue('class'));
        }
        if ($beanAnnotation->hasOption('name')) {
            $names = $beanAnnotation->getOptionValues('name');
            foreach ($names as $alias) {
                $def->addAlias($alias);
            }
        }
        $def->setName($name);
        if ($annotations->contains('scope')) {
            $annotation = $annotations->getSingleAnnotation('scope');
            if ($annotation->hasOption('value')) {
                $scope = $annotation->getOptionSingleValue('value');
                if ($scope == 'singleton') {
                    $def->setScope(BeanDefinition::BEAN_SINGLETON);
                } else if ($scope == 'prototype') {
                    $def->setScope(BeanDefinition::BEAN_PROTOTYPE);
                } else {
                    throw new BeanFactoryException("Invalid bean scope: $scope");
                }
            }
        } else if ($annotations->contains('singleton')) {
            $def->setScope(BeanDefinition::BEAN_SINGLETON);
        } else if ($annotations->contains('prototype')) {
            $def->setScope(BeanDefinition::BEAN_PROTOTYPE);
        }
        $isPrimary = $annotations->contains('primary');
        if (!$isPrimary) {
            if ($beanAnnotation->hasOption('primary')) {
                $isPrimary = $beanAnnotation->getOptionSingleValue('primary') == 'true';
            }
        }
        if ($isPrimary) {
            $def->markAsPrimaryCandidate();
        }
        if ($annotations->contains('initmethod')) {
            $annotation = $annotations->getSingleAnnotation('initmethod');
            if ($annotation->hasOption('method')) {
                $def->setInitMethod($annotation->getOptionSingleValue('method'));
            }
        }
        if ($annotations->contains('destroymethod')) {
            $annotation = $annotations->getSingleAnnotation('destroymethod');
            if ($annotation->hasOption('method')) {
                $def->setDestroyMethod($annotation->getOptionSingleValue('method'));
            }
        }
        return $def;
    }
Creates a bean definition from the given annotations.

@param string $name Bean name.
@param string $class Bean class.
@param Collection $annotations Annotations with data.

@return BeanDefinition