Php Laravel';中请求类的安全函数的扩展或重写功能;s框架,最佳行动?
我目前使用的是Laravel 4,正在考虑如何重写Request::secure()方法,我正在编写一个应用程序,它将位于负载平衡器后面,因此,如果从负载平衡器应用头值,我宁愿让函数返回true 理想情况下应该如何做?我在这里读了这篇博客文章,似乎有点过分了Php Laravel';中请求类的安全函数的扩展或重写功能;s框架,最佳行动?,php,laravel,laravel-4,Php,Laravel,Laravel 4,我目前使用的是Laravel 4,正在考虑如何重写Request::secure()方法,我正在编写一个应用程序,它将位于负载平衡器后面,因此,如果从负载平衡器应用头值,我宁愿让函数返回true 理想情况下应该如何做?我在这里读了这篇博客文章,似乎有点过分了 我不完全理解拉威尔的外观概念?这可能就是我在lyes中关于如何做到这一点的答案吗?正如fideloper在他的文章中提到的,扩展请求类与普通类有一点不同。但更简单的是: 1.创建扩展的请求类,并确保它可以自动加载 ExtendedReque
我不完全理解拉威尔的外观概念?这可能就是我在lyes中关于如何做到这一点的答案吗?正如fideloper在他的文章中提到的,扩展
请求
类与普通类有一点不同。但更简单的是:
1.创建扩展的请求
类,并确保它可以自动加载
ExtendedRequest.php
namespace Raphael\Extensions;
use Illuminate\Support\Facades\Response as IlluminateResponse;
class Response extends IlluminateResponse {
public function isSecure() {
return true;
}
}
/*
|--------------------------------------------------------------------------
| 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();
'aliases' => array(
// ...
'Request' => 'Raphael\Extensions\Request',
// ...
),
注意,我们扩展了isSecure
方法,而不是secure
。这是因为secure
只是从Symfony的baseRequest
类调用isScure
2.确保Laravel使用您的扩展类。为此,更改start.php文件
bootstrap/start.php
namespace Raphael\Extensions;
use Illuminate\Support\Facades\Response as IlluminateResponse;
class Response extends IlluminateResponse {
public function isSecure() {
return true;
}
}
/*
|--------------------------------------------------------------------------
| 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();
'aliases' => array(
// ...
'Request' => 'Raphael\Extensions\Request',
// ...
),
3.确保在app.php配置文件中设置了正确的别名
app/config/app.php
namespace Raphael\Extensions;
use Illuminate\Support\Facades\Response as IlluminateResponse;
class Response extends IlluminateResponse {
public function isSecure() {
return true;
}
}
/*
|--------------------------------------------------------------------------
| 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();
'aliases' => array(
// ...
'Request' => 'Raphael\Extensions\Request',
// ...
),
那篇博文几乎就是你问题的答案。“Facade”就像是响应的契约/接口。你的意思是不是
Request::secure()
?是的,我很抱歉这是一个深夜打字错误,我应该将自动加载的类放在哪里?任何地方,只要你在composer.json上正确设置它。我喜欢将文件放在app/lib
下,不带任何名称空间。然后我只需在我的composer.json
文件中的autload
下添加“app/lib”
。