getRequestUri() public méthode

Returns the requested URI (path and query string).
public getRequestUri ( ) : string
Résultat string The raw URI (i.e. not URI decoded)
 /**
  * @return string
  */
 public function getRequestUri()
 {
     if (null === $this->request) {
         throw new \LogicException('No Request set for RequestUriProviderByListener. Do not use this service manually.');
     }
     return $this->request->getRequestUri();
 }
Exemple #2
0
 /**
  * {@inheritdoc}
  */
 protected function doEnhance(CustomUrlBehavior $customUrl, Webspace $webspace, array $defaults, Request $request)
 {
     if ($request->getRequestUri() === '/' || substr($request->getRequestUri(), -1, 1) !== '/') {
         return [];
     }
     return ['_finalized' => true, '_controller' => 'SuluWebsiteBundle:Default:redirect', 'url' => substr($request->getUri(), 0, -1)];
 }
Exemple #3
0
 /**
  * {@inheritdoc}
  */
 public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
 {
     if (strpos($request->getRequestUri(), 'installer') !== false || !$this->isInstalled()) {
         define('MAUTIC_INSTALLER', 1);
     }
     if (defined('MAUTIC_INSTALLER')) {
         $uri = $request->getRequestUri();
         if (strpos($uri, 'installer') === false) {
             $base = $request->getBaseUrl();
             //check to see if the .htaccess file exists or if not running under apache
             if (strpos(strtolower($_SERVER['SERVER_SOFTWARE']), 'apache') === false || !file_exists(__DIR__ . '../.htaccess') && strpos($base, 'index') === false) {
                 $base .= '/index.php';
             }
             return new RedirectResponse($base . '/installer');
         }
     }
     if (false === $this->booted) {
         $this->boot();
     }
     // Check for an an active db connection and die with error if unable to connect
     if (!defined('MAUTIC_INSTALLER')) {
         $db = $this->getContainer()->get('database_connection');
         try {
             $db->connect();
         } catch (\Exception $e) {
             error_log($e);
             throw new \Mautic\CoreBundle\Exception\DatabaseConnectionException($this->getContainer()->get('translator')->trans('mautic.core.db.connection.error', ['%code%' => $e->getCode()]));
         }
     }
     return parent::handle($request, $type, $catch);
 }
 /**
  * Handle and return response.
  *
  * @return Response
  *
  * @throws BadRequestException
  */
 public function serve()
 {
     Log::debug('Request received:', ['Method' => $this->request->getMethod(), 'URI' => $this->request->getRequestUri(), 'Query' => $this->request->getQueryString(), 'Protocal' => $this->request->server->get('SERVER_PROTOCOL'), 'Content' => $this->request->getContent()]);
     $result = $this->handleRequest();
     $response = $this->buildResponse($result['response']);
     Log::debug('Server response created:', compact('response'));
     return new Response($response);
 }
Exemple #5
0
 public function matchItem(ItemInterface $item)
 {
     if (null === $this->request || null === $item->getUri()) {
         return null;
     }
     if ($item->getUri() === $this->request->getRequestUri()) {
         return true;
     }
     return null;
 }
 protected function isWordpressAdminPage(Request $request)
 {
     if (preg_match('/wp-admin/', $request->getRequestUri())) {
         return true;
     }
     if (preg_match('/admin/', $request->getRequestUri())) {
         return true;
     }
     return false;
 }
 public function matchesPath()
 {
     $urlFrom = $this->map->getUrlFrom();
     $requestUri = $this->request->getRequestUri();
     if (!$this->map->getUrlFromIsRegexPattern()) {
         $strtolower = function_exists('mb_strtolower') ? 'mb_strtolower' : 'strtolower';
         return $this->map->getUrlFromIsNoCase() ? $strtolower($urlFrom) === $strtolower($requestUri) : $urlFrom === $requestUri;
     }
     $regexModifier = $this->map->getUrlFromIsNoCase() ? 'i' : '';
     return preg_match('#' . $urlFrom . '#' . $regexModifier, $requestUri, $this->patternMatches);
 }
 public function __invoke(Application $app, Request $request, $id)
 {
     $requestJson = $request->getContent() ?: "{}";
     $data = json_decode($requestJson);
     $this->validate($app, $id, $data);
     $isCreated = !$this->service->contains($request->getRequestUri());
     if ($this->service->save($request->getRequestUri(), $data) === false) {
         throw new ServiceUnavailableHttpException(null, "Failed to save resource");
     }
     return JsonResponse::create($data, $isCreated ? Response::HTTP_CREATED : Response::HTTP_OK);
 }
