03.12.2015 Views

laravel4cookbook

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Deployment 75<br />

70 InputOption::VALUE_OPTIONAL,<br />

71 'An example option.',<br />

72 null<br />

73 ),<br />

74 );<br />

75 }<br />

76<br />

77 }<br />

.<br />

This file should be saved as app/commands/FooCommand.php.<br />

There are a few things of importance here:<br />

1. The $name property is used both to describe the command as well as invoke it. If we change<br />

it to foo, and register it correctly (as we’ll do in a moment), then we would be able to call it<br />

with: php artisan foo<br />

2. The description property is only descriptive. When all the registered command are displayed<br />

(by a call to: php artisan) then this description will be shown next to the name of the<br />

command.<br />

3. The fire() method is where all the action happens. If you want your command to do anything;<br />

there is where it needs to get done.<br />

4. The getArguments() method should return an array of arguments (or parameters) to the<br />

command. If our command was: php artisan foo bar, then bar would be an argument.<br />

Arguments are named (which we will see shortly).<br />

5. The getOptions() method should return an array of options (or flags) to the command. If out<br />

command was: php artisan foo –baz, then –baz would be an option. Options are also named<br />

(which we will also see shortly). This file gives us a good starting point from which to build<br />

our own set of commands.<br />

We begin our commands by creating the EnvironmentCommand class:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!