added documentation to main repository.
This commit is contained in:
30
documentation/other/benchmark.md
Normal file
30
documentation/other/benchmark.md
Normal file
@@ -0,0 +1,30 @@
|
||||
## Benchmarking Code
|
||||
|
||||
- [The Basics](#basics)
|
||||
- [Using Timers](#timers)
|
||||
- [Checking Memory Usage](#memory)
|
||||
|
||||
<a name="basics"></a>
|
||||
### The Basics
|
||||
|
||||
When making changes to your code, it's helpful to know the performance impact of your changes. Laravel provides a simple class to help you time code execution and check memory consumption. It's called the **Benchmark** class and it's a breeze to use.
|
||||
|
||||
<a name="timers"></a>
|
||||
### Using Timers
|
||||
|
||||
To start a timer, simply call the **start** method on the Benchmark class and give your timer a name:
|
||||
|
||||
Benchmark::start('foo');
|
||||
|
||||
Pretty easy, right?
|
||||
|
||||
You can easily check how much time has elapsed (in milliseconds) using the **check** method. Again, just mention the name of the timer to the method:
|
||||
|
||||
echo Benchmark::check('foo');
|
||||
|
||||
<a name="memory"></a>
|
||||
### Checking Memory Usage
|
||||
|
||||
Need to know how much memory is being used by your application? No problem. Just call the **memory** method to get your current memory usage in megabytes:
|
||||
|
||||
echo Benchmark::memory();
|
||||
36
documentation/other/crypt.md
Normal file
36
documentation/other/crypt.md
Normal file
@@ -0,0 +1,36 @@
|
||||
## Encryption
|
||||
|
||||
- [The Basics](#basics)
|
||||
- [Encrypting A String](#encrypt)
|
||||
- [Decrypting A String](#decrypt)
|
||||
|
||||
<a name="basics"></a>
|
||||
### The Basics
|
||||
|
||||
Need to do secure, two-way encryption? Laravel has you covered with the **Crypt** class. The Crypt class provides strong AES-256 encryption and decryption out of the box via the Mcrypt PHP extension.
|
||||
|
||||
To get started, you must set your **application key** in the **application/config/application.php** file. This key should be very random and very secret, as it will be used during the encryption and decryption process. It is best to use a random, 32 character alpha-numeric string:
|
||||
|
||||
'key' => 'xXSAVghP7myRo5xqJAnMvQwBc7j8qBZI';
|
||||
|
||||
Wonderful. You're ready to start encrypting.
|
||||
|
||||
> **Note:** Don't forget to install the Mcrypt PHP extension on your server.
|
||||
|
||||
<a name="encrypt"></a>
|
||||
### Encrypting A String
|
||||
|
||||
Encrypting a string is a breeze. Just pass it to the **encrypt** method on the Crypt class:
|
||||
|
||||
Crypt::encrypt($value);
|
||||
|
||||
Do you feel like James Bond yet?
|
||||
|
||||
<a name="decrypt"></a>
|
||||
### Decrypting A String
|
||||
|
||||
So you're ready to decrypt a string? It's simple. Just use the **decrypt** method on the Crypt class:
|
||||
|
||||
Crypt::decrypt($encrypted_value);
|
||||
|
||||
> **Note:** The decrypt method will only decrypt strings that were encrypted using **your** application key.
|
||||
69
documentation/other/file.md
Normal file
69
documentation/other/file.md
Normal file
@@ -0,0 +1,69 @@
|
||||
## Working With Files
|
||||
|
||||
- [Reading Files](#get)
|
||||
- [Writing Files](#put)
|
||||
- [File Uploads](#upload)
|
||||
- [File Extensions](#ext)
|
||||
- [Checking File Types](#is)
|
||||
- [Getting MIME Types](#mime)
|
||||
|
||||
<a name="get"></a>
|
||||
### Reading Files
|
||||
|
||||
It's a breeze to get the contents of a file using the **get** method on the **File** class:
|
||||
|
||||
$contents = File::get('path/to/file');
|
||||
|
||||
<a name="put"></a>
|
||||
### Writing Files
|
||||
|
||||
Need to write to a file? Check out the **put** method:
|
||||
|
||||
File::put('path/to/file', 'file contents');
|
||||
|
||||
Want to append to the file instead of overwriting the existing contents? No problem. Use the **append** method:
|
||||
|
||||
File::append('path/to/file', 'appended file content');
|
||||
|
||||
<a name="upload"></a>
|
||||
### File Uploads
|
||||
|
||||
After a file has been uploaded to your application, you will want to move it from its temporary location to a permanent directory. You can do so using the **upload** method. Simply mention the **name** of the uploaded file and the path where you wish to store it:
|
||||
|
||||
File::upload('picture', 'path/to/pictures');
|
||||
|
||||
> **Note:** You can easily validate file uploads using the [Validator class](/docs/start/validation).
|
||||
|
||||
<a name="ext"></a>
|
||||
### File Extensions
|
||||
|
||||
Need to get the extension of a file? Just pass the filename to the **extension** method:
|
||||
|
||||
File::extension('picture.png');
|
||||
|
||||
<a name="is"></a>
|
||||
### Checking File Types
|
||||
|
||||
Often, it is important to know the type of a file. For instance, if a file is uploaded to your application, you may wish to verify that it is an image. It's easy using the **is** method on the **File** class. Simply pass the extension of the file type you are expecting. Here's how to verify that a file is a JPG image:
|
||||
|
||||
if (File::is('jpg', 'path/to/file.jpg'))
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
The **is** method does not simply check the file extension. The Fileinfo PHP extension will be used to read the content of the file and determine the actual MIME type. Pretty cool, huh?
|
||||
|
||||
> **Note:** You may pass any of the extensions defined in the **application/config/mimes.php** file to the **is** method.
|
||||
|
||||
<a name="mime"></a>
|
||||
### Getting MIME Types
|
||||
|
||||
Need to know the MIME type associated with a file extension? Check out the **mime** method:
|
||||
|
||||
echo File::mime('gif');
|
||||
|
||||
The statement above returns the following string:
|
||||
|
||||
image/gif
|
||||
|
||||
> **Note:** This method simply returns the MIME type defined for the extension in the **application/config/mimes.php** file.
|
||||
62
documentation/other/lang.md
Normal file
62
documentation/other/lang.md
Normal file
@@ -0,0 +1,62 @@
|
||||
## Localization
|
||||
|
||||
- [The Basics](#basics)
|
||||
- [Retrieving A Language Line](#get)
|
||||
- [Place Holders & Replacements](#replace)
|
||||
|
||||
<a name="basics"></a>
|
||||
### The Basics
|
||||
|
||||
Localization is the process of translating your application into different languages. The **Lang** class provides a simple mechanism to help you organize and retrieve the text of your multilingual application.
|
||||
|
||||
All of the language files for your application live under the **application/lang** directory. Within the **application/lang** directory, you should create a directory for each language your application speaks. So, for example, if your application speaks English and Spanish, you might create **en** and **sp** directories under the **lang** directory.
|
||||
|
||||
Each language directory may contain many different language files. Each language file is simply an array of string values in that language. In fact, language files are structured identically to configuration files. For example, within the **application/lang/en** directory, you could create a **marketing.php** file that looks like this:
|
||||
|
||||
return array(
|
||||
|
||||
'welcome' => 'Welcome to our website!',
|
||||
|
||||
);
|
||||
|
||||
Next, you should create a corresponding **marketing.php** file within the **application/lang/sp** directory. The file would look something like this:
|
||||
|
||||
return array(
|
||||
|
||||
'welcome' => 'Bienvenido a nuestro sitio web!',
|
||||
|
||||
);
|
||||
|
||||
Nice! Now you know how to get started setting up your language files and directories. Let's keep localizing!
|
||||
|
||||
<a name="basics"></a>
|
||||
### Retrieving A Language Line
|
||||
|
||||
To retrieve a language line, first create a Lang instance using the **line** method, then call the **get** method on the instance:
|
||||
|
||||
echo Lang::line('marketing.welcome')->get();
|
||||
|
||||
Notice how a dot was used to separate "marketing" and "welcome"? The text before the dot corresponds to the language file, while the text after the dot corresponds to a specific string within that file.
|
||||
|
||||
But, how did the method know which language directory to retrieve the message from? By default, the **get** method will use the language specified in your **application/config/application.php** configuration file. In this file you may set the default language of your application using the **language** option:
|
||||
|
||||
'language' => 'en'
|
||||
|
||||
Need to retrieve the line in a language other than your default? Not a problem. Just mention the language to the **get** method:
|
||||
|
||||
echo Lang::line('marketing.welcome')->get('sp');
|
||||
|
||||
<a name="replace"></a>
|
||||
### Place Holders & Replacements
|
||||
|
||||
Now, let's work on our welcome message. "Welcome to our website!" is a pretty generic message. It would be helpful to be able to specify the name of the person we are welcoming. But, creating a language line for each user of our application would be time-consuming and ridiculous. Thankfully, you don't have to. You can specify "place-holders" within your language lines. Place-holders are preceeded by a colon:
|
||||
|
||||
'welcome' => 'Welcome to our website, :name!'
|
||||
|
||||
Then, simply pass an array of place-holder replacements to the **replace** method on a Lang instance:
|
||||
|
||||
echo Lang::line('marketing.welcome')->replace(array('name' => 'Taylor'))->get();
|
||||
|
||||
This statement will return a nice, heart-warming welcome message:
|
||||
|
||||
Welcome to our website, Taylor!
|
||||
Reference in New Issue
Block a user