Exemple #9
0
 /**
  * Returns the domain to use according to the current request.
  * If there is no valid request, null will be returned..
  *
  * @return string domain
  */
 public function getTranslatableDomain()
 {
     $ret = null;
     if ($this->request instanceof Request) {
         $uriParts = explode('/', substr($this->request->getRequestUri(), 1));
         if (isset($uriParts[0])) {
             $ret = $uriParts[0];
         }
     }
     return $ret;
 }
 public function __invoke(Request $request)
 {
     if (!$this->service->contains($request->getRequestUri())) {
         throw new NotFoundHttpException("Not Found");
     }
     $resource = $this->service->fetch($request->getRequestUri());
     if ($resource === false) {
         throw new ServiceUnavailableHttpException(null, "Failed to retrieve resource");
     }
     $response = JsonResponse::create($resource);
     $response->headers->set("Content-Type", $this->contentType);
     return $response;
 }
 public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
 {
     if ($request->getRequestUri() == "/") {
         return new Response("public");
     }
     if ($request->getRequestUri() == "/protected") {
         return new Response("protected");
     }
     if ($request->getRequestUri() == "/anon") {
         return new Response("anonymous");
     }
     return new Response("invalid");
 }
 /**
  * @param ItemInterface $item
  *
  * @return bool
  */
 public function matchItem(ItemInterface $item)
 {
     $requestUri = $this->request->getRequestUri();
     $baseUrl = $this->request->getBaseUrl() . '/';
     $uri = $item->getUri();
     if ($uri === $requestUri) {
         return true;
     } else {
         if ($uri !== $baseUrl && substr($requestUri, 0, strlen($uri)) === $uri) {
             return true;
         }
     }
     return null;
 }
 /**
  * Request constructor.
  *
  * @param        $request
  * @param        $response
  * @param string $username
  */
 public function __construct(SymfonyRequest $request, Response $response, $username = '******')
 {
     $this->request = $request;
     $this->response = $response;
     $this->username = $username;
     $this->uri = $request->getRequestUri();
 }
 public function indexAction(Request $request, $slug)
 {
     //echo '<pre>';print_r($slug);die;
     $page = new Page();
     $page->setUrl($request->getRequestUri());
     $page->setTitle('Homepage');
     $page->setSlug($slug);
     $site = new Site();
     $site->setBaseurl($request->getBaseUrl());
     $github = new \stdClass();
     $github->user = '******';
     $github->repo = 'bootstrap-bundle';
     $site->setGithub($github);
     $data = $site->getData();
     $data['showcase'] = Yaml::parse(__DIR__ . '/../Resources/data/showcase.yml');
     $data['translations'] = Yaml::parse(__DIR__ . '/../Resources/data/translations.yml');
     $site->setData($data);
     $site->setDownload(array('dist' => 'https://github.com/twbs/bootstrap/releases/download/v3.2.0/bootstrap-3.2.0-dist.zip', 'source' => 'https://github.com/twbs/bootstrap/archive/v3.2.0.zip', 'sass' => 'https://github.com/twbs/bootstrap-sass/archive/v3.2.0.tar.gz'));
     $site->setCdn(array('css' => 'https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css', 'css_theme' => 'https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css', 'js' => 'https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js'));
     $site->setTime(new \DateTime());
     /*$content = $this->render(
           'BootstrapBundle:pages:' . $slug . '.html.twig',
           array(
               'site' => $site
           )
       )->getContent();*/
     if ($slug == 'index') {
         $file = 'home';
     } else {
         $file = 'default';
     }
     return $this->render('BootstrapBundle:layouts:' . $file . '.html.twig', array('page' => $page, 'site' => $site, 'slug' => $slug));
 }
