/** * @param View $view */ public function compose(View $view) { $view->cruddyData = $this->cruddy->data(); $view->cruddyData += ['schemaUrl' => $this->url->route('cruddy.schema'), 'thumbUrl' => $this->url->route('cruddy.thumb'), 'baseUrl' => $this->url->route('cruddy.home'), 'root' => $this->request->root(), 'token' => csrf_token()]; $view->scripts = $this->assets->scripts(); $view->styles = $this->assets->styles(); $view->menu = $this->menuBuilder; }
/** * Return true if current page is $page. */ public function isPage(string $page, array $parameters = []) : bool { // Check if $page is a route name if ($this->route->has($page)) { if ($parameters) { return $this->url->current() == $this->url->route($page, $parameters); } return $this->route->currentRouteName() == $page; } return str_replace($this->request->root() . '/', '', $this->url->full()) == $page; }
/** * {@inheritdoc} */ public function renderHead() { if (!$this->url) { return parent::renderHead(); } $jsModified = $this->getModifiedTime('js'); $cssModified = $this->getModifiedTime('css'); $html = ''; $html .= sprintf('<link rel="stylesheet" type="text/css" href="%s?%s">' . "\n", $this->url->route('debugbar.assets.css'), $cssModified); $html .= sprintf('<script type="text/javascript" src="%s?%s"></script>' . "\n", $this->url->route('debugbar.assets.js'), $jsModified); if ($this->isJqueryNoConflictEnabled()) { $html .= '<script type="text/javascript">jQuery.noConflict(true);</script>' . "\n"; } return $html; }
/** * {@inheritdoc} */ public function renderHead() { if (!$this->url) { return parent::renderHead(); } $cssRoute = $this->url->route('debugbar.assets.css', ['v' => $this->getModifiedTime('css')]); $jsRoute = $this->url->route('debugbar.assets.js', ['v' => $this->getModifiedTime('js')]); $html = ''; $html .= "<link rel='stylesheet' type='text/css' href='{$cssRoute}'>"; $html .= "<script type='text/javascript' src='{$jsRoute}'></script>"; if ($this->isJqueryNoConflictEnabled()) { $html .= '<script type="text/javascript">jQuery.noConflict(true);</script>' . "\n"; } return $html; }
/** * Perform an API request to a controller action. * * @param string $action * @param string|array $actionParameters * @param string|array $parameters * @return mixed */ public function action($action, $actionParameters = [], $parameters = []) { $version = $this->version ?: $this->router->getDefaultVersion(); $route = $this->router->getApiRouteCollection($version)->getByAction($action); $uri = ltrim($this->url->route($action, $actionParameters, false, $route), '/'); return $this->queueRequest($route->methods()[0], $uri, $parameters); }
/** * Get a URL for a given page number. * * @param integer $page * @return string */ public function url($page) { if (null === $this->routeConfig) { //return parent::url($page); if ($page <= 0) { $page = 1; } // If we have any extra query string key / value pairs that need to be added // onto the URL, we will put them in query string form and then attach it // to the URL. This allows for extra information like sortings storage. $parameters = [$this->pageName => $page]; if (count($this->query) > 0) { $parameters = array_merge($this->query, $parameters); } return $this->getCurrentUrl() . '?' . http_build_query($parameters, null, '&') . $this->buildFragment(); } $parameters = $this->routeConfig['parameters']; //$parameters = [$this->pageName => $page]; //$this->getRequest()->query() if (true === $this->withQuery) { $parameters = array_merge($parameters, $this->query); } $parameters[$this->getPageName()] = $page; $absolute = null === $this->routeConfig['absolute'] ? true : $this->routeConfig['absolute']; // allow adding hash fragments to url $fragment = $this->buildFragment(); $generated_route = $this->urlGenerator->route($this->routeConfig['name'], $parameters, $absolute, $this->routeConfig['instance']); return $generated_route . $fragment; }
/** * Get the route action for a "route" option. * * @param array|string $route * @return string */ protected function getRoute($route) { if (is_array($route)) { return $this->url->route($route[0], array_slice($route, 1)); } return $this->url->route($route); }
/** * Get the action for a "route" option. * * @param array|string $options * @return string */ protected function getRouteAction($options) { if (is_array($options)) { return $this->url->route($options[0], array_slice($options, 1)); } return $this->url->route($options); }
/** * Return a named route if it exists. * * @param string $url * @param array $parameters * * @return string */ protected function parseUrl($url, $parameters) { // If provided $url is a route name... if ($this->route->has($url)) { $url = $this->url->route($url, $parameters); } else { $url = $this->url->to($url, $parameters); } return $url; }
/** * Get the URL to a named route. * * @param string $name * @param mixed $parameters * @param bool $absolute * @param \Illuminate\Routing\Route $route * @return string * * @throws \InvalidArgumentException */ public function route($name, $parameters = array(), $absolute = true, $route = null) { if ($path = $this->getPathFinder()->toRouteName($name, $parameters)) { if ($absolute) { return $this->to($path); } return $path; } return parent::route($name, $parameters, $absolute, $route); }
/** * Get the action type from the options. * * @param array $options * @return string */ public function dispatch($options) { if (isset($options['url'])) { return $this->getUrl($options); } elseif (isset($options['route'])) { return $this->url->route($options['route']); } elseif (isset($options['action'])) { return $this->url->action($options['action']); } return null; }
/** * Get a URL for a given page number. * * @param integer $page * @return string */ public function getUrl($page) { if (null === $this->routeConfig) { return parent::getUrl($page); } $parameters = $this->routeConfig['parameters']; if (true === $this->withQuery) { $parameters = array_merge($parameters, $this->factory->getRequest()->query()); } $parameters[$this->factory->getPageName()] = $page; $absolute = null === $this->routeConfig['absolute'] ? true : $this->routeConfig['absolute']; // allow adding hash fragments to url $fragment = $this->buildFragment(); $generated_route = $this->urlGenerator->route($this->routeConfig['name'], $parameters, $absolute, $this->routeConfig['instance']); return $generated_route . $fragment; }
/** * Get the link that can be used to automatically login a user to the * application. * * @param \Illuminate\Auth\UserInterface $user * @param string $path * @return string */ protected function getAutologinLink(UserInterface $user, $path = null) { // If we are supposed to remove expired tokens, let's do it now. if (config('autologin.remove_expired')) { $this->deleteExpiredTokens(); } // Get the user ID to be associated with a token. $userId = $user->getAuthIdentifier(); // Generate a random unique token that can be used for the link. $token = $this->getAutologinToken(); // Save the token to storage. $this->provider->create(['user_id' => $userId, 'token' => $token, 'path' => $path]); // Return a link using the route from the configuration file and // the generated token. $routeName = config('autologin.route_name'); return $this->generator->route($routeName, $token); }
/** * @param string $method * @param array $parameters * @throws MethodNotFoundException */ public function __call($method, $parameters) { if (preg_match('/^routeTo(?<routeName>[a-zA-Z]+)$/', $method, $matches)) { $route = Str::camel($matches['routeName']); while (count($parameters) < 2) { $parameters[] = []; } if (!is_array($parameters[1])) { $parameters[1] = [$parameters[1]]; } $routeParameters = $parameters[1]; array_unshift($routeParameters, $parameters[0]); return $this->urlGenerator->route($this->routePrefix . '.table.' . $route, $routeParameters); } if (method_exists($this->laravelRouter, $method)) { return $this->laravelRouter->group(['prefix' => $this->prefix, 'before' => $this->getBeforeFilters()], function () use($method, $parameters) { call_user_func_array([$this->laravelRouter, $method], $parameters); }); } throw new MethodNotFoundException(get_class($this), $method); }
/** * @todo - run this to ensure it generates the correct routes * @param $name * @param array $parameters * @param $referenceType * @return string */ public function generate($name, $parameters = array(), $referenceType = self::ABSOLUTE_PATH) { $refType = $referenceType === self::ABSOLUTE_PATH; return $this->urlGenerator->route($name, $parameters, $refType); }
function it_implements_routes_with_dynamic_parameters(UrlGenerator $url) { // Having $user_id = 20; $year = 2015; $month = 07; $day = 11; $account = "http://example.com/account/{$user_id}"; $calendar = "http://example.com/calendar/{$year}/{$month}/{$day}"; $url->current()->shouldBeCalled()->willReturn($account); $url->to('')->shouldBeCalled()->willReturn('http://example/'); $url->route('account', [$user_id])->shouldBeCalled()->willReturn($account); $url->route('calendar', [$year, $month, $day])->shouldBeCalled()->willReturn($calendar); // Generate new menu $menu = $this->make(['account' => ['route' => ['account', ':user_id']], 'calendar' => ['route' => ['calendar', ':year', ':month', ':day']]]); // With dynamic parameters $menu->setParams(compact('year', 'month', 'day')); $menu->setParam('user_id', $user_id); $items = ['account' => ['class' => 'active', 'submenu' => null, 'id' => 'account', 'active' => true, 'title' => 'Account', 'url' => $account], 'calendar' => ['class' => '', 'submenu' => null, 'id' => 'calendar', 'active' => false, 'title' => 'Calendar', 'url' => $calendar]]; $menu->getItems()->shouldReturn($items); }
/** * Custom action method * Get the URL to a controller action. * * @param string $action * @param mixed $parameters * @param bool $absolute * @return string */ public function action($action, $parameters = array(), $absolute = true) { ## ## Call url link modifier closure ## if (isset($action) && $action != '' && isset($this->url_modifiers[$action]) && is_callable($this->url_modifiers[$action])) { #\Helper::dd($parameters); $this->url_modifiers[$action]($action, $parameters); } return parent::route($action, $parameters, $absolute, $this->routes->getByAction($action)); }
public function route($name, $parameters = [], $absolute = true, $route = null, $locale = null) { $name = $this->getBestRouteName($name, $locale); return parent::route($name, $parameters, $absolute, $route); }
/** * Get the data for the given page. * * @param string $route * @param string $freq * @param string $priority * * @return array */ protected function getPage($route, $freq, $priority) { $url = $this->url->route($route); return compact('url', 'freq', 'priority'); }
/** * Queue up and dispatch a new request to a route name or action. * * @param \Dingo\Api\Routing\Route $route * @param string $name * @param string|array $parameters * @param string|array $requestParameters * * @return mixed */ protected function queueRouteOrActionRequest($route, $name, $parameters, $requestParameters) { $uri = ltrim($this->url->route($name, $parameters, false, $route), '/'); return $this->queueRequest($route->methods()[0], $uri, $requestParameters); }
/** * Create a new redirect response to a named route. * * @param string $route * @param array $parameters * @param int $status * @param array $headers * @return \Illuminate\Http\RedirectResponse */ public function route($route, $parameters = [], $status = 302, $headers = []) { $path = $this->generator->route($route, $parameters); return $this->to($path, $status, $headers); }
/** * Generate a HTML link to a named route. * * @param string $name * @param string $title * @param array $parameters * @param array $attributes * @return string */ public function linkRoute($name, $title = null, $parameters = array(), $attributes = array()) { return $this->link($this->url->route($name, $parameters), $title, $attributes); }
/** * Generate a HTML link to a route * * An array of parameters may be specified to fill in URI segment wildcards. * * @param string $name * @param string $title * @param array $parameters * @param array $attributes * @return string */ public function route($name, $title = null, $parameters = array(), $attributes = array(), $absolute = true) { return $this->to($this->url->route($name, $parameters, $absolute), $title, $attributes); }
/** * Get the URL to a named route. * * @param string $name * @param mixed $parameters * @param bool $absolute * @return string * @throws \InvalidArgumentException * @static */ public static function route($name, $parameters = array(), $absolute = true) { return \Illuminate\Routing\UrlGenerator::route($name, $parameters, $absolute); }
/** * Get the URL to a named route. * * @param string $name * @param mixed $parameters * @param bool $absolute * @return string * * @throws \InvalidArgumentException */ public function route($name, $parameters = [], $absolute = true) { $route = parent::route($name, $parameters, $absolute); if (!array_filter($parameters)) { $route = trim($route, '?'); } return $route; }