diff --git a/.vitepress/config.mts b/.vitepress/config.mts index 3beb566..6bb88eb 100644 --- a/.vitepress/config.mts +++ b/.vitepress/config.mts @@ -20,7 +20,9 @@ export default defineConfig({ // 默认禁用图片懒加载 lazyLoading: true }, - + }, + sitemap: { + hostname: 'https://www.xiaokeaii.top' }, themeConfig: { outlineTitle: '页面导航', diff --git a/.vitepress/sidebar.ts b/.vitepress/sidebar.ts index d0403a0..e7a3dd3 100644 --- a/.vitepress/sidebar.ts +++ b/.vitepress/sidebar.ts @@ -9,8 +9,8 @@ export default [ items: [ { text: '阅读版本', link: hyperf + '阅读版本' }, { text: '入口文件', link: hyperf + '入口文件' }, - { text: '初始化依赖注入 (DI) 容器', link: hyperf + '初始化依赖注入 (DI) 容器' }, - { text: 'container', link: hyperf + 'container' }, + { text: '初始化依赖注入 (DI) 容器', link: hyperf + 'DI' }, + { text: '初始化容器类', link: hyperf + 'container' }, { text: '启动服务', link: hyperf + '启动服务' }, { text: '请求', link: hyperf + '请求' }, { text: '路由寻址', link: hyperf + '路由寻址' }, diff --git a/src/hyperf/初始化依赖注入 (DI) 容器.md b/src/hyperf/DI.md similarity index 99% rename from src/hyperf/初始化依赖注入 (DI) 容器.md rename to src/hyperf/DI.md index afdbf77..00984db 100644 --- a/src/hyperf/初始化依赖注入 (DI) 容器.md +++ b/src/hyperf/DI.md @@ -1,7 +1,8 @@ --- title: 初始化依赖注入 (DI) 容器 --- -## 初始化依赖注入 (DI) 容器 +# 初始化依赖注入 (DI) 容器 + ```php (function () { diff --git a/src/hyperf/container.md b/src/hyperf/container.md index 7291548..1625f9b 100644 --- a/src/hyperf/container.md +++ b/src/hyperf/container.md @@ -1,24 +1,34 @@ --- title: 初始化容器类 --- - -本节分析容器类, +# 初始化容器类 +本节分析容器类的实例化过程, ```php -$container = require BASE_PATH . '/config/container.php'; +(function () { + Hyperf\Di\ClassLoader::init(); + /** @var Psr\Container\ContainerInterface $container */ + $container = require BASE_PATH . '/config/container.php'; // [!code focus] + + $application = $container->get(Hyperf\Contract\ApplicationInterface::class); + $application->run(); +})(); ``` + 这是容器类初始化的代码, + ```php use Hyperf\Context\ApplicationContext; use Hyperf\Di\Container; use Hyperf\Di\Definition\DefinitionSourceFactory; -$container = new Container((new DefinitionSourceFactory())()); +$container = new Container((new DefinitionSourceFactory())()); // [!code warning] return ApplicationContext::setContainer($container); ``` -> 首先,可以看出,先是`new`了 一个`DefinitionSourceFactory`类,然后使用方法的调用方式调用类,会触发该类的`__invoke`方法,最后返回的内容作为`Container`类的构造函数的参数,然后返回容器类。 + +首先,可以看出,先是实例化了`DefinitionSourceFactory`类,然后使用方法的调用方式调用类,会触发该类的`__invoke`方法,最后返回的内容作为`Container`类的构造函数的参数,然后返回实例化后的容器类。 ### DefinitionSourceFactory类 先看该类做了那些工作,