コード例 #1
0
 /**
  * Guess the HREF for a button.
  *
  * @param ControlPanelBuilder $builder
  */
 public function guess(ControlPanelBuilder $builder)
 {
     $buttons = $builder->getButtons();
     $sections = $builder->getControlPanelSections();
     $active = $sections->active();
     $module = $this->modules->active();
     foreach ($buttons as &$button) {
         // If we already have an HREF then skip it.
         if (isset($button['attributes']['href'])) {
             continue;
         }
         // Determine the HREF based on the button type.
         switch (array_get($button, 'button')) {
             case 'add':
             case 'new':
             case 'create':
                 $button['attributes']['href'] = $active->getHref('create');
                 break;
             case 'export':
                 if ($module) {
                     $button['attributes']['href'] = $this->url->to('entry/handle/export/' . $module->getNamespace() . '/' . array_get($button, 'namespace') . '/' . array_get($button, 'stream'));
                 }
                 break;
         }
         $type = array_get($button, 'segment', array_get($button, 'button'));
         if (!isset($button['attributes']['href']) && $type) {
             $button['attributes']['href'] = $active->getHref($type);
         }
     }
     $builder->setButtons($buttons);
 }
コード例 #2
0
 /**
  * Map the redirect routes.
  *
  * @param UrlGenerator                $url
  * @param Router                      $router
  * @param Request                     $request
  * @param RedirectRepositoryInterface $redirects
  * @internal param Filesystem $files
  * @internal param Application $application
  */
 public function map(UrlGenerator $url, Router $router, Request $request, RedirectRepositoryInterface $redirects)
 {
     if ($request->segment(1) == 'admin') {
         return;
     }
     /* @var RedirectInterface $redirect */
     foreach ($redirects->sorted() as $redirect) {
         if (!starts_with($parsed = $redirect->getFrom(), ['http://', 'https://', '//'])) {
             $parsed = $url->to($redirect->getFrom());
         }
         $parsed = parse_url(preg_replace_callback("/\\{[a-z]+\\?\\}/", function ($matches) {
             return str_replace('?', '!', $matches[0]);
         }, $parsed));
         if (isset($parsed['host']) && $parsed['host'] == $request->getHost()) {
             /**
              * Route a domain redirect in a domain group.
              */
             $router->group(['domain' => $parsed['host']], function () use($parsed, $router, $redirect) {
                 $path = ltrim(preg_replace_callback("/\\{[a-z]+\\!\\}/", function ($matches) {
                     return str_replace('!', '?', $matches[0]);
                 }, $parsed['path']), '/');
                 $router->any($path ?: '/', ['uses' => 'Anomaly\\RedirectsModule\\Http\\Controller\\RedirectsController@handle', 'redirect' => $redirect->getId()])->where(['any' => '(.*)', 'path' => '(.*)']);
             });
         } else {
             /**
              * Route a standard redirect.
              */
             $router->any($redirect->getFrom(), ['uses' => 'Anomaly\\RedirectsModule\\Http\\Controller\\RedirectsController@handle', 'redirect' => $redirect->getId()])->where(['any' => '(.*)', 'path' => '(.*)']);
         }
     }
 }
コード例 #3
0
 /**
  * {@inheritdoc}
  */
 public function url($path, $absolute = true)
 {
     if ($absolute === false) {
         return $path;
     }
     return $this->urlGenerator->to($path);
 }
コード例 #4
0
 /**
  * Get the URL to a named route.
  *
  * @param  string  $name
  * @param  mixed  $parameters
  * @param  bool  $absolute
  * @return string
  */
 public function route($name, $parameters = [], $absolute = true)
 {
     if ($this->isCurrentLocaleDefault()) {
         return $this->url->route($name, $parameters, $absolute);
     }
     $name = $this->config->get('app.locale') . '.' . $name;
     return $this->url->route($name, $parameters, $absolute);
 }
コード例 #5
0
 /**
  * Create a new Redirect response.
  *
  * @param RedirectInterface $redirect
  * @return \Illuminate\Http\RedirectResponse
  */
 public function create(RedirectInterface $redirect)
 {
     $parameters = array_merge(array_map(function () {
         return null;
     }, array_flip($this->route->parameterNames())), $this->route->parameters());
     if (!starts_with($url = $redirect->getTo(), ['http://', 'https://', '//'])) {
         $url = $this->url->to($redirect->getTo(), [], $redirect->isSecure());
     }
     return $this->redirector->to(rtrim($this->parser->parse($url, $parameters), '/'), $redirect->getStatus());
 }
