to() public method

Generate an absolute URL to the given path.
public to ( string $path, mixed $extra = [], boolean | null $secure = null ) : string
$path string
$extra mixed
$secure boolean | null
return string
Ejemplo n.º 1
2
 public function withBrand($brand, $link = null)
 {
     if (!isset($link)) {
         $link = $this->url->to('/');
     }
     $this->brand = compact('brand', 'link');
     return $this;
 }
Ejemplo n.º 2
2
 protected function getHomeUrl()
 {
     // wrap in value() to allow closures
     $enableHomeLink = value($this->config->get('c::enable-home-link', false));
     if ($enableHomeLink) {
         $url = $this->config->get('c::redirect-login', '/');
         return $this->url->to($url);
     }
     return null;
 }
Ejemplo n.º 3
1
 /**
  * Guess the HREF for a button.
  *
  * @param TableBuilder $builder
  */
 public function guess(TableBuilder $builder)
 {
     $buttons = $builder->getButtons();
     if (!($section = $this->sections->active())) {
         return;
     }
     if (!($module = $this->modules->active())) {
         return;
     }
     $stream = $builder->getTableStream();
     foreach ($buttons as &$button) {
         // If we already have an HREF then skip it.
         if (isset($button['attributes']['href'])) {
             continue;
         }
         switch (array_get($button, 'button')) {
             case 'restore':
                 $button['attributes']['href'] = $this->url->to('entry/handle/restore/' . $module->getNamespace() . '/' . $stream->getNamespace() . '/' . $stream->getSlug() . '/{entry.id}');
                 break;
             default:
                 // Determine the HREF based on the button type.
                 $type = array_get($button, 'segment', array_get($button, 'button'));
                 if ($type && !str_contains($type, '\\') && !class_exists($type)) {
                     $button['attributes']['href'] = $section->getHref($type . '/{entry.id}');
                 }
                 break;
         }
     }
     $builder->setButtons($buttons);
 }
Ejemplo n.º 4
1
 /**
  * Return the URL for the file.
  *
  * @param array $attributes
  * @param null  $secure
  * @return string
  */
 public function url(array $attributes = [], $secure = null)
 {
     if ($secure === null) {
         $secure = $this->request->isSecure();
     }
     return $this->url->to($this->object->publicPath(), $attributes, $secure);
 }
Ejemplo n.º 5
1
 public function filter(Route $route, Request $request)
 {
     if ($this->auth->check()) {
         $config = $this->config->get('c::redirect-login');
         $url = $config ? $this->url->to($config) : '/';
         return $this->redirect->to($url);
     }
 }
Ejemplo n.º 6
1
 /**
  * Generates a url for Sorter
  *
  * @param string $field
  * @param null|string $path
  * @param boolean $appends
  * */
 public function url($field, $path = null, $appends = true)
 {
     if ($path === null) {
         $path = $this->url->current();
     }
     $queryString = [$this->getFieldIndex() => $field, $this->getDirectionIndex() => $this->getConditionallyDirection($field)];
     $appends && ($queryString += $this->request->query());
     $url = $path . '?' . http_build_query($queryString);
     return $this->url->to($url);
 }
Ejemplo n.º 7
1
 /**
  * Guess the HREF for the views.
  *
  * @param TableBuilder $builder
  */
 public function guess(TableBuilder $builder)
 {
     $views = $builder->getViews();
     foreach ($views as &$view) {
         // Only automate it if not set.
         if (!isset($view['attributes']['href'])) {
             $view['attributes']['href'] = $this->url->to($this->request->path() . '?' . array_get($view, 'prefix') . 'view=' . $view['slug']);
         }
     }
     $builder->setViews($views);
 }
 function it_creates_image_links(UrlGenerator $url)
 {
     $url->to('/', null)->shouldBeCalled()->willReturn('localhost');
     $this->beConstructedWith($url);
     $html = '<a href="localhost"><img src="http://placehold.it/100x100.png" /></a>';
     $this->linkImage('/', '<img src="http://placehold.it/100x100.png" />')->shouldReturn($html);
 }
Ejemplo n.º 9
0
 public function url($path = null, $parameters = [], $secure = null)
 {
     if (!$path) {
         return $this->url;
     }
     return $this->url->to($path, $parameters, $secure);
 }
 /**
  * @param $request
  * @param \Closure $next
  * @return \Illuminate\Http\RedirectResponse
  */
 public function handle($request, Closure $next)
 {
     if ($this->auth->check()) {
         return new RedirectResponse(UrlGenerator::to('admin'));
     }
     return $next($request);
 }
