tobento/service-booting
Composer 安装命令:
composer require tobento/service-booting
包简介
Booting manager for creating PHP applications.
README 文档
README
Booting for any PHP applications.
Table of Contents
Getting started
Add the latest version of the booting service project running this command.
composer require tobento/service-booting
Requirements
- PHP 8.4 or greater
Highlights
- Framework-agnostic, will work with any project
- Decoupled design
Documentation
Booter
Create Booter
use Tobento\Service\Booting\Booter; use Tobento\Service\Booting\BooterInterface; use Tobento\Service\Booting\AutowiringBootFactory; use Tobento\Service\Container\Container; // Any PSR-11 container $container = new Container(); $booter = new Booter( bootFactory: new AutowiringBootFactory($container), name: 'app', bootMethods: ['register', 'boot'], terminateMethods: ['terminate'], ); var_dump($booter instanceof BooterInterface); // bool(true)
Parameters explanation
| Parameter | Description |
|---|---|
| bootFactory | The boot factory. |
| name | The name of the booter. |
| bootMethods | The boot methods the booter calls if exists, in the order defined. |
| terminateMethods | The terminate methods the booter calls if exists, in the order defined. |
Register Boots
Each boot class is registered once. If you register the same class again it will just overwrite it.
$booter->register(new ConfigBoot()); // You may set a priority for the boot: $booter->register(DebugBoot::class, priority: 2000); $booter->register( HttpBoot::class, RoutingBoot::class, );
Booting
// calls the boot methods: $booter->boot(); // calls the terminate methods $booter->terminate();
You may call the booting methods as many times as you want. By default the boot methods gets called once, except declared otherwise with the constant REBOOTABLE in the boot classes. See Rebooting.
Example
$booter->register(ConfigBoot::class); $booter->register(DebugBoot::class, priority: 2000); $booter->register( HttpBoot::class, RoutingBoot::class, ); $booter->boot(); $booter->terminate(); /* boot: DebugBoot::class boot: ConfigBoot::class boot: HttpBoot::class boot: RoutingBoot::class terminate: RoutingBoot::class terminate: HttpBoot::class terminate: ConfigBoot::class terminate: DebugBoot::class */
Misc
get
Returns the specified boot registry if exist, otherwise NULL.
use Tobento\Service\Booting\BootRegistry; $boot = $booter->get(MyBoot::class); var_dump($boot instanceof BootRegistry); // bool(true)
getBoot
Returns the specified boot if exist, otherwise NULL.
use Tobento\Service\Booting\BootInterface; $boot = $booter->getBoot(MyBoot::class); var_dump($boot instanceof BootInterface); // bool(true)
getBoots
Returns the registered boots.
use Tobento\Service\Booting\BootRegistry; $boots = $booter->getBoots(); foreach($boots as $boot) { var_dump($boot instanceof BootRegistry); // bool(true) }
getBooted
For debugging purposes, you might want to get boots booted.
$booted = $booter->getBooted();
Boots
Create Boot
You can create a Boot by simply exenting Tobento\Service\Booting\Boot:
use Tobento\Service\Booting\Boot; class MyBoot extends Boot { // }
Currently, your Boot doesn't do anything. Depending on the booter boot and terminate methods defined, you can now define these methods in your Boot class which support method injection (autowiring).
use Tobento\Service\Booting\Boot; class MyBoot extends Boot { public function boot(): void { // Do something } public function terminate(): void { // Do something } }
Dependent Boot
If your Boot depends on another Boot you may ensure that the Boot has always been initiated before by using the constant BOOT.
use Tobento\Service\Booting\Boot; class MyBoot extends Boot { public const BOOT = [ AnotherBoot::class, ]; public function boot(AnotherBoot $boot): void { // Do something } }
Boot Priority
You may declare a boot priority by using the constant PRIORITY. The default priority is 1000.
use Tobento\Service\Booting\Boot; class MyBoot extends Boot { public const PRIORITY = 2000; }
Rebooting
By default, when the booter calls the Booting methods muliple times, the boot method gets call once only. You may define methods as rebootable by using the constant REBOOTABLE.
use Tobento\Service\Booting\Boot; class MyBoot extends Boot { public const REBOOTABLE = ['terminate']; }
Boot Info
You may add some info for your boot methods by using the constant INFO.
use Tobento\Service\Booting\Boot; class MyBoot extends Boot { public const INFO = [ 'boot' => 'Some description what the boot method does.', 'terminate' => 'Some description what the terminate method does.', ]; }
Credits
tobento/service-booting 适用场景与选型建议
tobento/service-booting 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 296 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 01 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「package」 「tobento」 「booting」 「booter」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 tobento/service-booting 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 tobento/service-booting 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 tobento/service-booting 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Simple ASCII output of array data
Package for view storage in laravel
User Approval Laravel Package
App profiler.
A task schedule system for running tasks at specific intervals.
统计信息
- 总下载量: 296
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 21
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-01-04