コード例 #6
0
ファイル: Menu.php プロジェクト: larabros/laranav
 /**
  * Create a new `Menu` instance.
  *
  * @param string       $name
  * @param array        $items
  * @param array        $config
  * @param UrlGenerator $generator
  * @param Factory      $viewFactory
  */
 public function __construct($name, array $items, array $config, UrlGenerator $generator, Factory $viewFactory)
 {
     $this->name = $name;
     $this->config = $config;
     $this->request = $generator->getRequest();
     $this->generator = $generator;
     $this->viewFactory = $viewFactory;
     // Has to be done after other dependencies are set
     $this->items = new Collection($this->createItems($items));
 }
コード例 #7
0
 /**
  * Should be able to get the view href for a viewable object.
  */
 public function testViewHrefFor()
 {
     /** @var Viewable|MockObject $viewable */
     $viewable = $this->makeMock(Viewable::class);
     $viewable->expects($this->atLeastOnce())->method('routePrefix');
     $viewable->expects($this->atLeastOnce())->method('locationParts');
     $this->urlGenerator->expects($this->atLeastOnce())->method('route')->willReturn($this->generator()->anySlug());
     $viewHref = $this->locationComposer->viewHrefFor($viewable);
     $this->assertInternalType('string', $viewHref);
 }
コード例 #8
0
 /**
  * Build documentation URL.
  *
  * @param  array  $documentation
  *
  * @return array
  */
 protected function buildDocumentationUrl(array $documentation)
 {
     $current = $this->request->segment(2);
     foreach ($documentation as $doc) {
         $code = $doc->getCode();
         if ($code !== $current && $this->foundation->is('app::docs*')) {
             $doc->setURL(strtr($this->urlGenerator->current(), [$current => $code]));
         }
     }
     return $documentation;
 }
コード例 #9
0
 /**
  * index.
  *
  * @param \Illuminate\Contracts\Foundation\Application $app
  * @param \Recca0120\Terminal\Kernel                   $kernel
  * @param \Illuminate\Http\Request                     $request
  * @param \Illuminate\Contracts\Response\Factory       $responseFactory
  * @param \Illuminate\Contracts\Routing\UrlGenerator   $urlGenerator
  * @param string                                       $view
  *
  * @return mixed
  */
 public function index(Application $app, Kernel $kernel, Request $request, ResponseFactory $responseFactory, UrlGenerator $urlGenerator, $view = 'index')
 {
     $kernel->call('--ansi');
     $csrfToken = null;
     if ($request->hasSession() === true) {
         $csrfToken = $request->session()->token();
     }
     $options = json_encode(['csrfToken' => $csrfToken, 'username' => 'LARAVEL', 'hostname' => php_uname('n'), 'os' => PHP_OS, 'basePath' => $app->basePath(), 'environment' => $app->environment(), 'version' => $app->version(), 'endpoint' => $urlGenerator->action('\\' . static::class . '@endpoint'), 'helpInfo' => $kernel->output(), 'interpreters' => ['mysql' => 'mysql', 'artisan tinker' => 'tinker', 'tinker' => 'tinker'], 'confirmToProceed' => ['artisan' => ['migrate', 'migrate:install', 'migrate:refresh', 'migrate:reset', 'migrate:rollback', 'db:seed']]]);
     $id = $view === 'panel' ? Str::random(30) : null;
     return $responseFactory->view('terminal::' . $view, compact('options', 'resources', 'id'));
 }
コード例 #10
0
ファイル: Html.php プロジェクト: huglester/streams-platform
 /**
  * Get the action for an "action" option.
  *
  * @param array|string $options
  *
  * @return string
  */
 protected function getControllerAction($options)
 {
     if (is_array($options)) {
         return $this->url->action($options[0], array_slice($options, 1));
     }
     return $this->url->action($options);
 }
コード例 #11
0
 /**
  * Generate a page URL, based on the request's current URL.
  *
  * @param int  $page
  * @param bool $full Return the full version of the URL in for the first page
  *                   Ex. /users/page/1 instead of /users
  *
  * @return string
  */
 public function pageUrl($page, $full = false)
 {
     $currentPageUrl = $this->router->getCurrentRoute()->getUri();
     $url = $this->addPageQuery(str_replace('{pageQuery?}', '', $currentPageUrl), $page, $full);
     foreach ($this->router->getCurrentRoute()->bindParameters(app('request')) as $parameterName => $parameterValue) {
         $url = str_replace(['{' . $parameterName . '}', '{' . $parameterName . '?}'], $parameterValue, $url);
     }
     return $this->urlGenerator->to($url);
 }
