bitExpert\Disco\AnnotationBeanFactory::get PHP Метод

get() публичный Метод

{@inheritDoc}
public get ( $id )
    public function get($id)
    {
        if (!is_string($id) || empty($id)) {
            throw new BeanException('Id must be a non-empty string.');
        }
        $instance = null;
        try {
            if (is_callable([$this->beanConfig, $id])) {
                $instance = $this->beanConfig->{$id}();
            } elseif ($this->beanConfig->hasAlias($id)) {
                $instance = $this->beanConfig->getAlias($id);
            }
        } catch (\Throwable $e) {
            $message = sprintf('Exception occurred while instantiating "%s": %s', $id, $e->getMessage());
            throw new BeanException($message, $e->getCode(), $e);
        }
        if (null === $instance) {
            throw new BeanNotFoundException(sprintf('"%s" is not defined!', $id));
        }
        return $instance;
    }

Usage Example

 /**
  * @test
  */
 public function retrievingProtectedBeanByAlias()
 {
     $this->beanFactory = new AnnotationBeanFactory(BeanConfigurationWithAliases::class);
     BeanFactoryRegistry::register($this->beanFactory);
     self::assertFalse($this->beanFactory->has('internalServiceWithAlias'));
     self::assertTrue($this->beanFactory->has('aliasIsPublicForInternalService'));
     self::assertInstanceOf(SampleService::class, $this->beanFactory->get('aliasIsPublicForInternalService'));
 }
AnnotationBeanFactory