Ejemplo n.º 11
0
 /**
  * Generate a absolute URL to the given path.
  *
  * @param  mixed  $path or SiteTreeNodeInterface Instance
  * @param  mixed  $extra
  * @param  bool  $secure
  * @return string
  */
 public function to($path, $extra = array(), $secure = null)
 {
     // Page object passed
     if (is_object($path) && $path instanceof SiteTreeNodeInterface) {
         if (starts_with($path->getPath(), 'http:')) {
             $path = $path->getPath();
         } else {
             $path = $this->getPathFinder()->toPage($path);
         }
     } elseif (is_string($path) && $this->pageTypes->has($path)) {
         $path = $this->getPathFinder()->toPageType($path);
     } elseif (is_string($path) && $this->currentCmsPathProvider->getCurrentCmsPath()->isCmsPath()) {
         if ($extra && !isset($extra[0])) {
             $extra = array_values($extra);
             $extraPath = implode('/', $extra);
             $path = trim($path, '/') . '/' . trim($extraPath, '/');
             $extra = [];
         }
         if ($path == '/' && $this->getTreeScope()) {
             $path = trim($this->getTreeScope()->getPathPrefix() . $path, '/');
         }
     } elseif ($path == '/' && ($treeScope = $this->getTreeScope())) {
         $path = trim($treeScope->getPathPrefix() . $path, '/');
     }
     return parent::to($path, $extra, $secure);
 }
Ejemplo n.º 12
0
 /**
  * Get the action for a "url" option.
  *
  * @param  array|string  $options
  * @return string
  */
 protected function getUrlAction($options)
 {
     if (is_array($options)) {
         return $this->url->to($options[0], array_slice($options, 1));
     }
     return $this->url->to($options);
 }
Ejemplo n.º 13
0
 /**
  * Guess the sections HREF attribute.
  *
  * @param ControlPanelBuilder $builder
  */
 public function guess(ControlPanelBuilder $builder)
 {
     $sections = $builder->getSections();
     foreach ($sections as $index => &$section) {
         // If HREF is set then skip it.
         if (isset($section['attributes']['href'])) {
             continue;
         }
         $module = $this->modules->active();
         $href = $this->url->to('admin/' . $module->getSlug());
         if ($index !== 0 && $module->getSlug() !== $section['slug']) {
             $href .= '/' . $section['slug'];
         }
         $section['attributes']['href'] = $href;
     }
     $builder->setSections($sections);
 }
Ejemplo n.º 14
0
 /**
  * Generate a HTML link.
  *
  * @param  string  $url
  * @param  string  $title
  * @param  array   $attributes
  * @param  bool    $secure
  * @return string
  */
 public function link($url, $title = null, $attributes = array(), $secure = null)
 {
     $url = $this->url->to($url, array(), $secure);
     if (is_null($title) || $title === false) {
         $title = $url;
     }
     return '<a href="' . $url . '"' . $this->attributes($attributes) . '>' . $this->entities($title) . '</a>';
 }
Ejemplo n.º 15
0
 /**
  * Generate an HTML image element.
  *
  * @param  string $url
  * @param  string $alt
  * @param  array  $attributes
  * @return string
  */
 public function image($url, $alt = null, $attributes = array())
 {
     if (is_null($alt)) {
         $alt = $url;
     }
     $attributes['alt'] = $alt;
     return '<img src="' . $this->url->to($url) . '"' . $this->attributes($attributes) . '>';
 }
Ejemplo n.º 16
0
 /**
  * Generate a absolute URL to the given path.
  *
  * @param  string  $path
  * @param  mixed   $parameters
  * @param  bool    $secure
  * @return string
  */
 public function to($path, $parameters = array(), $secure = null)
 {
     // If the given path is an object, we build a string path based on resource
     // controllers conventions
     if (is_object($path)) {
         $path = str_plural(snake_case(get_class($path))) . '/' . $path->getKey();
     }
     return parent::to($path, $parameters, $secure);
 }
Ejemplo n.º 17
0
 /**
  * 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;
 }
Ejemplo n.º 18
0
 /**
  * Get the action for a "url" option.
  *
  * @param  array|string  $options
  * @return string
  */
 protected function getUrl($options)
 {
     foreach ($options as $key => $value) {
         ${$key} = $value;
     }
     $secure = (isset($options['secure']) and $options['secure'] === true) ? true : false;
     if (is_array($url)) {
         if (self::isAbs($url[0])) {
             return $url[0];
         }
         return $this->url->to($prefix . '/' . $url[0], array_slice($url, 1), $secure);
     }
     if (self::isAbs($url)) {
         return $url;
     }
     return $this->url->to($prefix . '/' . $url, array(), $secure);
 }
Ejemplo n.º 19
0
 /**
  * Generate an absolute URL to the given path.
  *
  * @param  string  $path
  * @param  mixed  $extra
  * @param  bool|null  $secure
  * @return string
  */
 public function to($path, $extra = [], $secure = null)
 {
     if ($this->isValidUrl($path)) {
         return $path;
     }
     if (!strpos($path, '/rtlweb/rtler/assets/css/rtl.css')) {
         $backendUri = Config::get('cms.backendUri', 'backend');
         $requestUrl = Request::url();
         if (File::exists(base_path(dirname($path)) . '.rtl.' . File::extension($path))) {
             $path = dirname($path) . '.rtl.' . File::extension($path);
         } else {
             if (File::extension($path) == 'css' && (strpos($requestUrl, $backendUri) || strpos($path, 'plugins/') || strpos($path, 'modules/'))) {
                 $path = CssFlipper::flipCss($path);
             }
         }
     }
     return parent::to($path, $extra, $secure);
 }
