Swoft 框架运行分析(五) —— ConsoleProcessor模块分析

这里以Swoft启动http server为例。 php bin/swoft http:start 执行上述命令,启动http server。 在前面第一篇文章的时候,提到了如何启动http服务。 今天我们就来看一下http服务是如何启动的,具体实现就在ConsoleProcess这个模块。 ...

2019-09-26 · 10 min · 4524 words · Liudon

Swoft 框架运行分析(四) —— EventProcessor模块分析

今天我们来看一下EventProcessor的实现。 /** * Handle event register * @return bool */ public function handle(): bool { if (!$this->application->beforeEvent()) { CLog::warning('Stop event processor by beforeEvent return false'); return false; } /** @var EventManager $eventManager */ $eventManager = bean('eventManager'); [$count1, $count2] = ListenerRegister::register($eventManager); CLog::info('Event manager initialized(%d listener, %d subscriber)', $count1, $count2); // Trigger a app init event Swoft::trigger(SwoftEvent::APP_INIT_COMPLETE); return $this->application->afterEvent(); } 获取eventManager的Bean实例,对应为Swoft\Event\Manager\EventManager类。 ...

2019-09-26 · 4 min · 1896 words · Liudon

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定义。 ...

2019-09-02 · 9 min · 4044 words · Liudon

Swoft 框架运行分析(二) —— AnnotationProcessor模块分析

上一篇介绍了,SwoftApplication里定义了6个Processor对象。 protected function processors(): array { return [ new EnvProcessor($this), new ConfigProcessor($this), new AnnotationProcessor($this), new BeanProcessor($this), new EventProcessor($this), new ConsoleProcessor($this), ]; } 所有的Processor实现都在framework\src\Processor目录下。 ...

2019-08-29 · 4 min · 1656 words · Liudon

Swoft 框架运行分析(一)

Swoft 是一款基于 Swoole 扩展实现的 PHP 微服务协程框架。 以前一直都是用的原生swoole框架,最近有时间研究了下衍生的Swoft框架。 刚开始看的时候,感觉自己像个原始人,完全看不懂。 ...

2019-08-29 · 2 min · 966 words · Liudon