Readouble

Laravel 4.2 Artisan開発

イントロダクションIntroduction

アプリケーションで動作する追加のカスタムコマンドを構築することも可能です。app/commandsディレクトリーにカスタムコマンドを保存してください。しかし、コマンドがオートロードされるようにcomposer.jsonを設定する限り、どこにでも好きな場所に置くことができます。In addition to the commands provided with Artisan, you may also build your own custom commands for working with your application. You may store your custom commands in the app/commands directory; however, you are free to choose your own storage location as long as your commands can be autoloaded based on your composer.json settings.

コマンドの構築Building A Command

クラスを生成するGenerating The Class

新しいコマンドを生成するには、Artisanコマンドのcommand:makeを使用し、開発開始の手助けとなるコマンドスタブを生成してください。To create a new command, you may use the command:make Artisan command, which will generate a command stub to help you get started:

新しいコマンドクラスを生成するGenerate A New Command Class

php artisan command:make FooCommand

デフォルトでは、生成されたコマンドはapp/commandsディレクトリーに保存されます。しかし、独自のパスか名前空間を指定することもできます。By default, generated commands will be stored in the app/commands directory; however, you may specify custom path or namespace:

php artisan command:make FooCommand --path=app/classes --namespace=Classes

--commandオプションを付け、コマンドを生成すると、コマンド名を指定することができます。When creating the command, the --command option may be used to assign the terminal command name:

php artisan command:make AssignUsers --command=users:assign

コマンドを書くWriting The Command

コマンドを生成したら、クラスのnamedescriptionプロパティーを埋めてください。listスクリーンであなたのコマンドを表示する時に使用されます。Once your command is generated, you should fill out the name and description properties of the class, which will be used when displaying your command on the list screen.

fireメソッドはコマンドが実行される時に呼び出されます。このメソッドの中に、コマンドロジックを書いてください。The fire method will be called when your command is executed. You may place any command logic in this method.

引数とオプションArguments & Options

getArgumentsgetOptionsメソッドでコマンドが受け取る引数とオプションを定義します。両者のメソッドはオプションを配列のリストで記述した、コマンドの配列をリターンします。The getArguments and getOptions methods are where you may define any arguments or options your command receives. Both of these methods return an array of commands, which are described by a list of array options.

argumentsを定義する定義配列は以下のような形式です。When defining arguments, the array definition values represent the following:

array($name, $mode, $description, $defaultValue)

引数modeInputArgument::REQUIREDInputArgument::OPTIONALのどちらかです。The argument mode may be any of the following: InputArgument::REQUIRED or InputArgument::OPTIONAL.

optionsを定義する定義配列は以下のような形式です。When defining options, the array definition values represent the following:

array($name, $shortcut, $mode, $description, $defaultValue)

オプションでは、引数modeInputOption:REQUIREDInputOption::OPTIONALInputOption::VALUE_IS_ARRAYInputOption::VALUE_NONEのどちらかです。For options, the argument mode may be: InputOption::VALUE_REQUIRED, InputOption::VALUE_OPTIONAL, InputOption::VALUE_IS_ARRAY, InputOption::VALUE_NONE.

VALUE_IS_ARRAYモードはコマンド実行時に複数回指定されるスイッチを表します。The VALUE_IS_ARRAY mode indicates that the switch may be used multiple times when calling the command:

php artisan foo --option=bar --option=baz

VALUE_NONEオプションは「スイッチ」として指定されるオプションを表します。The VALUE_NONE option indicates that the option is simply used as a "switch":

php artisan foo --option

入力の取り込みRetrieving Input

コマンド実行時、アプリケーションが受け取った引数やオプションの値にアクセスする必要があるのは明らかです。これを行うには、argumentoptionメソッドを使用します。While your command is executing, you will obviously need to access the values for the arguments and options accepted by your application. To do so, you may use the argument and option methods:

コマンド引数の値を取得するRetrieving The Value Of A Command Argument

$value = $this->argument('name');

全ての引数を取得するRetrieving All Arguments

$arguments = $this->argument();

コマンドオプションの値を習得するRetrieving The Value Of A Command Option

$value = $this->option('name');

全てのオプションを取得するRetrieving All Options

$options = $this->option();

出力Writing Output

