Last active
December 8, 2016 14:04
-
-
Save matej21/8118567 to your computer and use it in GitHub Desktop.
Revisions
-
matej21 revised this gist
Mar 10, 2014 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,6 +2,7 @@ use Nette\Application\IRouter; use Nette\Application\UI\InvalidLinkException; use Nette\Application\UI\Presenter; use Nette\Application; use Nette\Http\Url; use Nette\Object; -
matej21 revised this gist
Feb 22, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -69,7 +69,7 @@ public function link($destination, array $args = array()) $action = (string) substr($destination, $a + 1); $presenter = substr($destination, 0, $a); if ($presenter[0] == ":") { $presenter = substr($presenter, 1); } if (!$action) { $action = 'default'; -
matej21 revised this gist
Dec 24, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -10,7 +10,7 @@ * @author David Matějka * @author David Grudl */ class UrlGenerator extends Object { /** @var \Nette\Application\IRouter */ -
matej21 created this gist
Dec 24, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,98 @@ <?php use Nette\Application\IRouter; use Nette\Application\UI\InvalidLinkException; use Nette\Application; use Nette\Http\Url; use Nette\Object; /** * @author David Matějka * @author David Grudl */ class LinkGenerator extends Object { /** @var \Nette\Application\IRouter */ protected $router; /** @var \Nette\Http\Url */ protected $refUrl; /** * @param Url $refUrl * @param IRouter $router */ public function __construct(Url $refUrl, IRouter $router) { $this->refUrl = $refUrl; $this->router = $router; } /** * URL factory. * * @param string $destination in format "[module:]presenter:action" * @param array $args array of arguments * @return string URL * @throws InvalidLinkException */ public function link($destination, array $args = array()) { $a = strpos($destination, '#'); if ($a === FALSE) { $fragment = ''; } else { $fragment = substr($destination, $a); $destination = substr($destination, 0, $a); } $a = strpos($destination, '?'); if ($a !== FALSE) { parse_str(substr($destination, $a + 1), $args); // requires disabled magic quotes $destination = substr($destination, 0, $a); } $a = strpos($destination, '//'); if ($a !== FALSE) { $destination = substr($destination, $a + 2); } if ($destination == NULL) { // intentionally == throw new InvalidLinkException("Destination must be non-empty string."); } $a = strrpos($destination, ':'); $action = (string) substr($destination, $a + 1); $presenter = substr($destination, 0, $a); if ($presenter[0] == ":") { $presenter = substr($destination, 1); } if (!$action) { $action = 'default'; } $args[Presenter::ACTION_KEY] = $action; $request = new Application\Request( $presenter, Application\Request::FORWARD, $args, array(), array() ); $url = $this->router->constructUrl($request, $this->refUrl); if ($url === NULL) { unset($args[Presenter::ACTION_KEY]); $params = urldecode(http_build_query($args, NULL, ', ')); throw new InvalidLinkException("No route for $presenter:$action($params)"); } return $url . $fragment; } }