Yaf 命令行模式爬坑

前言

使用 yaf 框架做一个消息队列,执行命令的时候一直找不到对应的控制器,爬坑2小时,原来是Git Bash 的锅。

开发环境

windwos 10

PHP 7.3

Yaf 3.0.8

问题重现

/root_path/shell/index.php

<?php
if (empty($argv[1])) {
    exit('command error');
}

ini_set('display_errors', 'on');
error_reporting(E_ALL);

define('IS_CLI', true);
define('APP_PATH', realpath(__DIR__.'/../'));

date_default_timezone_set('Asia/Shanghai');
require_once APP_PATH.'/vendor/autoload.php';

$app = new Yaf_Application(APP_PATH.'/conf/application.ini', 'common');
$app->bootstrap()->getDispatcher()->dispatch(new Yaf_Request_Simple());

Git Bash中执行命令php index.php request_uri=/cli/Notify/login 输出如下

Failed opening controller script D:\wnmp\www\bitell\Middleman/app\controllers\:.php: No such file or directory

index.php 改成这样

<?php
$request = new Yaf_Request_Simple();
print_r($request);
die;

再执行命令 php index.php request_uri=/cli/Notify/login 输出如下

Yaf_Request_Simple Object
(
    [module] =>
    [controller] =>
    [action] =>
    [method] => CLI
    [params:protected] => Array
        (
        )

    [language:protected] =>
    [_exception:protected] =>
    [_base_uri:protected] =>
    [uri:protected] => :/Program Files/Git/cli/Notify/login
    [dispatched:protected] =>
    [routed:protected] =>
)

uri 寻找 Git Bash 的安装目录去了,所以找不到我的控制器了

Windows PowerShell中 执行命令 php index.php request_uri=/cli/Notify/login 输出如下

Yaf_Request_Simple Object
(
    [module] =>
    [controller] =>
    [action] =>
    [method] => CLI
    [params:protected] => Array
        (
        )

    [language:protected] =>
    [_exception:protected] =>
    [_base_uri:protected] =>
    [uri:protected] => cli/Notify/login
    [dispatched:protected] =>
    [routed:protected] =>
)

还原index.php 就可以正常使用了,爬出来了

本作品采用《CC 协议》,转载必须注明作者和本文链接
感谢阅读,有收获的话不妨点个赞:smiling_imp:
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!