/**
  * @param       $route
  * @param array $params
  * @param array $options
  *
  * @return string
  */
 public function buildRoute($route, $params = [], $options = [])
 {
     $params['hash'] = $this->config->getHash();
     $options['name'] = $route;
     $options['force_canonical'] = true;
     $options['uri'] = $this->uri;
     return $this->router->assemble($params, $options);
 }
 /**
  * @param string $method
  * @param string $url
  *
  * @return null|string
  */
 public function match($method, $url)
 {
     $request = new Request();
     $request->setMethod($method);
     $request->setUri($url);
     $routeMatch = $this->router->match($request);
     return $routeMatch instanceof RouteMatch ? $routeMatch->getMatchedRouteName() : null;
 }
Exemple #3
0
 /**
  * @param string $route
  * @param null $query
  * @return mixed
  * @throws \Zend\View\Exception\RuntimeException
  */
 public function __invoke($route, $query = null)
 {
     if (null === $this->router) {
         throw new Exception\RuntimeException('No RouteStackInterface instance provided');
     }
     $options = array('name' => $route, 'query' => $query);
     //
     return $this->router->assemble(array(), $options);
 }
Exemple #4
0
 /**
  * Set the router from the MVC framework
  * 
  * This will push the route paths into the request as parameters
  * 
  * @param RouteStack $router
  */
 public function setRouter(RouteStackInterface $router)
 {
     $this->router = $router;
     // now extract the route elements and set them as params
     $route_match = $router->match($this);
     if ($route_match instanceof RouteMatch) {
         foreach ($route_match->getParams() as $name => $value) {
             $this->setParam($name, $value);
         }
     }
 }
Exemple #5
0
 /**
  * @param $route
  * @param null $query
  * @return mixed
  * @throws \Zend\View\Exception\RuntimeException
  */
 public function __invoke($route, $params, $query = null)
 {
     if (null === $this->router) {
         throw new Exception\RuntimeException('No RouteStackInterface instance provided');
     }
     //
     $params = explode('/', $params);
     $routeParams = array('controller' => isset($params[0]) ? $params[0] : 'index', 'action' => isset($params[1]) ? $params[1] : 'index');
     $options = array('name' => $route, 'query' => $query);
     //
     return $this->router->assemble($routeParams, $options);
 }
Exemple #6
0
 /**
  *
  *
  * @param string $templateName
  * @param string $to
  * @param array $params
  * @return
  */
 public function __invoke($templateName, $to, array $params = array())
 {
     // set mail language if not given
     if (!isset($params['language']) && $this->translator) {
         $params['language'] = \Locale::getPrimaryLanguage($this->translator->getLocale());
     }
     // set root url if not given
     if (!isset($params['root_url']) && $this->router) {
         $params['root_url'] = rtrim($this->router->assemble(array('language' => $params['language']), array('name' => 'frontend/index')), '/');
     }
     //
     $params['to'] = $to;
     return $this->mailer->sendMail($templateName, $to, $params);
 }
Exemple #7
0
 /**
  * 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);
 }
 /**
  * Returns the assembled route as string
  * @param $message
  * @param null $extension
  * @param null $size
  * @param null $padding
  * @return mixed
  */
 public function assembleRoute($message, $extension = null, $size = null, $padding = null)
 {
     $params = array('message' => $message);
     if (isset($extension)) {
         $params['extension'] = $extension;
         if (isset($size)) {
             $params['size'] = $size;
             if (isset($padding)) {
                 $params['padding'] = $padding;
             }
         }
     }
     $this->routeOptions['name'] = 'acelaya-qrcode';
     return $this->router->assemble($params, $this->routeOptions);
 }
Exemple #9
0
 /**
  * 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);
 }
Exemple #10
0
 /**
  * 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(), array $options = array(), $reuseMatchedParams = false)
 {
     if (null === $this->router) {
         throw new Exception\RuntimeException('No RouteStackInterface 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);
 }
 /**
  * @test
  */
 public function it_should_be_able_to_build_routes()
 {
     $expected = 'http://localhost/path/to/route';
     $this->router->expects($this->any())->method('assemble')->with(['hash' => 'hash'], ['name' => 'route', 'force_canonical' => true, 'uri' => $this->uri])->will($this->returnValue($expected));
     $this->assertEquals($this->routeAssembler->buildRoute('route'), $expected);
 }