コード例 #1
0
ファイル: Url.php プロジェクト: Baft/Zend-Form
 /**
  * Generates an 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   $options            Options for the route
  * @param  boolean $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
  */
 public function __invoke($name = null, array $params = array(), $options = array(), $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 = array();
     }
     if ($name === null) {
         if ($this->routeMatch === null) {
             throw new Exception\RuntimeException('No RouteMatch instance provided');
         }
         $name = $this->routeMatch->getMatchedRouteName();
         if ($name === null) {
             throw new Exception\RuntimeException('RouteMatch does not contain a matched route name');
         }
     }
     if ($reuseMatchedParams && $this->routeMatch !== null) {
         $routeMatchParams = $this->routeMatch->getParams();
         if (isset($routeMatchParams[ModuleRouteListener::ORIGINAL_CONTROLLER])) {
             $routeMatchParams['controller'] = $routeMatchParams[ModuleRouteListener::ORIGINAL_CONTROLLER];
             unset($routeMatchParams[ModuleRouteListener::ORIGINAL_CONTROLLER]);
         }
         if (isset($routeMatchParams[ModuleRouteListener::MODULE_NAMESPACE])) {
             unset($routeMatchParams[ModuleRouteListener::MODULE_NAMESPACE]);
         }
         $params = array_merge($routeMatchParams, $params);
     }
     $options['name'] = $name;
     return $this->router->assemble($params, $options);
 }
コード例 #2
0
ファイル: Url.php プロジェクト: joacub/libra-locale
 /**
  * Generates an 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 = array(), $options = array(), $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 = array();
     }
     if ($name === null) {
         if ($this->routeMatch === null) {
             throw new Exception\RuntimeException('No RouteMatch instance provided');
         }
         $name = $this->routeMatch->getMatchedRouteName();
         if ($name === null) {
             throw new Exception\RuntimeException('RouteMatch does not contain a matched route name');
         }
     }
     if (!is_array($params)) {
         if (!$params instanceof Traversable) {
             throw new Exception\InvalidArgumentException('Params is expected to be an array or a Traversable object');
         }
         $params = iterator_to_array($params);
     }
     if ($reuseMatchedParams && $this->routeMatch !== null) {
         $routeMatchParams = $this->routeMatch->getParams();
         if (isset($routeMatchParams[ModuleRouteListener::ORIGINAL_CONTROLLER])) {
             $routeMatchParams['controller'] = $routeMatchParams[ModuleRouteListener::ORIGINAL_CONTROLLER];
             unset($routeMatchParams[ModuleRouteListener::ORIGINAL_CONTROLLER]);
         }
         if (isset($routeMatchParams[ModuleRouteListener::MODULE_NAMESPACE])) {
             unset($routeMatchParams[ModuleRouteListener::MODULE_NAMESPACE]);
         }
         $params = array_merge($routeMatchParams, $params);
     } elseif ($this->routeMatch !== null) {
         // Set current locale if it presents
         $currentLocaleAlias = $this->routeMatch->getParam('locale') !== null ? $this->routeMatch->getParam('locale') : false;
         if (!array_key_exists('locale', $params) && $currentLocaleAlias) {
             $params['locale'] = $currentLocaleAlias;
         }
     }
     $options['name'] = $name;
     return $this->router->assemble($params, $options);
 }
コード例 #3
0
ファイル: Url.php プロジェクト: rafalwrzeszcz/zf2
 /**
  * Generates an url given the name of a route.
  *
  * @see    Zend\Mvc\Router\Route::assemble()
  * @param  string  $name               Name of the route
  * @param  array   $params             Parameters for the link
  * @param  array   $options            Options for the route
  * @param  boolean $reuseMatchedParams Whether to reuse matched parameters
  * @return string Url                  For the link href attribute
  * @throws Exception\RuntimeException  If no RouteStack was provided
  * @throws Exception\RuntimeException  If no RouteMatch was provided
  * @throws Exception\RuntimeException  If RouteMatch didn't contain a matched route name
  */
 public function __invoke($name = null, array $params = array(), array $options = array(), $reuseMatchedParams = false)
 {
     if (null === $this->router) {
         throw new Exception\RuntimeException('No RouteStack instance provided');
     }
     if ($name === null) {
         if ($this->routeMatch === null) {
             throw new Exception\RuntimeException('No RouteMatch instance provided');
         }
         $name = $this->routeMatch->getMatchedRouteName();
         if ($name === null) {
             throw new Exception\RuntimeException('RouteMatch does not contain a matched route name');
         }
     }
     if ($reuseMatchedParams && $this->routeMatch !== null) {
         $params = array_merge($this->routeMatch->getParams(), $params);
     }
     $options['name'] = $name;
     return $this->router->assemble($params, $options);
 }