Created
January 13, 2018 12:56
-
-
Save orange634nty/85921162d45fa51862befa4916553b99 to your computer and use it in GitHub Desktop.
laravelコマンド実行方法比較
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 \Artisan; | |
class CallCommand extends Command | |
{ | |
/** | |
* The name and signature of the console command. | |
* | |
* @var string | |
*/ | |
protected $signature = 'command:call'; | |
/** | |
* 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() | |
{ | |
// run called command | |
$this->info('***** run command using exec *****'); | |
$this->info('execResult: ' . exec('php artisan command:called --path=exec') . PHP_EOL); | |
$this->info('***** run command using call *****'); | |
$this->info('callResult: ' . $this->call('command:called', ['--path' => 'call']) . PHP_EOL); | |
$this->info('***** run command using artisan *****'); | |
$this->info('artisanResult: ' . Artisan::call('command:called', ['--path' => 'artisan']) . PHP_EOL); | |
} | |
} |
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; | |
class CalledCommand extends Command | |
{ | |
/** | |
* The name and signature of the console command. | |
* | |
* @var string | |
*/ | |
protected $signature = 'command:called {--path=default}'; | |
/** | |
* 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() | |
{ | |
$path = $this->option('path'); | |
echo 'run child command, path: ' . $path . PHP_EOL; | |
$this->info('run child command, path: ' . $path); | |
$this->error('throw error on child command, path: ' . $path); | |
} | |
} |
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 artisan command:call | |
***** run command using exec ***** | |
execResult: throw error on child command, path: exec | |
***** run command using call ***** | |
run child command, path: call | |
run child command, path: call | |
throw error on child command, path: call | |
callResult: 0 | |
***** run command using artisan ***** | |
run child command, path: artisan | |
artisanResult: 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment