Skip to content

Instantly share code, notes, and snippets.

@fhefh2015
Created February 22, 2019 07:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fhefh2015/a123acaa2023a5a8c788c7fefd8cf923 to your computer and use it in GitHub Desktop.
Save fhefh2015/a123acaa2023a5a8c788c7fefd8cf923 to your computer and use it in GitHub Desktop.
用Laravel的artisan命令执行php脚本
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputArgument;
class RunFile extends Command
{
/**
* The console command name.
*
* @var string
*/
protected $name = 'run';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Run php file with system env support.';
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$file = $this->argument('php_file');
if (is_file($file)) {
include $file;
} else {
$this->error("file '{$file}' not found!");
}
}
/**
* Get the console command arguments.
*
* @return array
*/
protected function getArguments()
{
return array(
array('php_file', InputArgument::REQUIRED, 'The php file to run with Laputa.'),
);
}
}
//Laravel 5.7
//使用:php artisan run [file path]
php artisan run ./app/Utils/Tools.php
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment