Swoft 框架运行分析(三) —— BeanProcessor模块分析
今天讲一下BeanProcessor模块,先看一下handle方法实现。 /** * Handle bean * * @return bool * @throws ReflectionException * @throws AnnotationException */ public function handle(): bool { if (!$this->application->beforeBean()) { return false; } $handler = new BeanHandler(); $definitions = $this->getDefinitions(); $parsers = AnnotationRegister::getParsers(); $annotations = AnnotationRegister::getAnnotations(); BeanFactory::addDefinitions($definitions); BeanFactory::addAnnotations($annotations); BeanFactory::addParsers($parsers); BeanFactory::setHandler($handler); BeanFactory::init(); /* @var Config $config*/ $config = BeanFactory::getBean('config'); CLog::info('config path=%s', $config->getPath()); CLog::info('config env=%s', $config->getEnv()); $stats = BeanFactory::getStats(); CLog::info('Bean is initialized(%s)', SwoftHelper::formatStats($stats)); return $this->application->afterBean(); } 先通过getDefinitions方法获取所有的Bean定义。 ...