teraone/slim-cli

此包已被废弃,不再维护。未建议替代包。

通过 CLI 进行模拟 GET 请求并在 CLI 脚本中启用相同的应用程序入口点。

2.0.0 2017-05-05 14:08 UTC

This package is not auto-updated.

Last update: 2020-01-24 16:40:23 UTC


README

Build Status

Slim 3 框架 CLI 请求中间件

此中间件将 CLI 调用转换为 GET 请求。它基于 https://github.com/pavlakis/slim-cli,但不使用方法参数。

使用 composer 添加

composer require teraone/slim-cli

按照此顺序传递参数

路由 / 查询字符串

php public/index.php /status event=true

将此添加到应用程序的中间件部分

$app->add(new \Teraone\SlimCli\CliRequest());

传递一个路由来测试它


$app->get('/status', 'YourNameSpace\YourController:yourMethod')
    ->setName('status');

检查您是否仅使用 CLI 调用

final class YourController
{
    ...

    public function yourMethod(Request $request, Response $response, $args)
    {

        // ONLY WHEN CALLED THROUGH CLI
        if (PHP_SAPI !== 'cli') {
            return $response->withStatus(404)->withHeader('Location', '/404');
        }

        if (!$request->getParam('event')) {
            return $response->withStatus(404)->withHeader('Location', '/404');
        }

        ...

    }

}

鸣谢

基于 Bobby DeVeaux (@bobbyjason) 的 Gulp 骨架