定制 haihv433/sagoboot 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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\CarInterface in 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 Helper object sgb_helper(), (any class has name ending by Helper keyword)
  • Event sgb_event() and sgb_add_event()
  • Filter sgb_filter and sgb_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 我们能提供哪些服务?
定制开发 / 二次开发

基于 haihv433/sagoboot 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 42
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2020-03-01