コード例 #1
0
ファイル: AlphaBrowse.php プロジェクト: datavoyager/vufind
 /**
  * Get link to browse results (or null if no valid URL available)
  *
  * @param string $source AlphaBrowse index currently being used
  * @param array  $item   Item to link to
  *
  * @return string
  */
 public function getUrl($source, $item)
 {
     if ($item['count'] <= 0) {
         return null;
     }
     // Linking using bib ids is generally more reliable than doing searches for
     // headings, but headings give shorter queries and don't look as strange.
     if ($item['count'] < 5) {
         $safeIds = array_map([$this, 'escapeForSolr'], $item['ids']);
         $query = ['type' => 'ids', 'lookfor' => implode(' ', $safeIds)];
         if ($item['count'] == 1) {
             $query['jumpto'] = 1;
         }
     } else {
         $query = ['type' => ucwords($source) . 'Browse', 'lookfor' => $this->escapeForSolr($item['heading'])];
     }
     return $this->url->__invoke('search-results', [], ['query' => $query]);
 }
コード例 #2
0
ファイル: SearchTabs.php プロジェクト: tillk/vufind
 /**
  * Create information representing an advanced search tab.
  *
  * @param string $class Search class ID
  * @param string $label Display text for tab
  *
  * @return array
  */
 protected function createAdvancedTab($class, $label)
 {
     // If an advanced search is available, link there; otherwise, just go
     // to the search home:
     $options = $this->results->get($class)->getOptions();
     $advSearch = $options->getAdvancedSearchAction();
     $url = $this->url->__invoke($advSearch ? $advSearch : $options->getSearchHomeAction());
     return ['class' => $class, 'label' => $label, 'selected' => false, 'url' => $url];
 }
コード例 #3
0
ファイル: UrlHelper.php プロジェクト: jakubigla/zf-locale
 /**
  * Generates a url given the name of a route.
  *
  * @see    Zend\Mvc\Router\RouteInterface::assemble()
  * @param  string               $name               Name of the route
  * @param  array                $params             Parameters for the link
  * @param  array|\Traversable    $options            Options for the route
  * @param  bool                 $reuseMatchedParams Whether to reuse matched parameters
  * @return string Url                         For the link href attribute
  * @throws Exception\RuntimeException         If no RouteStackInterface was provided
  * @throws Exception\RuntimeException         If no RouteMatch was provided
  * @throws Exception\RuntimeException         If RouteMatch didn't contain a matched route name
  * @throws Exception\InvalidArgumentException If the params object was not an array or \Traversable object
  */
 public function __invoke($name = null, $params = [], $options = [], $reuseMatchedParams = false)
 {
     $url = parent::__invoke($name, $params, $options, $reuseMatchedParams);
     $locale = $this->moduleOptions->getCurrentLocale();
     if (isset($params['locale'])) {
         $locale = $params['locale'];
     }
     $url = '/' . $locale . $url;
     return $url;
 }
コード例 #4
0
 /**
  * Generate URL to given controller and action
  *
  * @param string $controller Optional controller name (default: current controller)
  * @param string $action Optional action name (default: current action)
  * @param array $params Optional associative array of query parameters
  * @param bool $inheritParams Include request query parameters. Parameters in $params take precedence.
  * @return string Target URL
  */
 public function __invoke($controller = null, $action = null, $params = array(), $inheritParams = false)
 {
     $route = array();
     if ($controller) {
         $route['controller'] = $controller;
     }
     if ($action) {
         $route['action'] = $action;
     }
     if ($inheritParams and $this->_request instanceof \Zend\Http\Request) {
         // Merge current request parameters (parameters from $params take precedence)
         $params = array_merge($this->_request->getQuery()->toArray(), $params);
     }
     $options = array();
     if (!empty($params)) {
         // Cast values to string to support values that would otherwise get
         // ignored by Url helper, like objects implementing __toString()
         foreach ($params as $name => $value) {
             $options['query'][$name] = (string) $value;
         }
     }
     return $this->_url->__invoke('console', $route, $options, true);
 }
