本文整理汇总了PHP中Pimple\Container::before方法的典型用法代码示例。如果您正苦于以下问题:PHP Container::before方法的具体用法?PHP Container::before怎么用?PHP Container::before使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pimple\Container
的用法示例。
在下文中一共展示了Container::before方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: register
public function register(Container $app)
{
$app['menu_manager'] = function ($app) {
return new MenuManager($app, $app['menu']);
};
$app['menu_manager.security'] = function ($app) {
return new MenuSecurityService($app);
};
$app['twig.loader.filesystem'] = $app->extend('twig.loader.filesystem', function ($filesystem, $app) {
$filesystem->addPath(__DIR__ . '/../Resource/views', 'MenuManager');
return $filesystem;
});
$app['twig'] = $app->extend('twig', function ($twig, $app) {
$twig->addFunction(new \Twig_SimpleFunction('menu', function ($which = 'main', Item $item = null, $paramList = [], $activeOnly = false) use($app) {
return $app['menu_manager']->render($which, $item, $paramList, $activeOnly);
}));
$twig->addFunction(new \Twig_SimpleFunction('breadcrumb', function ($paramList = []) use($app) {
return $app['menu_manager']->renderBreadcrumb($paramList);
}));
return $twig;
});
// Current route name
$app->before(function (Request $request) use($app) {
$app['menu_manager']->setCurrentRoute($request->get('_route'));
});
}
示例2: register
public function register(Container $app)
{
$app->before(function (Request $request) {
if ($this->isRequestTransformable($request)) {
$transformedRequest = $this->transformContent($request->getContent());
$request->request->replace($transformedRequest);
}
});
}
示例3: register
public function register(Container $app)
{
$app->before(function (Request $req) use($app) {
$correctUser = $app['basic_auth.user'];
$correctPasswordMd5 = $app['basic_auth.password_md5'];
if (isset($app['basic_auth.pattern'])) {
$pattern = $app['basic_auth.pattern'];
$uri = $req->getRequestUri();
if (!preg_match("|{$pattern}|u", $uri)) {
return;
}
}
$realm = 'Secured';
if (isset($app['basic_auth.realm'])) {
$realm = $app['basic_auth.realm'];
}
$authUser = $req->server->get('PHP_AUTH_USER');
$authPw = $req->server->get('PHP_AUTH_PW');
if ($authUser === $correctUser && md5($authPw) === $correctPasswordMd5) {
return;
}
throw new HttpException(Response::HTTP_UNAUTHORIZED, null, null, ['WWW-Authenticate' => 'Basic realm="' . $realm . '"']);
});
}