haihv433/sagoboot
Composer 安装命令:
composer require haihv433/sagoboot
包简介
SagoBoot | The mini-framework for scalable PHP application
README 文档
README
SagoBoot | The mini-framework for scalable PHP application
There is no principle when using this package or any, just blump your mind
The key archive
SagoBoot, which designed small enough to inject in any complex and not highly architect such as WordPress, Drupal ... using for theming and plugins.
SagoBoot, which designed to scale up more efficiently, by using Composer packages and PSR-4: Autoloader,
out of the box, you can use it beside Symfony or Zend for the first routing or destructor ...
SagoBoot, which designed for ease to use, quicky start, flexible and compatible for any idea and projects.
Installation
Install from Composer
composer require haihv433/sagoboot
Or just clone repo from github
git clone git@github.com:haihv433/sagoboot.git
Application and Loader
The first important thing when creating your own application is the App class manager, which holds all the instances
See class SagoBoot\Sample\App\App for a sample
Your Application Manager needs to extend from \SagoBoot\Application
In your bootstrap.php
you can control when your application booting, such as add Autoloader
// Initlize your application
$app = new \SagoBoot\Sample\App\App();
// Set your new class as App manager
// that then, your system will cheat \SagoBoot\Sample\App as a Manager instead of \SagoBoot\Application
$app->bind('SagoBoot\Sample\App', 'App', 1);
// SagoBoot do call your Loader when system boot
// Before that, you can add the logic more
$app->addEvent('boot', function ( \SagoBoot\Sample\App\Loader $loader) use ($app) {
$app->make('Autoload')->addLoader($loader);
});
Look at your own sample loader \SagoBoot\Sample\App\Loader
// This method will call automatically when system boot
public function autoload(Modules\Loader $loader)
{
$loader->loadPath(__DIR__ . '/../autoload.php');
}
As you see, Loader using a file named autoload.php, take a look of this those lines:
[
'abstract' => \SagoBoot\Sample\Car\Car::class,
'make' => false,
'singleton' => true,
'aliases' => [
\SagoBoot\Sample\Car\CarInterface::class
]
]
The file contains an array, each element has configuration:
abstract: Define your class
make: Set true if your want system constructs them automatically, or otherwise.
singleton: Set instances as Singleton that allow accessing as the same
aliases: You can hide your real logic when using aliases pattern, check class
\SagoBoot\Sample\Car\CarInterface
for a sample.
Finally, don't forget to boot your system.
$app = require_once(__DIR__ . "/sample/bootstrap.php");
// Now booting
$app->boot();
Dependency Injection
Now, if you'd finished declaring your Application, no more effort to construct your class, just inject any class you needed
The MakeCar sample class
namespace SagoBoot\Sample;
class MakeCar
{
public function __construct(
\SagoBoot\Sample\Garage $garage,
\SagoBoot\Sample\Car\CarInterface $car
)
{
}
}
the Garage sample class
namespace SagoBoot\Sample;
class Garage
{
/**
* @var \SagoBoot\Sample\Car\CarInterface
*/
protected $car;
public function __construct(
\SagoBoot\Sample\Car\CarInterface $car
)
{
$this->car = $car;
}
}
As you see above, no need to add the new keyword when create class, which is already set in autoload.php
The Application also check the aliases for a reflection from real class to alias
In this case, calling interface \SagoBoot\Sample\Car\CarInterface will return an instance of \SagoBoot\Sample\Car\Car
Singleton
If you set your class as singleton in autoload.php or implements from \SagoBoot\Support\Singleton, your Application will
treat what one as Singleton object, that mean, calling or injection will return the same object.
See this in MakeCar.php::__construct()
$car->start()
->observerState()
->addFuel()
->observerState()
->stop();
$garage->maintenanceCar();
$car->observerState();
By running command php index.sample.php
Output:
Your car is: RUNNING.
Your car is: REFUEL.
Your car is: RUNNING.
Your car is: MAINTENANCE.
The car was destroyed.
For calling the instance of Car class, these methods could useful:
- Inject the interface
\SagoBoot\Sample\Car\CarInterfacein constructor - Calling
\SagoBoot\Sample\App\App::getInstance()->make(\SagoBoot\Sample\Car\CarInterface::class) sgb_app(\SagoBoot\Sample\Car\CarInterface::class)(check API)
Event
If you are noted, your application only boots when call $app->boot(),
look more closely in this method:
$this->make('EventsHelper')->fire('boot');
The event boot is a system designed for booting, for that, you can add your custom logic after or before system boot,
see this:
$app->addEvent('your_custome_event', function() {
// Your logical
});
$app->addEvent('boot', function() {
$this->make('EventsHelper')->fire('your_custome_event');
})
API Functional
For more convenient when interact with your application, please check helpers.php
for more options:
- Create or retrieve an instance
sgb_app() - Call a
Helperobjectsgb_helper(), (any class has name ending byHelperkeyword) - Event
sgb_event()andsgb_add_event() - Filter
sgb_filterandsgb_add_filter()
Practical
Do you love design pattern and how to implement them all, those articles might useful
There is no principle when implement SagoBoot with any pattern, Factory, Proxy, Repo ... whatever, you already have a skeleton, just do it !!!
haihv433/sagoboot 适用场景与选型建议
haihv433/sagoboot 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 42 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 03 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「framework」 「php」 「mini-framework」 「sagoboot」 「mini-php」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 haihv433/sagoboot 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 haihv433/sagoboot 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 haihv433/sagoboot 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP Framework HLEB2 is the foundation of the web application. Provides ease of development and application performance.
A simple, lightweight and high-performance PHP coroutine framework.
Alfabank REST API integration
O2System Restful Project Boilerplate.
High-performance, opinionated PHP 8 web framework with O(1) routing, parallel async MySQL, type-safe asset bridge, and React-island frontend
The PHP Mini Framework.
统计信息
- 总下载量: 42
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2020-03-01