Skip to content

Commit

Permalink
laravel 4 docs first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Jan 10, 2013
0 parents commit 85780e6
Show file tree
Hide file tree
Showing 31 changed files with 3,636 additions and 0 deletions.
36 changes: 36 additions & 0 deletions artisan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Artisan CLI

- [Introduction](#introduction)
- [Usage](#usage)

<a name="introduction"></a>
## Introduction

Artisan is the name of the command-line interface included with Laravel. It provides a number of helpful commands for your use while developing your application. It is driven by the powerful Symfony Console component.

<a name="usage"></a>
## Usage

To view a list of all available Artisan commands, you may use the `list` command:

**Listing All Available Commands**

php artisan list

Every command also includes a "help" screen which displays and describes the command's available argumnets and options. To view a help screen, simply preceed the name of the command with `help`:

**Viewing The Help Screen For A Command**

php artisan help migrate

You may specify the configuration environment that should be used while running a command using the `--env` switch:

**Specifying The Configuration Environment**

php artisan migrate --env=local

You may also view the current version of your Laravel installation using the `--version` option:

**Displaying Your Current Laravel Version**

php artisan --version
65 changes: 65 additions & 0 deletions cache.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Cache

- [Configuration](#configuration)
- [Cache Usage](#cache-usage)
- [Database Cache](#database-cache)

<a name="configuration"></a>
## Configuration

Laravel provides a unified API for various caching systems. The cache configuration is located at `app/config/cache.php`. In this file you may specify which cache driver you would like used by default throughout your application. Laravel supports popular caching backends like [Memcached](http://memcached.org) and [Redis](http://redis.io) out of the box.

The cache configuration file also contains various other options, which are documented within the file, so make sure to read over these options. By default, Laravel is configured to use the `file` cache driver, which stores the serialized, cached objects in the filesystem. For larger applications, it is recommended that you use an in-memory cache such as Memcached or APC.

<a name="cache-usage"></a>
## Cache Usage

**Storing An Item In The Cache**

Cache::put('key', 'value', $minutes);

**Retrieving An Item From The Cache**

$value = Cache::get('key');

**Retrieving An Item Or Returning A Default Value**

$value = Cache::get('key', 'default');

$value = Cache::get('key', function() { return 'default'; });

**Storing An Item In The Cache Permanently**

Cache::forever('key', 'value');

Sometimes you may wish to retrieve an item from the cache, but also store a default value if the requested item doens't exist. You may do this using the `Cache::remember` method:

$value = Cache::remember('users', $minutes, function()
{
return DB::table('users')->get();
});

You may also combine the `remember` and `forever` methods:

$value = Cache::rememberForever('users', $minutes, function()
{
return DB::table('users')->get();
});

Note that all items stored in the cache are serialized, so you are free to store any type of data.

**Removing An Item From The Cache**

Cache::forget('key');

<a name="database-cache"></a>
## Database Cache

When using the `database` cache driver, you will need to setup a table to contain the cache items. Below is an example `Schema` declaration for the table:

Schema::create('cache', function($t)
{
$t->string('key')->unique();
$t->text('value');
$t->integer('expiration');
});
131 changes: 131 additions & 0 deletions commands.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
# Artisan Development

- [Introduction](#introduction)
- [Building A Command](#building-a-command)
- [Registering Commands](#registering-commands)
- [Calling Other Commands](#calling-other-commands)

<a name="introduction"></a>
## Introduction

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.

<a name="building-a-command"></a>
## Building A Command

### Generating The Class

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

By default, generated commands will be stored in the `app/commands` directory; however, you may specify custom path or namespace:

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

### Writing The Command

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.

The `fire` method will be called when your command is executed. You may place any command logic in this method.

### Arguments & Options

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.

When defining `arguments`, the array definition values represent the following:

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

The argument `mode` may be any of the following: `InputArgument::REQUIRED` or `InputArgumnet::OPTIONAL`.

When defining `options`, the array definition values represent the following:

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

For options, the argument `mode` may be: `InputOption::VALUE_REQUIRED`, `InputOption::VALUE_OPTIONAL`, `InputOption::VALUE_IS_ARRAY`, `InputOption::VALUE_NONE`.

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

The `VALUE_NONE` option indicates that the option is simply used as a "switch":

php artisan foo --option

### Retrieving Input

While you commnad 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

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 Conosle**

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

**Sending An Error Message To The Console**

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

### Asking Questions

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 Confirmation**

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

You may also specify a default value to the `confirm` method, which should be `true` or `false`:

$this->confirm($question, true)

<a name="registering-commands"></a>
## Registering Commands

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:

**Registering An Artisan Command**

Artisan::add(new CustomCommand);

If your command is registered in the application [IoC container](/docs/ioc), you may use the `Artisan::resolve` method to make it available to Artisan:

**Registering A Command That Is In The IoC Container**

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

<a name="calling-other-commands"></a>
## Calling Other Commands

Sometimes you may wish to call other commands from your command. You may do so using the `call` method:

**Calling Another Command**

$this->call('command.name', array('argument' => 'foo', '--option' => 'bar'))
40 changes: 40 additions & 0 deletions configuration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Configuration

- [Introduction](#introduction)
- [Environment Configuration](#environment-configuration)

<a name="introduction"></a>
## Introduction

All of the configuration files for the Laravel framework are stored in the `app/config` directory. Each option in every file is documented, so feel free to look through the files and get familiar with the options available to you.

Sometimes you may need to access configuration values at run-time. You may do so using the `Config` class:

**Accessing A Configuration Value**

Config::get('app.timezone');

Notice that "dot" style syntax may be used to access values in the various files. You may also set configuration values at run-time:

**Setting A Configuration Value**

Config::set('database.default', 'sqlite');

<a name="environment-configuration"></a>
## Environment Configuration

It is often helpful to have different configuration values based on the environment the application is running in. For example, you may wish to use a different cache driver on your local development machine than on the production server. It is easy to accomplish this using environment based configuration.

Simply create a folder within the `config` directory that matches your environment name, such as `local`. Next, create the configuration files you wish to override and specify the options for that environment. For example, to override the cache driver for the local environment, you would create a `cache.php` file in `app/config/local` with the following content:

<?php

return array(

'driver' => 'file',

);

Notice that you do not have to specify _every_ option that is in the base configuration file, but only the options you wish to override. The environment configuration files will "cascade" over the base files.

Next, we need to instruct the framework how to determine which environment it is running in. The default environment is always `production`. However, you may setup other environments within the `start.php` file at the root of your installation. In this file you will find an `$app->detectEnvironment` call. The array passed to this method is used to determine the current environment. You may add other environments and machine names to the array as needed.
32 changes: 32 additions & 0 deletions contributing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Contributing To Laravel

- [Introduction](#introduction)
- [Pull Requests](#pull-requests)
- [Coding Guidelines](#coding-guidelines)

<a name="introduction"></a>
## Introduction

Laravel is free, open-source software, meaning anyone can contribute to its development and progress. Laravel source code is currently hosted on [Github](http://github.com), which provides an easy method for forking the project and merging your contributions.

<a name="pull-requests"></a>
## Pull Requests

The pull request process differs for new features and bugs. Before sending a pull request for a new feature, you should first create an issue with `[Proposal]` in the title. The proposal should describe the new feature, as well as implementation ideas. The proposal will then be reviewed and either approved or denied. Once a proposal is approved, a pull request may be created implementing the new feature. Pull requests which do not follow this guideline will be closed immediately.

Pull requests for bugs may be sent without creating any proposal issue. If you believe that you know of a solution for a bug that has been filed on Github, please leave a comment detailing your proposed fix.

### Feature Requests

If you have an idea for a new feature you would like to see added to Laravel, you may create an issue on Github with `[Request]` in the title. The feature request will then be reviewed by a core contributor.

<a name="coding-guidelins"></a>
## Coding Guidelines

Laravel follows the [PSR-0](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md) and [PSR-1](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-1-basic-coding-standard.md) coding standards. In addition to these standards, below is a list of other coding standards that should be followed:

- Namespace declarations should be on the same line as `<?php`.
- Class opening `{` should be on the same line as the class name.
- Function and control structure opening `{` should be on a separate line.
- Always use `and` and `or`. Never use `&&` or `||`.
- Interface names are suffixed with `Interface` (`FooInterface`)
Loading

0 comments on commit 85780e6

Please sign in to comment.