cspray/labrador

通过插件、事件和引擎提供核心功能,以驱动 Labrador 狗舍应用程序

3.2.1 2021-06-17 10:21 UTC

README

PHP Unit Testing & Code Lint GitHub release GitHub license

这是一个基于 amphp 的有观点的异步微框架。它采用 SOLID 原则、单元测试和模块化生态系统构建,旨在成为创建异步 PHP 应用程序的现成框架。Labrador 核心是该框架的基础,并为使用 Labrador 构建应用程序提供重要关键概念。

安装

Composer 是安装 Labrador 包的唯一支持方法。

composer require cspray/labrador

快速入门

如果您想快速开始而不必阅读大量文档,下面的代码演示了如何快速实现并运行一个 Application。否则,我们建议您查看文档以获取更详细的信息和完整的入门指南。

<?php

// app.php in your project's root directory

require_once __DIR__ . '/vendor/autoload.php';

use Cspray\Labrador\AbstractApplication;
use Cspray\Labrador\EnvironmentType;
use Cspray\Labrador\CoreApplicationObjectGraph;
use Cspray\Labrador\Engine;
use Cspray\Labrador\StandardEnvironment;
use Amp\Promise;
use Amp\Delayed;
use Amp\Log\StreamHandler;
use Auryn\Injector;
use Monolog\Logger;
use function Amp\call;
use function Amp\ByteStream\getStdout;

class HelloWorldApplicationObjectGraph extends CoreApplicationObjectGraph {

    public function wireObjectGraph() : Injector {
        $injector = parent::wireObjectGraph();

        // wire up your app's dependencies

        return $injector;
    }

}

class HelloWorldApplication extends AbstractApplication {

    protected function doStart() : Promise {
        return call(function() {
            yield new Delayed(500);  // just to show that we are running on the Loop
            $this->logger->info('Hello Labrador!');
        }); 
    }

}

$environment = new StandardEnvironment(EnvironmentType::Development());
$logger = new Logger('labrador.hello-world', [new StreamHandler(getStdout())]);

$injector = (new HelloWorldApplicationObjectGraph($environment, $logger))->wireObjectGraph();

$app = $injector->make(HelloWorldApplication::class);
$engine = $injector->make(Engine::class);

$engine->run($app);

文档

Labrador 包在 docs/ 目录中有详细的文档。您还可以在网上查看 https://labrador-kennel.io/docs/core 的文档。

治理

所有 Labrador 包都遵守 Labrador Governance 仓库 中规定的规则。