コンソールに出力するには、infocommentquestionerrorメソッドを使います。その名前が表す目的で使用し、それぞれ適当なANSIカラーが表示に使われます。To send output to the console, you may use the info, comment, question and error methods. Each of these methods will use the appropriate ANSI colors for their purpose.

お知らせをコンソールに送るSending Information To The Console

$this->info('Display this on the screen');

エラーメッセージをコンソールに送るSending An Error Message To The Console

$this->error('Something went wrong!');

質問Asking Questions

入力を求めるためにaskconfirmメソッドも使用できます。You may also use the ask and confirm methods to prompt the user for input:

ユーザーに入力を求めるAsking The User For Input

$name = $this->ask('What is your name?');

ユーザーに秘密の文字列の入力を求めるAsking The User For Secret Input

$password = $this->secret('What is the password?');

ユーザーに確認を求めるAsking The User For Confirmation

if ($this->confirm('Do you wish to continue? [yes|no]'))
{
	//
}

また、confirmメソッドにはtruefalseのデフォルト値が指定できます。You may also specify a default value to the confirm method, which should be true or false:

$this->confirm($question, true);

コマンドの登録Registering Commands

Artisanコマンドを登録するRegistering An Artisan Command

作成し終えたコマンドを使用するためにArtisanに登録する必要があります。通常、app/start/artisan.phpファイルで行います。このファイルの中で、Artisan::addメソッドをコマンドの登録に使用してください。Once your command is finished, you need to register it with Artisan so it will be available for use. This is typically done in the app/start/artisan.php file. Within this file, you may use the Artisan::add method to register the command:

Artisan::add(new CustomCommand);

IoCコンテナの中のコマンドを登録するRegistering A Command That Is In The IoC Container

コマンドをアプリケーションのIoCコンテナに登録している場合、Artisanで使用可能にするにはArtisan::resolveメソッドを使います。If your command is registered in the application IoC container[/docs/4.2/ioc], you may use the Artisan::resolve method to make it available to Artisan:

Artisan::resolve('binding.name');

サービスプロバイダーによるコマンド登録Registering Commands In A Service Provider

サービスプロバーダー内でコマンドを登録する必要があるときは、プロバイダーのbootメソッドから、そのコマンドのIoCコンテナへの結合名を渡し、commandメソッドを呼び出してください。If you need to register commands from within a service provider, you should call the commands method from the provider's boot method, passing the IoC container[/docs/4.2/ioc] binding for the command:

public function boot()
{
	$this->commands('command.binding');
}

他のコマンドを呼び出すCalling Other Commands

場合により、コマンドの中から他のコマンドを呼び出したい場合もあります。callメソッドを使ってください。Sometimes you may wish to call other commands from your command. You may do so using the call method:

$this->call('command:name', array('argument' => 'foo', '--option' => 'bar'));

章選択

Artisan CLI

設定

明暗テーマ
light_mode
dark_mode
brightness_auto システム設定に合わせる
テーマ選択
photo_size_select_actual デフォルト
photo_size_select_actual モノクローム(白黒)
photo_size_select_actual Solarized風
photo_size_select_actual GitHub風(青ベース)
photo_size_select_actual Viva(黄緑ベース)
photo_size_select_actual Happy(紫ベース)
photo_size_select_actual Mint(緑ベース)
コードハイライトテーマ選択

明暗テーマごとに、コードハイライトのテーマを指定できます。

テーマ配色確認
スクリーン表示幅
640px
80%
90%
100%

768px以上の幅があるときのドキュメント部分表示幅です。

インデント
無し
1rem
2rem
3rem
原文確認
原文を全行表示
原文を一行ずつ表示
使用しない

※ 段落末のEボタンへカーソルオンで原文をPopupします。

Diff表示形式
色分けのみで区別
行頭の±で区別
削除線と追記で区別

※ [tl!…]形式の挿入削除行の表示形式です。

Pagination和文
ペジネーション
ペギネーション
ページネーション
ページ付け
Scaffold和文
スカフォールド
スキャフォールド
型枠生成
本文フォント

総称名以外はCSSと同様に、"〜"でエスケープしてください。

コードフォント

総称名以外はCSSと同様に、"〜"でエスケープしてください。

保存内容リセット

localStrageに保存してある設定項目をすべて削除し、デフォルト状態へ戻します。

ヘッダー項目移動

キーボード操作