jeyroik/extas-api

此包的最新版本(3.0.0)没有提供许可证信息。

API 包

3.0.0 2022-11-24 14:44 UTC

This package is auto-updated.

Last update: 2024-09-24 18:48:39 UTC


README

tests codecov.io PHPStan Enabled Extas Installer v3 Latest Stable Version Total Downloads Dependents

描述

extas 的 API。

使用

  • php -S 0.0.0.0:8080 -t vendor/jeyroik/extas-api/public.
  • 您可以通过阶段 extas.api.app.init 使用插件添加自己的路由(有关详细信息,请参阅 src/interfaces/extensions/IStageApiAppInit)。

插件示例

use extas\components\plugins\Plugin;
use extas\interfaces\stages\IStageApiAppInit;
use Slim\App;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;

class PluginOwnRoute extends Plugin implements IStageApiAppInit
{
    /**
     * @param App $app
     */
    public function __invoke(App &$app): void
    {
        $app->post(// post/get/delete/put/patch/any/
            '/my/route',
            function (RequestInterface $request, ResponseInterface $response, array $args) {
                // dispatching 
            }
        );
    }
}

使用路由

//extas.app.storage.json

{
    "plugins": [
        {
            "class": "\\extas\\components\\plugins\\PluginRoutes",
            "stage": "extas.api.app.init"
        }
    ]
}

//extas.app.json

{
    "routes": [
        {
            "name": "/json/v1/my-items",
            "title": "Items list",
            "description": "My items list",
            "method": "get",
            "class": "\\some\\routes\\ClassName"
        }
    ]
}

// ClassName.php - 路由分发器类

<?php
namespace some\routes;

use extas\components\routes\dispatchers\JsonDispatcher;

class ClassName extends JsonDispatcher
{
    use TRouteList;

    protected string $repoName = 'my_items';

    public function help(): ResponseInterface
    {
        //...
    }
}

// my\interfaces\IMyItem

<?php
namespace my\interfaces;

class IMyItem
{
    //...
}

从这里开始,您可以访问

  • GET /json/v1/my-items : 您应该看到 my_items 项的列表。