swoft 启动流程分析
2018-12-04 15:13:53 0 举报
swoft启动流程分析
作者其他创作
大纲/内容
是
getCoreBean
Array( [0] = Swoft\\Cache [1] = Swoft\\Console [2] = Swoft\\DataParser [3] = Swoft\\Db [4] = Swoft\\Devtool [5] = Swoft [6] = Swoft\\HttpClient [7] = Swoft\\Http\\Message [8] = Swoft\\Http\\Server [9] = Swoft\\I18n [10] = Swoft\\Memory [11] = Swoft\\Process [12] = Swoft\\Redis [13] = Swoft\\Rpc [14] = Swoft\\Rpc\\Client [15] = Swoft\\Rpc\\Server [16] = Swoft\\Sg [17] = Swoft\\Session [18] = Swoft\\Swoole\\Ide\\Helper [19] = Swoft\\Task [20] = Swoft\\View [21] = Swoft\\WebSocket\\Server)
2. 引入define.php
4。addDefinitions
单个格式
[Swoft\\Rpc\\Server\\Command\\RpcCommand] = Array ( [name] = [enabled] = 1 [coroutine] = [server] = 1 [routes] = Array ( [0] = Array ( [mappedName] = [methodName] = start ) [1] = Array ( [mappedName] = [methodName] = reload ) [2] = Array ( [mappedName] = [methodName] = stop ) [3] = Array ( [mappedName] = [methodName] = restart ) ) )
parseBeanAnnotations
5。initBeans
1. composer 自动加载
是否输入命令
$coreBeans
1. $properties = self::getProperties();2. self::$container = new Container(); self::$container-setProperties($properties); self::$container-autoloadServerAnnotation();3. $definition = self::getServerDefinition();4. self::$container-addDefinitions($definition);5. self::$container-initBeans();
/* @var HandlerMapping $router */ $router = App::getBean('commandRoute'); if (!$handler = $router-getHandler()) { \\output()-colored(\"The entered command does not exist! command = $cmd\
collector 收集的
//\\Swoft\\Console\\Command$command = App::getBean('command');
doHandler
否
$route = App::getBean('commandRoute'); $commandMapping = CommandCollector::getCollector(); $route-register($commandMapping);
classNames
$resource-getDefinitions();
// annotation parser,得到解决类的parser $annotationParser = $this-getAnnotationParser($annotation); 比如说 Command的Parser is CommandParser// 得到分析出来的数据
executeCommandByCoroutine
实例化console
Array( [App\\Commands\\TestCommand] = Array ( [class] = Array ( [Swoft\\Console\\Bean\\Annotation\\Command] = Swoft\\Console\\Bean\\Annotation\\Command Object ( [name:Swoft\\Console\\Bean\\Annotation\\Command:private] = [enabled:Swoft\\Console\\Bean\\Annotation\\Command:private] = 1 [coroutine:Swoft\\Console\\Bean\\Annotation\\Command:private] = [server:Swoft\\Console\\Bean\\Annotation\\Command:private] = ) ) [method] = Array ( [test] = Array ( [Swoft\\Console\\Bean\\Annotation\\Mapping] = Array ( [0] = Swoft\\Console\\Bean\\Annotation\\Mapping Object ( [name:Swoft\\Console\\Bean\\Annotation\\Mapping:private] = test2 ) ) ) [demo] = Array ( [Swoft\\Console\\Bean\\Annotation\\Mapping] = Array ( [0] = Swoft\\Console\\Bean\\Annotation\\Mapping Object ( [name:Swoft\\Console\\Bean\\Annotation\\Mapping:private] = ) ) ) [task] = Array ( [Swoft\\Console\\Bean\\Annotation\\Mapping] = Array ( [0] = Swoft\\Console\\Bean\\Annotation\\Mapping Object ( [name:Swoft\\Console\\Bean\\Annotation\\Mapping:private] = ) ) ) ) ))
executeCommand
2 register
2. 初始化容器
$bootstrap = \\Swoft\\App::getBean(\\Swoft\\Bootstrap\\Bootstrap::class);$bootstrap-bootstrap();
componentNamespaces
3,server 定义的bean
循环初始化
引入bootstrap文件
bootstraps
run()
parseClassAnnotations
1. LoadEnv 加载.env环境变量2. InitPhpEnv设置php 环境变量3. LoadInitConfiguration加载define.php配置文件
$console-run();
parseAnnotationsData
4. get Bootstrap bean 并运行
将扫描目录,添加到扫描命名空间:addScanNamespace() { $this-registerNamespace();}
Array( [commandRoute] = Array ( [class] = Swoft\\Console\\Router\\HandlerMapping ))
解析的所有的值存储在:$this-definitions中。1. Wrapper $annotationWrapperClassName = \"{$beanNamespace}\\\\Wrapper\\\\{$classFileName}Wrapper\
doWrapper()
3. BeanFactory::init(); 注册所有的Bean
Array( [App\\Commands\\TestCommand] = Swoft\\Bean\\ObjectDefinition Object ( [name:Swoft\\Bean\\ObjectDefinition:private] = App\\Commands\\TestCommand [className:Swoft\\Bean\\ObjectDefinition:private] = App\\Commands\\TestCommand [scope:Swoft\\Bean\\ObjectDefinition:private] = 1 [ref:Swoft\\Bean\\ObjectDefinition:private] = [constructorInjection:Swoft\\Bean\\ObjectDefinition:private] = [propertyInjections:Swoft\\Bean\\ObjectDefinition:private] = Array ( ) [methodInjections:Swoft\\Bean\\ObjectDefinition:private] = Array ( ) ))
addScanNamespace
1 commandMapping收集的命令
Array( [0] = Swoft\\Http\\Server\\Command\\ServerCommand [1] = start [2] = 是否协程 [3] = 1)
默认如下: [1] = Swoft\\Db\\Command\\EntityCommand [2] = Swoft\\Devtool\\Command\\AppCommand [3] = Swoft\\Devtool\\Command\\DevCommand [4] = Swoft\\Devtool\\Command\\GenCommand [5] = Swoft\\Http\\Server\\Command\\ServerCommand [6] = Swoft\\Rpc\\Server\\Command\\RpcCommand [7] = Swoft\\WebSocket\\Server\\Command\\WsCommand
registerRoute
$classNames结构如下:Array( [0] = App\\Commands\\TestCommand [1] = App\\Boot\\MyProcess [2] = Swoft\\Cache\\Bootstrap\\CoreBean [3] = Swoft\\Console\\Bean\\Annotation\\Command [4] = Swoft\\Console\\Bean\\Annotation\\Mapping [5] = Swoft\\Console\\Bean\\Collector\\CommandCollector [6] = Swoft\\Console\\Bean\\Parser\\CommandParser [7] = Swoft\\Console\\Bean\\Parser\\MappingParser [8] = Swoft\\Console\\Bean\\Wrapper\\CommandWrapper [9] = Swoft\\Console\\Command [10] = Swoft\\Console\\Console [11] = Swoft\\Console\\ConsoleInterface [12] = Swoft\\Console\\CoreBean [13] = Swoft\\Console\\Exception\\ConsoleException [14] = Swoft\\Console\\Helper\\CommandHelper [15] = Swoft\\Console\\Helper\\ConsoleUtil [16] = Swoft\\Console\\Helper\\DocBlockHelper [17] = Swoft\\Console\\Helper\\Functions
1 加载配置文件
registerNamespace
是否自动initBeans
$this-registerMapping();
// 版本命令解析 if (input()-hasOpt('v') || input()-hasOpt('version')) { $this-showVersion(); return; } // 显示命令列表 $this-showCommandList();
Array( [worker] = Array ( [0] = Swoft\\Cache\\Bootstrap\\CoreBean [1] = Swoft\\Devtool\\Bootstrap\\CoreBean [2] = Swoft\\Bootstrap\\CoreBean [3] = Swoft\\Http\\Server\\Bootstrap\\CoreBean [4] = Swoft\\Redis\\Bootstrap\\CoreBean [5] = Swoft\\Rpc\\Bootstrap\\CoreBean [6] = Swoft\\Rpc\\Server\\Bootstrap\\CoreBean [7] = Swoft\\Sg\\Bootstrap\\CoreBean [8] = Swoft\\Session\\Bootstrap\\CoreBean [9] = Swoft\\View\\Bootstrap\\CoreBean [10] = Swoft\\WebSocket\\Server\\Bootstrap\\CoreBean ) [server] = Array ( [0] = Swoft\\Console\\CoreBean ))
bootstrap()
swoft 启动
$handler 例子
单个类结构
$this-definitions[$beanName]结果如下:
是否协程
返回
1. 读取@properties目录的所有配置文件
create
autoloadServerAnnotation
运行默认命令$this-baseCommand();
1. 自动加载2. 配置文件3. BeanFactory 工厂 init()4. get Bootstrap bean 并运行
Array( [Swoft\\Bootstrap\\Boots\\LoadEnv] = Array ( [name] = [order] = 1 ) [Swoft\\Bootstrap\\Boots\\InitPhpEnv] = Array ( [name] = [order] = 2 ) [Swoft\\Bootstrap\\Boots\\LoadInitConfiguration] = Array ( [name] = [order] = 3 )
_construct()
收藏
0 条评论
下一页