Example #1
0
 public function pathFor($args)
 {
     $name = $args['name'];
     $data = isset($args['options']) ? $args['options'] : [];
     $queryParams = isset($args['queryParams']) ? $args['queryParams'] : [];
     return $this->router->pathFor($name, $data, $queryParams);
 }
 public function pathFor($params, Smarty_Internal_Template $template)
 {
     if (!isset($params['data'])) {
         $params['data'] = [];
     }
     if (!isset($params['queryParams'])) {
         $params['queryParams'] = [];
     }
     return $this->router->pathFor($params['name'], $params['data'], $params['queryParams']);
 }
 /**
  * Renders the html to include needed assets
  *
  * Only useful if Assetic is not used
  *
  * @param  RouterInterface Description
  *
  * @return string
  */
 public function renderHeadSlim(RouterInterface $router)
 {
     $jsModified = $this->getModifiedTime('js');
     $cssModified = $this->getModifiedTime('css');
     $html = '';
     $html .= sprintf('<link rel="stylesheet" type="text/css" href="%s?%s">' . "\n", $router->pathFor('debugbar-assets-css'), $cssModified);
     $html .= sprintf('<script type="text/javascript" src="%s?%s"></script>' . "\n", $router->pathFor('debugbar-assets-js'), $jsModified);
     if ($this->isJqueryNoConflictEnabled()) {
         $html .= '<script type="text/javascript">jQuery.noConflict(true);</script>' . "\n";
     }
     return $html;
 }
Example #4
0
 /**
  * @param ConfigRepository $config
  * @param Container $container
  * @param Router $router
  */
 private function initRoutes(ConfigRepository $config, Container $container, Router $router)
 {
     $routes = $config->get('routes');
     foreach ($routes as $request => $controller) {
         $request = explode(' ', $request);
         $method = $request[0];
         $url = $request[1];
         $action = $controller[1];
         $controller = $container->get($controller[0]);
         $router->map([$method], $url, function ($req, $res, $args) use($controller, $action) {
             return $controller->{$action}($req, $res, $args);
         });
     }
 }
Example #5
0
 /**
  *
  */
 public function nav($root)
 {
     if (!isset($this->navigation[$root]) || !is_array($this->navigation[$root])) {
         return [];
     }
     $navigation = $this->navigation[$root];
     $aclFilter = function ($page) {
         if (!$this->acl) {
             return true;
         }
         $path = parse_url($page['href'], PHP_URL_PATH);
         if (isset($page['external'])) {
             return true;
         }
         $resource = 'route' . $path;
         return $this->acl->isAllowed($this->currentRole, $resource, 'get');
     };
     $prepare = function ($page) use(&$prepare, &$aclFilter) {
         if (isset($page['route'])) {
             $routeData = isset($page['route_data']) ? $page['route_data'] : [];
             $query = isset($page['query']) ? $page['query'] : [];
             $page['href'] = $this->router->pathFor($page['route'], $routeData, $query);
         }
         $path = parse_url($page['href'], PHP_URL_PATH);
         $page['active'] = $path !== '/' && 0 === strpos($this->request->getUri()->getPath(), $path);
         if (isset($page['pages']) && is_array($page['pages'])) {
             $page['pages'] = array_filter(array_map($prepare, $page['pages']), $aclFilter);
         }
         return $page;
     };
     return array_filter(array_map($prepare, $navigation), $aclFilter);
 }
Example #6
0
 /**
  * Dispatch the router to find the route. Prepare the route for use.
  *
  * @param ServerRequestInterface $request
  * @param RouterInterface        $router
  * @return ServerRequestInterface
  */
 protected function dispatchRouterAndPrepareRoute(ServerRequestInterface $request, RouterInterface $router)
 {
     $routeInfo = $router->dispatch($request);
     if ($routeInfo[0] === Dispatcher::FOUND) {
         $routeArguments = [];
         foreach ($routeInfo[2] as $k => $v) {
             $routeArguments[$k] = urldecode($v);
         }
         $route = $router->lookupRoute($routeInfo[1]);
         $route->prepare($request, $routeArguments);
         // add route to the request's attributes in case a middleware or handler needs access to the route
         $request = $request->withAttribute('route', $route);
     }
     $routeInfo['request'] = [$request->getMethod(), (string) $request->getUri()];
     return $request->withAttribute('routeInfo', $routeInfo);
 }
Example #7
0
 public function pathFor($name, $data = [], $queryParams = [], $appName = 'default')
 {
     return $this->router->pathFor($name, $data, $queryParams);
 }