Exemple #15
0
 /**
  * Chooses a language for a request
  *
  * @return $response or null
  **/
 public function switchLocaleForRequest(Request $request)
 {
     $session = $request->getSession();
     $parts = explode('.', $request->getHost());
     if (count($parts) === 3) {
         $locale = $parts[0];
         if ($locale == $session->getLocale()) {
             return;
         }
         if ($this->manager->isAvailable($locale)) {
             $session->setLocale($locale);
             $preferred = $request->getPreferredLanguage($this->manager->getAvailableLanguageCodes());
             if ($preferred != $locale) {
                 $session->setFlash('locale_change_adjust', $preferred);
             } else {
                 $session->setFlash('locale_change_contribute', $locale);
             }
             return;
         }
         $host = $parts[1] . '.' . $parts[2];
     } else {
         $host = $parts[0] . '.' . $parts[1];
     }
     $locale = $request->getPreferredLanguage($this->manager->getAvailableLanguageCodes());
     $url = sprintf('http://%s.%s%s', $locale, $host, $request->getRequestUri());
     $response = new RedirectResponse($url);
     $preferredLanguage = $this->getRequestPreferredLanguage($request);
     if ($preferredLanguage && $locale != $preferredLanguage) {
         $allLanguageCodes = array_keys($this->manager->getLanguages());
         if (in_array($preferredLanguage, $allLanguageCodes)) {
             $session->setFlash('locale_missing', $preferredLanguage);
         }
     }
     return $response;
 }
Exemple #16
0
 /**
  * Breadcrumbs
  *
  * @param Request $request
  *
  * @return mixed
  */
 public function createBreadcrumbsMenu(Request $request)
 {
     $menu = $this->factory->createItem('root');
     $menu->setUri($request->getRequestUri());
     $menu->addChild($this->translator->trans('Главная'), array('route' => 'homepage'));
     return $menu;
 }
 /**
  * Logs the duration of a specific request through the application
  *
  * @param Request $request
  * @param Response $response
  * @param double $startTime
  */
 protected static function logDuration(Request $request, Response $response, $startTime)
 {
     $duration = microtime(true) - $startTime;
     $metric = self::prefix('request_time');
     $tags = ["url" => $request->getSchemeAndHttpHost() . $request->getRequestUri(), "status_code" => $response->getStatusCode()];
     Datadog::timing($metric, $duration, 1, $tags);
 }
