0

私は現在Laravel 4を使用しており、Request::secure()メソッドをオーバーライドする方法をさまよっていました.ロードバランサーの背後にあるアプリケーションを書いているので、ヘッダーがロードバランサーから適用される値。

理想的にはどのように行うべきですか?ここでこのブログ投稿を読みましたhttp://fideloper.com/extend-request-response-laravelこれは少しやりすぎのようです。

Laravel の Facades の概念を完全に理解していませんか? これを行う方法で私の答えがどこにある可能性はありますか?

4

1 に答える 1

2

fideloper が彼の記事で言及しているように、クラスの拡張はRequest通常のクラスとは少し異なります。ただし、より単純です。

1.拡張Requestクラスを作成し、オートロードできることを確認します。

ExtendedRequest.php

namespace Raphael\Extensions;

use Illuminate\Support\Facades\Response as IlluminateResponse;

class Response extends IlluminateResponse {
    public function isSecure() {
        return true;
    }
}

isSecureの代わりにメソッドを拡張したことに注意してくださいsecure。これは、secure単にisScureSymfony の基本Requestクラスから , を呼び出すためです。

2. Laravel が拡張クラスを使用していることを確認します。これを行うには、start.phpファイルを変更します。

ブートストラップ/start.php

/*
|--------------------------------------------------------------------------
| Create The Application
|--------------------------------------------------------------------------
|
| The first thing we will do is create a new Laravel application instance
| which serves as the "glue" for all the components of Laravel, and is
| the IoC container for the system binding all of the various parts.
|
*/

use Illuminate\Foundation\Application;
Application::requestClass('Raphael\Extensions\Request');

$app = new Application;

$app->redirectIfTrailingSlash();

3. app.php設定ファイルに正しいエイリアスが設定されていることを確認してください。

アプリ/設定/app.php

'aliases' => array(
    // ...
    'Request' => 'Raphael\Extensions\Request',
    // ...
),
于 2013-09-16T04:41:36.830 に答える