Created
July 26, 2015 08:59
-
-
Save icedfish/d337740fbf728ed6dd6a to your computer and use it in GitHub Desktop.
Laravel artisan command to run php script.
This file contains 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 fire() | |
{ | |
$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.'), | |
); | |
} | |
} |
Thanks for your share!
Laravel 5.7 is running incorrectly, I modified it, working now!
How to use?
//php artisan run [file path]
php artisan run ./app/Utils/Tools.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.'),
);
}
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
simple run script like
shell php artisan run xxx.php