コード例 #12
0
 /**
  * Should use the update route with an ID for an existing resource.
  */
 public function testPersistActionForExistingResource()
 {
     $existingCrud = $this->makeMockCrudResource();
     $existingCrud->shouldReceive('isStored')->andReturn(true);
     $routePath = $this->generator()->anyString();
     $existingCrud->shouldReceive('routePath')->andReturn($routePath);
     $crudID = $this->generator()->anyInteger();
     $existingCrud->shouldReceive('crudId')->andReturn($crudID);
     $URL = $this->generator()->anyString();
     $this->urlGenerator->shouldReceive('route')->with("{$routePath}.update", $crudID)->andReturn($URL);
     $this->assertSame($URL, $this->locationComposer->persistActionFor($existingCrud));
 }
コード例 #13
0
ファイル: Navigation.php プロジェクト: ssomenzi/silence
 /**
  * Convert slugs to urls.
  *
  * @param array $nav
  *
  * @return array
  */
 protected function process(array $nav)
 {
     // convert slugs to urls
     foreach ($nav as $key => $value) {
         // if the url is not set
         if (!isset($value['url'])) {
             // set the url based on the slug
             $nav[$key]['url'] = $this->url->to($value['slug']);
         }
         // remove any remaining slugs
         unset($nav[$key]['slug']);
     }
     // spit out the nav bar array at the end
     return $nav;
 }
コード例 #14
0
 /**
  * Get the previous page url
  * 
  * @param  bool $full  Return the full version of the url in for the first page
  *                     Ex. /users/page/1 instead of /users
  * @return string|null
  */
 public function previousPageUrl($full = false)
 {
     $previousPage = $this->previousPage();
     if ($previousPage === null) {
         return null;
     }
     // This should call the current action with a different parameter
     // Afaik there's no cleaner way to do this
     $currentPageUrl = new String($this->router->getCurrentRoute()->getUri());
     if ($previousPage === 1 && !$full) {
         $previousPageUrl = $currentPageUrl->replaceLast($this->pageName . '/{page}', '');
     } else {
         $previousPageUrl = $currentPageUrl->replaceLast('{page}', $previousPage);
     }
     return $this->urlGenerator->to($previousPageUrl);
 }
コード例 #15
0
ファイル: Menu.php プロジェクト: phroggyy/html
 /**
  * Generates the menu item URL, using any of the following options, in order:
  *
  * If you pass a 'full_url' key within the item configuration, in that case
  * it will return it as the URL with no additional action.
  *
  * If you pass a 'url' key then it will call the Url::to method to complete
  * the base URL, you can also specify a 'secure' key to indicate whether
  * this URL should be secure or not. Otherwise the defaultSecure option will
  * be used.
  *
  * If you pass a 'route' key then it will call the getRouteAndParameters to
  * return the route's name and its parameters, then it will call Url::route
  *
  * If you pass an 'action' key it'd be processed in a similar way as the
  * route key, but calling the Url::action method instead.
  *
  * If none of these options are found then this function will simple return
  * a placeholder (#).
  *
  *
  * @param $values
  * @return mixed
  */
 protected function generateUrl($values)
 {
     if (isset($values['full_url'])) {
         return $values['full_url'];
     }
     if (isset($values['url'])) {
         $isSecure = isset($values['secure']) ? $values['secure'] : $this->defaultSecure;
         return $this->url->to($values['url'], $isSecure);
     }
     if (isset($values['route'])) {
         list($route, $params) = $this->getRouteAndParameters($values['route']);
         return $this->url->route($route, $params);
     }
     if (isset($values['action'])) {
         list($route, $params) = $this->getRouteAndParameters($values['action']);
         return $this->url->action($route, $params);
     }
     return '#';
 }
コード例 #16
0
ファイル: Metadata.php プロジェクト: arrounded/metadata
 /**
  * Renders the metadata.
  *
  * @param array $attributes
  *
  * @return string
  */
 public function render(array $attributes = [])
 {
     $html = '';
     // Add some default options
     $attributes = array_merge(['card' => 'summary', 'site' => $this->project, 'url' => $this->url->current()], $this->metadata, $attributes);
     // Format URLs if provided
     $image = array_get($attributes, 'image');
     if (!file_exists($this->publicFolder . $image) || strpos($image, 'placeholder') !== false) {
         $image = $this->getPlaceholderIllustration();
     }
     $attributes['image'] = $this->url->asset($image);
     // Get Twitter equivalents
     $twitterProperties = ['name' => 'title', 'image' => 'image:src'];
     // Append attributes
     foreach ($attributes as $name => $value) {
         $twitter = array_get($twitterProperties, $name, $name);
         $html .= $this->getWrapper($twitter, $name, $value) . PHP_EOL;
     }
     return $html;
 }
コード例 #17
0
 /**
  * Return a URL.
  *
  * @param null  $path
  * @param array $parameters
  * @param null  $secure
  * @return string
  */
 public function url($path = null, $parameters = [], $secure = null)
 {
     return $this->url->to($path, $parameters, $secure);
 }