コード例 #5
0
ファイル: QueryUrl.php プロジェクト: sitrunlab/learnzf2
 public function __invoke($name = null, $params = [], $options = [], $reuseMatchedParams = false)
 {
     if (null === $this->router) {
         throw new Exception\RuntimeException('No RouteStackInterface instance provided');
     }
     if (3 === func_num_args() && is_bool($options)) {
         $reuseMatchedParams = $options;
         $options = [];
     }
     // Inherit query parameters
     if ($reuseMatchedParams) {
         $providedQueryParams = isset($options['query']) ? $options['query'] : [];
         $currentQueryParams = $this->request->getQuery()->toArray();
         $options['query'] = array_merge($currentQueryParams, $providedQueryParams);
     }
     return parent::__invoke($name, $params, $options, $reuseMatchedParams);
 }
コード例 #6
0
ファイル: Url.php プロジェクト: sebaks/Translate
 public function __invoke($name = null, $params = [], $options = [], $reuseMatchedParams = false)
 {
     $uri = parent::__invoke($name, $params, $options, $reuseMatchedParams);
     if (false !== strpos($uri, '/admin')) {
         return $uri;
     }
     if (isset($params['locale'])) {
         $code = $params['locale'];
     } else {
         $locale = $this->translator->getLocale();
         $code = preg_replace('/\\_.*/', '', $locale);
     }
     $array = explode('/', $uri);
     $array = array_diff($array, ['']);
     array_unshift($array, $code);
     $uri = '/' . implode('/', $array);
     return $uri;
 }
コード例 #7
0
ファイル: Url.php プロジェクト: andreas-serlo/athene2
 public function __invoke($name = null, $params = [], $options = [], $reuseMatchedParams = false, $useAlias = true)
 {
     $useCanonical = isset($options['force_canonical']) && $options['force_canonical'];
     $link = parent::__invoke($name, $params, $options, $reuseMatchedParams);
     if (!$useAlias) {
         return $link;
     }
     try {
         $aliasManager = $this->getAliasManager();
         $instance = $this->getInstanceManager()->getInstanceFromRequest();
         if ($useCanonical) {
             $options['force_canonical'] = false;
             $source = parent::__invoke($name, $params, $options, $reuseMatchedParams);
             $link = $aliasManager->findAliasBySource($source, $instance);
             return $this->getView()->serverUrl($link);
         }
         $link = $aliasManager->findAliasBySource($link, $instance);
     } catch (AliasNotFoundException $e) {
         // No alias was found -> nothing to do
     }
     return $link;
 }
コード例 #8
0
ファイル: UrlTest.php プロジェクト: nieldm/zf2
 public function testRemovesModuleRouteListenerParamsWhenReusingMatchedParameters()
 {
     $router = new \Zend\Mvc\Router\Http\TreeRouteStack();
     $router->addRoute('default', array('type' => 'Zend\\Mvc\\Router\\Http\\Segment', 'options' => array('route' => '/:controller/:action', 'defaults' => array(ModuleRouteListener::MODULE_NAMESPACE => 'ZendTest\\Mvc\\Controller\\TestAsset', 'controller' => 'SampleController', 'action' => 'Dash')), 'child_routes' => array('wildcard' => array('type' => 'Zend\\Mvc\\Router\\Http\\Wildcard', 'options' => array('param_delimiter' => '=', 'key_value_delimiter' => '%')))));
     $routeMatch = new RouteMatch(array(ModuleRouteListener::MODULE_NAMESPACE => 'ZendTest\\Mvc\\Controller\\TestAsset', 'controller' => 'Rainbow'));
     $routeMatch->setMatchedRouteName('default/wildcard');
     $event = new MvcEvent();
     $event->setRouter($router)->setRouteMatch($routeMatch);
     $moduleRouteListener = new ModuleRouteListener();
     $moduleRouteListener->onRoute($event);
     $helper = new UrlHelper();
     $helper->setRouter($router);
     $helper->setRouteMatch($routeMatch);
     $url = $helper->__invoke('default/wildcard', array('Twenty' => 'Cooler'), true);
     $this->assertEquals('/Rainbow/Dash=Twenty%Cooler', $url);
 }