Created
February 22, 2019 07:19
-
-
Save fhefh2015/a123acaa2023a5a8c788c7fefd8cf923 to your computer and use it in GitHub Desktop.
用Laravel的artisan命令执行php脚本
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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