Ejemplo n.º 20
0
 /**
  * Create a new internal request from an HTTP verb and URI.
  *
  * @param string       $verb
  * @param string       $uri
  * @param string|array $parameters
  *
  * @return \Dingo\Api\Http\InternalRequest
  */
 protected function createRequest($verb, $uri, $parameters)
 {
     if (!isset($this->version)) {
         $this->version = $this->properties->getVersion();
     }
     $api = $this->router->getApiGroups()->getByDomainOrVersion($this->domain, $this->version);
     if (($prefix = $api->option('prefix')) && !starts_with($uri, $prefix)) {
         $uri = sprintf('%s/%s', $prefix, $uri);
     }
     $parameters = array_merge($this->parameters, (array) $parameters);
     $request = InternalRequest::create($this->url->to($uri), $verb, $parameters, $this->cookies, $this->uploads, [], $this->content);
     if ($domain = $api->option('domain')) {
         $request->headers->set('host', $domain);
     }
     foreach ($this->headers as $header => $value) {
         $request->headers->set($header, $value);
     }
     $request->headers->set('accept', $this->buildAcceptHeader());
     return $request;
 }
Ejemplo n.º 21
0
 /**
  * Get the fallback callback redirect URL if none provided.
  *
  * @param string $callback_url
  *
  * @return string
  */
 private function getCallbackUrl($callback_url)
 {
     $callback_url = $callback_url ?: $this->config_handler->get('laravel-facebook-sdk.default_redirect_uri');
     return $this->url->to($callback_url);
 }
Ejemplo n.º 22
0
 /**
  * Create a new redirect response to the given path.
  *
  * @param  string  $path
  * @param  int     $status
  * @param  array   $headers
  * @param  bool    $secure
  * @return \Illuminate\Http\RedirectResponse
  */
 public function to($path, $status = 302, $headers = [], $secure = null)
 {
     $path = $this->generator->to($path, [], $secure);
     return $this->createRedirect($path, $status, $headers);
 }
Ejemplo n.º 23
0
 /**
  * Generate a link that will automatically login a user and then redirect 
  * them to a hard-coded path as generated by the URL
  * generator.
  *
  * @param  \Illuminate\Auth\UserInterface  $user
  * @param  string  $path
  * @param  mixed  $extra
  * @param  bool  $secure
  * @return string
  */
 public function to(UserInterface $user, $path, $extra = array(), $secure = null)
 {
     $path = $this->generator->to($path, $extra, $secure);
     return $this->getAutologinLink($user, $path);
 }
Ejemplo n.º 24
0
 public function asset($path, $secure = null)
 {
     return parent::to($this->rewrite_url($path), [], false);
 }
Ejemplo n.º 25
0
 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);
 }
Ejemplo n.º 26
0
 protected function getHomeUrl()
 {
     $path = $this->config->get('c::redirect-login', '/');
     return $this->url->to($path);
 }
Ejemplo n.º 27
0
 /**
  * Return true if current page is an admin home (main) page.
  */
 public function isAdminHome() : bool
 {
     return $this->url->current() == $this->url->to($this->config->get('helpers.paths.admin'));
 }
Ejemplo n.º 28
0
 /**
  * Creates a Link to the first page of a Resource Collection.
  *
  * Makes sense to have this ability when we would like to embed a link to a sub Resource Collection which should
  * be paginated due to the fact that it maybe contains tons of data, so this way we don't expose all the Collection,
  * sparing some server side resources.
  *
  * @param $rel
  * @return array
  */
 public function createLinkToFirstPage($rel)
 {
     $url = $this->url->to($this->request->url() . '/' . strtolower($rel) . $this->queryStringOps->setQueryStringParam($this->config->get('restext::page_param'), 1));
     return ['rel' => $rel, 'href' => $url];
 }
Ejemplo n.º 29
0
 /**
  * Generate an absolute URL to the given path.
  *
  * @param string $path
  * @param mixed $extra
  * @param bool|null $secure
  * @return string 
  * @static 
  */
 public static function to($path, $extra = array(), $secure = null)
 {
     return \Illuminate\Routing\UrlGenerator::to($path, $extra, $secure);
 }
Ejemplo n.º 30
0
 /**
  * Returns the URL for the relative URI.
  *
  * @param  string  $uri
  * @return string
  */
 public function getUrl($uri)
 {
     return $this->urlGenerator->to($this->removeWindowsSeparator($uri));
 }