コード例 #18
0
ファイル: LocaleUrl.php プロジェクト: thinktomorrow/locale
 /**
  * Generate route via illuminate
  *
  * @param $name
  * @param array $parameters
  * @param bool $absolute
  * @return string
  */
 private function resolveRoute($name, $parameters = [], $absolute = true)
 {
     return $this->generator->route($name, $parameters, $absolute);
 }
コード例 #19
0
ファイル: LaravelFacebookSdk.php プロジェクト: SAEMA/project
 /**
  * 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);
 }
コード例 #20
0
 /**
  * generateUrl.
  *
  * @method generateUrl
  *
  * @param string $path
  * @param array  $parameters
  *
  * @return string
  */
 protected function generateUrl($path, array $parameters = [])
 {
     return $this->urlGenerator->route($path, $parameters);
 }
コード例 #21
0
ファイル: UrlGenerator.php プロジェクト: fluxbb/core
 protected function getUrlToPath($path)
 {
     return $this->generator->route('fluxbb', ['url' => $path]);
 }
コード例 #22
0
ファイル: HtmlBuilder.php プロジェクト: stevebauman/html
 /**
  * Generate a HTML link to a controller action.
  *
  * @param  string  $action
  * @param  string  $title
  * @param  array   $parameters
  * @param  array   $attributes
  *
  * @return string
  */
 public function linkAction($action, $title = null, $parameters = [], $attributes = [])
 {
     return $this->link($this->url->action($action, $parameters), $title, $attributes);
 }
コード例 #23
0
 /**
  * Returns the current Url
  *
  **/
 public function currentUrl()
 {
     return $this->urlGenerator->to($this->request->getPathInfo());
 }
コード例 #24
0
 /**
  * Get a JSON API link to a named route within your application.
  *
  * @param $name
  * @param array $parameters
  * @param array|object|null
  *      meta to attach to the link object.
  * @return LinkInterface
  */
 public function route($name, $parameters = [], $meta = null)
 {
     $uri = $this->generator->route($name, $parameters);
     return new Link($uri, $meta, true);
 }
コード例 #25
0
ファイル: Navigation.php プロジェクト: inoplate/navigation
 /**
  * Normalize route to url
  * 
  * @param  string $url
  * @return string
  */
 protected function normalize($url)
 {
     return $this->route->has($url) ? $this->url->route($url) : $url;
 }
コード例 #26
0
 /**
  * Get static option data for the editor
  *
  * @return array
  */
 protected function getStaticOption()
 {
     $routeParam = ['instanceId' => $this->instanceId];
     return ['fileUpload' => ['upload_url' => $this->urls->route('editor.file.upload', $routeParam), 'source_url' => $this->urls->route('editor.file.source', $routeParam), 'download_url' => $this->urls->route('editor.file.download', $routeParam), 'destroy_url' => $this->urls->route('editor.file.destroy', $routeParam)], 'suggestion' => ['hashtag_api' => $this->urls->route('editor.hashTag'), 'mention_api' => $this->urls->route('editor.mention')], 'names' => ['file' => ['input' => $this->getFileInputName(), 'class' => $this->getFileClassName(), 'identifier' => $this->getFileIdentifierAttrName(), 'image' => ['class' => $this->getImageClassName(), 'identifier' => $this->getImageIdentifierAttrName()]], 'tag' => ['input' => $this->getTagInputName(), 'class' => $this->getTagClassName()], 'mention' => ['input' => $this->getMentionInputName(), 'class' => $this->getMentionClassName(), 'identifier' => $this->getMentionIdentifierAttrName()]]];
 }
コード例 #27
0
 /**
  * @param Viewable $viewable
  *
  * @throws \InvalidArgumentException
  *
  * @return string
  */
 public function viewHrefFor(Viewable $viewable) : string
 {
     return $this->urlGenerator->route($viewable->routePrefix() . self::ROUTE_VIEW, $viewable->locationParts());
 }
コード例 #28
0
 /**
  * Get the current URL for the request.
  *
  * @return string
  */
 public function current()
 {
     return $this->url->current();
 }
コード例 #29
0
 /**
  * Called before routes are registered.
  *
  * Register any model bindings or pattern based filters.
  *
  * @param  UrlGenerator  $url
  * @return void
  */
 public function before(UrlGenerator $url)
 {
     $url->setRootControllerNamespace(trim(config('namespaces.controllers'), '\\'));
 }
コード例 #30
0
 /**
  * Called before routes are registered.
  *
  * Register any model bindings or pattern based filters.
  *
  * @param  Router  $router
  * @param  UrlGenerator  $url
  * @return void
  */
 public function before(Router $router, UrlGenerator $url)
 {
     $url->setRootControllerNamespace('App\\Http\\Controllers');
 }