-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from codeburnerframework/dev
merge support to named routes
- Loading branch information
Showing
10 changed files
with
241 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ language: php | |
php: | ||
- 5.5 | ||
- 5.6 | ||
- hhvm | ||
- 7.0 | ||
|
||
before_script: | ||
- composer self-update | ||
|
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
/** | ||
* Codeburner Framework. | ||
* | ||
* @author Alex Rohleder <contato@alexrohleder.com.br> | ||
* @copyright 2016 Alex Rohleder | ||
* @license http://opensource.org/licenses/MIT | ||
*/ | ||
|
||
namespace Codeburner\Router; | ||
|
||
/** | ||
* Create paths based on registered routes. | ||
* | ||
* @author Alex Rohleder <contato@alexrohleder.com.br> | ||
*/ | ||
|
||
class Path | ||
{ | ||
|
||
/** | ||
* @var Collector | ||
*/ | ||
|
||
protected $collector; | ||
|
||
/** | ||
* Link constructor. | ||
* | ||
* @param Collector $collector | ||
*/ | ||
|
||
public function __construct(Collector $collector) | ||
{ | ||
$this->collector = $collector; | ||
} | ||
|
||
/** | ||
* Generate a path to a route named by $name. | ||
* | ||
* @param string $name | ||
* @param array $args | ||
* | ||
* @throws \BadMethodCallException | ||
* @return string | ||
*/ | ||
|
||
public function to($name, array $args = []) | ||
{ | ||
$route = $this->collector->findNamedRoute($name); | ||
$parser = $this->collector->getParser(); | ||
$pattern = $route->getPattern(); | ||
|
||
preg_match_all("~" . $parser::DYNAMIC_REGEX . "~x", $pattern, $matches, PREG_SET_ORDER); | ||
|
||
foreach ((array) $matches as $key => $match) { | ||
if (!isset($args[$match[1]])) { | ||
throw new \BadMethodCallException("Missing argument '{$match[1]}' on creation of link for '{$name}' route."); | ||
} | ||
|
||
$pattern = str_replace($match[0], $args[$match[1]], $pattern); | ||
} | ||
|
||
return $pattern; | ||
} | ||
|
||
} |
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters