vd/app/Domains/Virtual/Http/Controllers/ArtisanController.php
2019-01-17 11:32:21 +08:00

48 lines
1.0 KiB
PHP

<?php
namespace App\Domains\Virtual\Http\Controllers;
use App\Core\Controller;
use Illuminate\Http\Request;
use App\Exceptions\NotAllowedException;
use Illuminate\Support\Facades\Artisan;
use Dipper\Foundation\Exceptions\HttpException;
class ArtisanController extends Controller
{
protected $request;
/**
* 构造函数,自动注入.
*/
public function __construct(Request $request)
{
$this->request = $request;
}
/**
* 列表.
*
* @return \Illuminate\Http\Response
*/
public function call()
{
$command = $this->request->get('command');
$commands = array_keys(Artisan::all());
if (!in_array($command, $commands)) {
throw new NotAllowedException('非法的命令');
}
$parameters = $this->request->get('parameters', []);
try{
Artisan::call($command, $parameters);
}catch(\Exception $e){
throw new HttpException($e->getMessage());
}
return res(true, '执行成功');
}
}