Exemple #18
0
 public function __construct(Request $request, Router $router)
 {
     parent::__construct();
     $this->setCurrentUri($request->getRequestUri());
     $this->addChild('Song Library', $router->generate('song'));
     $this->addChild('Add Song to Library', $router->generate('song_create'));
 }
 /**
  * the master method.  delegate the request
  * to the right class method with parameters.
  * returns the result of the method call
  *
  * @param Request $request
  * @return mixed
  */
 public function delegate(Request $request)
 {
     $args = $request->request->all();
     $uriParts = explode('?', $request->getRequestUri());
     $path = $uriParts[0];
     $path = trim($path, '/');
     $path ? $pathParts = explode('/', urldecode($path)) : ($pathParts = array());
     // access routing overrides from application.xml
     $pathParts = $this->implementRoutingOverrides($pathParts);
     $method = array_pop($pathParts);
     $thing = implode('', $pathParts);
     // convert classname
     $classname_parts = explode('-', $thing);
     foreach ($classname_parts as &$part) {
         $part = ucfirst($part);
     }
     $classname = implode('', $classname_parts);
     // convert method name
     $x = explode("-", $method);
     for ($i = 1; $i < count($x); $i++) {
         $x[$i] = ucfirst($x[$i]);
     }
     $method = implode('', $x);
     Event::run($classname . '::onBefore' . ucfirst($method));
     $result = call_user_func_array(array($this->{$classname}, $method), $args);
     Event::run($classname . '::onAfter' . ucfirst($method));
     return $result;
 }
 public function indexAction(Request $req, Application $app)
 {
     // Check if user is an logged in and an Admin
     if (!$this->userHasAccess($app)) {
         return $app->redirect($app['url'] . '/dashboard');
     }
     $admin_user_id = $app['sentry']->getUser()->getId();
     $mapper = $app['spot']->mapper('OpenCFP\\Entity\\Talk');
     $pager_formatted_talks = $mapper->getAllPagerFormatted($admin_user_id);
     // Set up our page stuff
     $adapter = new \Pagerfanta\Adapter\ArrayAdapter($pager_formatted_talks);
     $pagerfanta = new \Pagerfanta\Pagerfanta($adapter);
     $pagerfanta->setMaxPerPage(20);
     $pagerfanta->getNbResults();
     if ($req->get('page') !== null) {
         $pagerfanta->setCurrentPage($req->get('page'));
     }
     // Create our default view for the navigation options
     $routeGenerator = function ($page) {
         return '/admin/talks?page=' . $page;
     };
     $view = new TwitterBootstrap3View();
     $pagination = $view->render($pagerfanta, $routeGenerator, array('proximity' => 3));
     $template = $app['twig']->loadTemplate('admin/talks/index.twig');
     $templateData = array('pagination' => $pagination, 'talks' => $pagerfanta, 'page' => $pagerfanta->getCurrentPage(), 'current_page' => $req->getRequestUri(), 'totalRecords' => count($pager_formatted_talks));
     return $template->render($templateData);
 }
 public function createRightSideDropdownMenu(Request $request)
 {
     $menu = $this->factory->createItem('root');
     $menu->setCurrentUri($request->getRequestUri());
     $menu->setChildrenAttribute('class', 'nav pull-right');
     // ... add theme change
     $dropdown = $this->createDropdownMenuItem($menu, "Change Theme", true, array('icon' => 'caret'));
     $dropdown->addChild('Bootstrap', array('route' => 'liip_theme_switch', 'routeParameters' => array('theme' => 'bootstrap')));
     $dropdown->addChild('initializr', array('route' => 'liip_theme_switch', 'routeParameters' => array('theme' => 'initializr')));
     $dropdown = $this->createDropdownMenuItem($menu, "Tools Menu", true, array('icon' => 'caret'));
     $dropdown->addChild('Symfony', array('uri' => 'http://www.symfony.com'));
     $dropdown->addChild('bootstrap', array('uri' => 'http://twitter.github.com/bootstrap/'));
     $dropdown->addChild('node.js', array('uri' => 'http://nodejs.org/'));
     $dropdown->addChild('less', array('uri' => 'http://lesscss.org/'));
     //adding a nice divider
     $this->addDivider($dropdown);
     $dropdown->addChild('google', array('uri' => 'http://www.google.com/'));
     $dropdown = $this->createDropdownMenuItem($menu, "Another Dropdown", true, array('icon' => 'caret'));
     $dropdown->addChild('node.js', array('uri' => 'http://nodejs.org/'));
     //adding a nice divider
     $this->addDivider($dropdown);
     $dropdown->addChild('Mohrenweiser & Partner', array('uri' => 'http://www.mohrenweiserpartner.de'));
     // ... add more children
     return $menu;
 }
 public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
 {
     $data = ['request-id' => $request->headers->get('X-Request-Id'), 'datetime' => date('Y-m-d H:i:s'), 'method' => $request->getMethod(), 'scheme' => $request->getScheme(), 'host' => $request->getHttpHost(), 'uri' => $request->getRequestUri(), 'route' => $request->get('_route')];
     /*
     if (isset($this['current_user'])) {
         $data['username'] = $this['current_user']->getName();
     }
     */
     $data['address'] = $request->getClientIp();
     if ($request->getSession()) {
         $data['session-id'] = $request->getSession()->getId();
     }
     if ($request->headers->has('User-Agent')) {
         $data['agent'] = $request->headers->get('User-Agent');
     }
     if ($request->headers->has('referer')) {
         $data['referer'] = $request->headers->get('referer');
     }
     $this->log($data);
     $response = $this->app->handle($request, $type, $catch);
     /*
     // response details
     $data['status'] = $response->getStatusCode();
     if ($response->headers->has('Content-Type')) {
         $data['content-type'] = $response->headers->get('content-type');
     }
     */
     return $response;
 }
 public function cosign_login(Request $request)
 {
     $request_uri = $request->getRequestUri();
     global $base_path;
     if (!CosignSharedFunctions::cosign_is_https()) {
         return new TrustedRedirectResponse('https://' . $_SERVER['HTTP_HOST'] . $request_uri);
     } else {
         if ($request_uri == $base_path) {
             //The front page is set to /user. we have to login here to avoid a redirect loop
             $username = CosignSharedFunctions::cosign_retrieve_remote_user();
             $user = CosignSharedFunctions::cosign_user_status($username);
             if (empty($user) || $user->id() == 0) {
                 $response = array('#type' => 'markup', '#title' => 'Auto creation of user accounts is disabled.', '#markup' => t('<p>This site does not auto create users from cosign. Please contact the <a href="mailto:' . \Drupal::config("system.site")->get("mail") . '">site administrator</a> to have an account created.</p>'));
                 return $response;
             } else {
                 if (in_array('administrator', $user->getRoles())) {
                     drupal_set_message('When the homepage is set to /user (Drupal default), anonymous browsing will not always work', 'warning');
                 }
                 $referrer = $base_path . 'user';
             }
         } elseif (isset($_SERVER['HTTP_REFERER'])) {
             $referrer = $_SERVER['HTTP_REFERER'];
         } else {
             $referrer = $base_path;
         }
         return new TrustedRedirectResponse($referrer);
     }
 }
 public function indexAction(Request $req)
 {
     if (!$this->userHasAccess($this->app)) {
         return $this->redirectTo('login');
     }
     $admin_user_id = $this->app['sentry']->getUser()->getId();
     $options = ['order_by' => $req->get('order_by'), 'sort' => $req->get('sort')];
     $pager_formatted_talks = $this->getFilteredTalks($req->get('filter'), $admin_user_id, $options);
     $per_page = (int) $req->get('per_page') ?: 20;
     // Set up our page stuff
     $adapter = new \Pagerfanta\Adapter\ArrayAdapter($pager_formatted_talks);
     $pagerfanta = new \Pagerfanta\Pagerfanta($adapter);
     $pagerfanta->setMaxPerPage($per_page);
     $pagerfanta->getNbResults();
     if ($req->get('page') !== null) {
         $pagerfanta->setCurrentPage($req->get('page'));
     }
     $queryParams = $req->query->all();
     // Create our default view for the navigation options
     $routeGenerator = function ($page) use($queryParams) {
         $queryParams['page'] = $page;
         return '/admin/talks?' . http_build_query($queryParams);
     };
     $view = new TwitterBootstrap3View();
     $pagination = $view->render($pagerfanta, $routeGenerator, array('proximity' => 3));
     $templateData = ['pagination' => $pagination, 'talks' => $pagerfanta, 'page' => $pagerfanta->getCurrentPage(), 'current_page' => $req->getRequestUri(), 'totalRecords' => count($pager_formatted_talks), 'filter' => $req->get('filter'), 'per_page' => $per_page, 'sort' => $req->get('sort'), 'order_by' => $req->get('order_by')];
     return $this->render('admin/talks/index.twig', $templateData);
 }
 /**
  * This route decides wheater a request has a missing locale or it is a missing page
  *
  * @param Request $request
  *
  * @return Response
  */
 public function localeRedirectAction(Request $request)
 {
     $requestUri = $request->getRequestUri();
     $explodedUri = explode('/', $requestUri);
     $doubleSlash = substr($requestUri, 0, 2) === '//';
     if (!$doubleSlash) {
         // does not start with 2 slashes
         if (strlen($explodedUri[1]) !== 2) {
             // no locale supplied
             $matchingRoute = $this->get('router')->match("/" . $requestUri);
         } else {
             // 404
             throw $this->createNotFoundException();
         }
     } else {
         $requestUri = substr($requestUri, 2);
         // Removed first 2 slashes
         $locale = empty($request->getLocale()) ? $request->getDefaultLocale() : mb_substr($request->getLocale(), 0, 2);
         $requestUri = '/' . $locale . '/' . $requestUri;
         $matchingRoute = $this->get('router')->match($requestUri);
     }
     if ($matchingRoute['_controller'] === 'Ashura\\OptionalLocaleBundle\\Controller\\DefaultController::localeRedirectAction') {
         throw $this->createNotFoundException();
     }
     return $this->forward($matchingRoute['_controller']);
 }
 /**
  * @param Request $request
  * @return \Symfony\Component\HttpFoundation\RedirectResponse
  */
 public function removeTrailingSlashAction(Request $request)
 {
     $pathInfo = $request->getPathInfo();
     $requestUri = $request->getRequestUri();
     $url = str_replace($pathInfo, rtrim($pathInfo, ' /'), $requestUri);
     return $this->redirect($url, 301);
 }
 /**
  * get grid object filled
  *
  * @param  \Kitpages\DataGridBundle\Grid\GridConfig $gridConfig
  * @param  \Symfony\Component\HttpFoundation\Request $request
  * @return \Kitpages\DataGridBundle\Grid\Grid
  */
 public function getGrid(GridConfig $gridConfig, Request $request)
 {
     $queryBuilder = $gridConfig->getQueryBuilder();
     // create grid objet
     $grid = new Grid();
     $grid->setGridConfig($gridConfig);
     $grid->setUrlTool(new UrlTool());
     $grid->setRequestUri($request->getRequestUri());
     $grid->setRequestCurrentRoute($request->attributes->get("_route"));
     $grid->setRequestCurrentRouteParams($request->attributes->get("_route_params"));
     $grid->setDispatcher($this->dispatcher);
     // create base request
     $gridQueryBuilder = clone $queryBuilder;
     // Apply filters
     $filter = $request->query->get($grid->getFilterFormName(), "");
     $this->applyFilter($gridQueryBuilder, $grid, $filter);
     // Apply selector
     $selectorField = $request->query->get($grid->getSelectorFieldFormName(), "");
     $selectorValue = $request->query->get($grid->getSelectorValueFormName(), "");
     $this->applySelector($gridQueryBuilder, $grid, $selectorField, $selectorValue);
     // Apply sorting
     $sortField = $request->query->get($grid->getSortFieldFormName(), "");
     $sortOrder = $request->query->get($grid->getSortOrderFormName(), "");
     $this->applySort($gridQueryBuilder, $grid, $sortField, $sortOrder);
     // build paginator
     $paginatorConfig = $gridConfig->getPaginatorConfig();
     if ($paginatorConfig === null) {
         $paginatorConfig = new PaginatorConfig();
         $paginatorConfig->setCountFieldName($gridConfig->getCountFieldName());
         $paginatorConfig->setName($gridConfig->getName());
         $paginatorConfig->setQueryBuilder($gridQueryBuilder);
     }
     if (is_null($paginatorConfig->getQueryBuilder())) {
         $paginatorConfig->setQueryBuilder($gridQueryBuilder);
     }
     $paginator = $this->paginatorManager->getPaginator($paginatorConfig, $request);
     $grid->setPaginator($paginator);
     // calculate limits
     $gridQueryBuilder->setMaxResults($paginator->getPaginatorConfig()->getItemCountInPage());
     $gridQueryBuilder->setFirstResult(($paginator->getCurrentPage() - 1) * $paginator->getPaginatorConfig()->getItemCountInPage());
     // send event for changing grid query builder
     $event = new DataGridEvent();
     $event->set("grid", $grid);
     $event->set("gridQueryBuilder", $gridQueryBuilder);
     $event->set("request", $request);
     $this->dispatcher->dispatch(KitpagesDataGridEvents::ON_GET_GRID_QUERY, $event);
     if (!$event->isDefaultPrevented()) {
         // execute request
         $query = $gridQueryBuilder->getQuery();
         $event->set("query", $query);
     }
     $this->dispatcher->dispatch(KitpagesDataGridEvents::AFTER_GET_GRID_QUERY, $event);
     // hack : recover query from the event so the developper can build a new grid
     // from the gridQueryBuilder in the listener and reinject it in the event.
     $normalizedItemList = $this->itemListNormalizer->normalize($event->get("query"), $event->get("gridQueryBuilder"), $this->hydratorClass);
     // end normalization
     $grid->setItemList($normalizedItemList);
     return $grid;
 }
 /**
  * @param Request $request
  * @param $menu
  * @return array
  */
 protected function getCurrentPage(Request $request, array $menu) : array
 {
     /**
      * @var Menu $item
      */
     foreach ($menu as $item) {
         if ($request->getRequestUri() === $item->getUri()) {
             return $item->toJson();
         }
     }
     foreach ($menu as $item) {
         if ($item->getUri() !== "/" && strpos($request->getRequestUri(), $item->getUri()) !== false) {
             return $item->toJson();
         }
     }
     return [];
 }
 public function __construct(Request $request, Router $router)
 {
     parent::__construct();
     $this->setCurrentUri($request->getRequestUri());
     $this->addChild('Admin', $router->generate('admin'));
     $this->addChild('Sign out', $router->generate('_security_logout'));
     $this->setAttributes(array('id' => 'tools-menu', 'class' => 'menu'));
 }
Exemple #30
-1
 /**
  *
  * @param Request $request
  * @throws AppException
  * @return ApplicationUri
  */
 public function match($request)
 {
     $found = null;
     $uris = ApplicationUriQuery::create()->joinApplication()->filterByHttphost($request->getHttpHost())->find();
     $requestUri = Text::create($request->getRequestUri())->trimRight('/');
     foreach ($uris as $uri) {
         $basepath = new Text($uri->getBasepath());
         // either request uri and uri basepath are both empty
         // or request uri starts with basepath
         if ($basepath->isEmpty() && $uri->getHttphost() == $request->getHttpHost() || $requestUri->startsWith($basepath)) {
             // assign when it's the first found
             if ($found === null) {
                 $found = $uri;
             } else {
                 if ($basepath->count('/') > Text::create($found->getBasepath())->count('/')) {
                     $found = $uri;
                 }
             }
         }
     }
     if ($found === null) {
         throw new AppException(sprintf('No app found on %s', $request->getUri()), 404);
     }
     $this->destination = str_replace($found->getBasepath(), '', $request->getRequestUri());
     return $found;
 }