追踪Laravel Artisan Command中的错误

时间:2018-03-13 20:49:23

标签: php laravel

我试图将一些http端点转换为控制台端点,并且无法跟踪错误。给定命令(简化):

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\Console\Controllers\TaskController;

class DummyCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'dummy';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        TaskController::make()->perform(...);        

    }
}

如果我在handle()中输入错误$z["break me"];,则控制台输出

  

在DummyCommand.php第42行:未定义   变量:z

正如预期的那样。另外,如果我把它放在TaskController :: make()中,它指向正确的文件。

<?php

namespace App\Console\Controllers;

class TaskController
{

    public static function make() {
        return new TaskController();
    }

    public function perform($tasks) {
        return $tasks->map(function($task) use($tasks) {
            return $this->feedback($task, $tasks);
        });
    }

    private function feedback($task, $tasks) {
        try {
            $taskClassName = '\\App\\Stimpack\\Tasks\\' . $task->name;
            $task = new $taskClassName( $tasks);
            $feedback = $task->perform();
        } catch (\Exception $e) {
            abort(500, $e->getMessage());
        }
        return $feedback;
    }     
}

但是,您可以看到TaskController动态地解析类名,因此在其他文件中继续执行。如果这些文件中有错误,我会收到一条参考Application.php的错误消息:

  

在Application.php第940行中:未定义   变量:z

为什么会这样?

我有办法从错误消息中获取更具体的位置吗?

0 个答案:

没有答案
相关问题