Exemplo n.º 1
0
 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'));
     });
 }
 public function register(Container $app)
 {
     $app->before(function (Request $request) {
         if ($this->isRequestTransformable($request)) {
             $transformedRequest = $this->transformContent($request->getContent());
             $request->request->replace($transformedRequest);
         }
     });
 }
Exemplo n.º 3
0
 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 . '"']);
     });
 }