2014-04-04 5 views
1

php artisan에서 커스텀 커맨드가 필요합니다.PHP Artisan Custom Command

장인 셸을 통해 명령 파일을 만들었습니다.

하지만 php artisan을 통해 실행하면 정의되지 않은 상태가됩니다.

내 명령에 인수를 추가하는 방법도 혼란 스럽습니다. 여기

내 전체 명령 파일입니다 : 당신은에 명령을 추가 할 필요가

<?php 

use Illuminate\Console\Command; 
use Symfony\Component\Console\Input\InputOption; 
use Symfony\Component\Console\Input\InputArgument; 

class createLibrarySet extends Command 
{ 

/** 
* The console command name. 
* 
* @var string 
*/ 
protected $name = 'createLibrarySet'; 

/** 
* The console command description. 
* 
* @var string 
*/ 
protected $description = 'Creates a Library Set.'; 

/** 
* Create a new command instance. 
* 
* @return void 
*/ 
public function __construct() 
{ 
    parent::__construct(); 
} 

/** 
* Execute the console command. 
* 
* @return mixed 
*/ 
public function fire() 
{ 
    $dir = mkdir(app_path()."/".library."/".$this->library_name); 
    $coreName = $this->library_name; 
    $serivceProvider = $coreName."."."ServiceProvider.php"; 
    $library = $coreName."."."Library.php"; 
    $facade = $coreName."."."Facade.php"; 
    $interface = $coreName."."."Interface.php"; 
    fopen($dir."/".$library, "w"); 
    fopen($dir."/".$facade, "w"); 
    fopen($dir."/".$serivceProvider, "w"); 
    fopen($dir."/".$interface, "w"); 
} 

/** 
* Get the console command arguments. 
* 
* @return array 
*/ 
protected function getArguments() 
{ 
    return array(
     array('example', InputArgument::REQUIRED, 'An example argument.'), 
    ); 
} 

/** 
* Get the console command options. 
* 
* @return array 
*/ 
protected function getOptions() 
{ 
    return array(
     array('example', null, InputOption::VALUE_OPTIONAL, 'An example option.', null), 
    ); 
} 

} 
+0

이 왜 파일 핸들을 캡처하는 데 실패 후 모든하면 fopen() 호출을하고있다 :

당신의 인수를 얻으려면, 당신은 단지에 있나요? 이러한 파일에 실제로 쓰려면 파일 핸들이 필요하며 모든 파일을 잃어 버릴 수 있습니다. –

+0

해당 섹션이 불완전하지 않고 내 관심사가 아닙니다. 이제 숙련공 인터페이스와 관련이 있습니다. –

답변

3

당신의 app/start/artisan.php : 이제

Artisan::resolve('createLibrarySet'); 

당신이

php artisan 
에서 볼 수 있어야합니다

목록

$email = $this->argument('email'); 

그리고 옵션

$force = $this->option('force'); 
+0

쉘에서 전달 된 인수를 얻는 방법을 묻습니다. 현재 나는 "예"라는 단 하나의 논쟁만을 가지고 있지만 그 값을 얻는 방법을 모른다. –

+0

그냥 내 대답에 추가하기 위해 편집했다. –

관련 문제