/** * {@inheritDoc} */ public function generateUri($name, array $substitutions = []) { if (!$this->zf2Router->hasRoute($name)) { throw new Exception\RuntimeException(sprintf('Cannot generate URI based on route "%s"; route not found', $name)); } $name = isset($this->routeNameMap[$name]) ? $this->routeNameMap[$name] : $name; $options = ['name' => $name, 'only_return_path' => true]; return $this->zf2Router->assemble($substitutions, $options); }
/** * assemble(): defined by \Zend\Mvc\Router\RouteInterface interface. * * @see \Zend\Mvc\Router\RouteInterface::assemble() * @param array $params * @param array $options * @return mixed * @throws Exception\InvalidArgumentException * @throws Exception\RuntimeException */ public function assemble(array $params = array(), array $options = array()) { if ($this->hasTranslator() && $this->isTranslatorEnabled() && !isset($options['translator'])) { $options['translator'] = $this->getTranslator(); } if (!isset($options['text_domain'])) { $options['text_domain'] = $this->getTranslatorTextDomain(); } return parent::assemble($params, $options); }
/** * (non-PHPdoc) * * @see \Zend\Mvc\Router\Http\TreeRouteStack::assemble() */ public function assemble(array $params = [], array $options = []) { // Generate orignal URL $url = parent::assemble($params, $options); // Fill Route-Map if (null === $this->routeMap) { $this->routeMap = []; $nodes = $this->getServiceLocator()->get('NodeService')->getNodes(); foreach ($nodes as $node) { if (false == empty($node->getNodeOriginalRoute()) && 'redirect' != $node->getNodeType()) { $this->routeMap[$node->getNodeOriginalRoute()] = $node->getNodeRoute(); } } } // Get URL from Route-Map and return it if (true === isset($this->routeMap[$url])) { return $this->routeMap[$url]; } // Return original URL return $url; }
public function testDefaultParamDoesNotOverrideParamForAssembling() { $stack = new TreeRouteStack(); $stack->addRoute('foo', new TestAsset\DummyRouteWithParam()); $stack->setDefaultParam('foo', 'baz'); $this->assertEquals('bar', $stack->assemble(array('foo' => 'bar'), array('name' => 'foo'))); }
/** * assemble(): Defined by RouteInterface interface. * * @see Route::assemble() * @param array $params * @param array $options * @return mixed * @throws Exception\RuntimeException */ public function assemble(array $params = array(), array $options = array()) { if ($this->childRoutes !== null) { $this->addRoutes($this->childRoutes); $this->childRoutes = null; } $options['has_child'] = isset($options['name']); $path = $this->route->assemble($params, $options); $params = array_diff_key($params, array_flip($this->route->getAssembledParams())); if (!isset($options['name'])) { if (!$this->mayTerminate) { throw new Exception\RuntimeException('Part route may not terminate'); } else { return $path; } } unset($options['has_child']); $options['only_return_path'] = true; $path .= parent::assemble($params, $options); return $path; }
/** * assemble(): Defined by Route interface. * * @see Route::assemble() * @param array $params * @param array $options * @return mixed */ public function assemble(array $params = null, array $options = null) { if ($this->childRoutes !== null) { $this->addRoutes($this->childRoutes); $this->childRoutes = null; } $uri = $this->route->assemble($params, $options) . parent::assemble($params, $options); return $uri; }
/** * assemble(): Defined by Route interface. * * @see Route::assemble() * @param array $params * @param array $options * @return mixed */ public function assemble(array $params = array(), array $options = array()) { if ($this->childRoutes !== null) { $this->addRoutes($this->childRoutes); $this->childRoutes = null; } $uri = $this->route->assemble($params, $options); if (!isset($options['name'])) { if (!$this->mayTerminate) { throw new Exception\RuntimeException('Part route may not terminate'); } else { return $uri; } } $uri .= parent::assemble($params, $options); return $uri; }
public function testChainRouteAssembling() { $stack = new TreeRouteStack(); $stack->addPrototype('bar', array('type' => 'literal', 'options' => array('route' => '/bar'))); $stack->addRoute('foo', array('type' => 'literal', 'options' => array('route' => '/foo'), 'chain_routes' => array('bar'))); $this->assertEquals('/foo/bar', $stack->assemble(array(), array('name' => 'foo'))); }
/** * Get upload url path * * @param integer $propertyId Property id * * @return string */ public function getUploadUrl($propertyId) { return $this->router->assemble(array('document_id' => $this->getDocumentId(), 'property_id' => $propertyId), array('name' => 'content/media/upload')); }
public function testChainRouteAssemblingWithChildrenAndSecureScheme() { $stack = new TreeRouteStack(); $uri = new \Zend\Uri\Http(); $uri->setHost('localhost'); $stack->setRequestUri($uri); $stack->addRoute('foo', array('type' => 'literal', 'options' => array('route' => '/foo'), 'chain_routes' => array(array('type' => 'scheme', 'options' => array('scheme' => 'https'))), 'child_routes' => array('baz' => array('type' => 'literal', 'options' => array('route' => '/baz'))))); $this->assertEquals('https://localhost/foo/baz', $stack->assemble(array(), array('name' => 'foo/baz'))); }