您正在查看: 2016年6月

laravel 中 Facades的原理以及代码剖析

Facades

原理

In the context of a Laravel application, a facade is a class that provides access to an object from the container. The machinery that makes this work is in the Facade class. Laravel's facades, and any custom facades you create, will extend the base Illuminate\Support\Facades\Facade class.

A facade class only needs to implement a single method: getFacadeAccessor. It's the getFacadeAccessor method's job to define what to resolve from the container. The Facade base class makes use of the __callStatic() magic-method to defer calls from your facade to the resolved object.

简单来说,门面是通过一个魔术方法__callStatic()把静态方法映射到真正的方法上。

本文我们用Route来举例,

Route::get('/', function(){
    # 
}

Facades

原理

In the context of a Laravel application, a facade is a class that provides access to an object from the container. The machinery that makes this work is in the Facade class. Laravel's facades, and any custom facades you create, will extend the base Illuminate\Support\Facades\Facade class.

A facade class only needs to implement a single method: getFacadeAccessor. It's the getFacadeAccessor method's job to define what to resolve from the container. The Facade base class makes use of the __callStatic() magic-method to defer calls from your facade to the resolved object.

简单来说,门面是通过一个魔术方法__callStatic()把静态方法映射到真正的方法上。

本文我们用Route来举例,

Route::get('/', function(){
    # 
}

- 阅读剩余部分 -

laravel Encryption 详解

laravel Encryption 详解

简介

Encryption是laravel自带的一个加密模块,让我们先来看看文档说明

Configuration

Before using Laravel's encrypter, you should set the key option of your config/app.php configuration file to a 32 character, random string. If this value is not properly set, all values encrypted by Laravel will be insecure.

意思就是在使用laravel的encrypter前,需要在config/app.php设置一下key(秘钥)和cipher(加密方式)。

# from config/app.php
'key' => env('APP_KEY'),
'cipher' => 'AES-256-CBC',

env方法指明了读取.env文件的APP_KEY,这个只能够通过 php artisan key:generate生成,也是整个应用程序的key,cipher表明了加密的方式,默认AES-256-CBC

laravel Encryption 详解

简介

Encryption是laravel自带的一个加密模块,让我们先来看看文档说明

Configuration

Before using Laravel's encrypter, you should set the key option of your config/app.php configuration file to a 32 character, random string. If this value is not properly set, all values encrypted by Laravel will be insecure.

意思就是在使用laravel的encrypter前,需要在config/app.php设置一下key(秘钥)和cipher(加密方式)。

# from config/app.php
'key' => env('APP_KEY'),
'cipher' => 'AES-256-CBC',

env方法指明了读取.env文件的APP_KEY,这个只能够通过 php artisan key:generate生成,也是整个应用程序的key,cipher表明了加密的方式,默认AES-256-CBC

- 阅读剩余部分 -