Skip to content

Commit

Permalink
Minor code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
joanrodas committed Apr 9, 2022
1 parent 2e6420f commit 14cc2dc
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion PluboRoutes/Route/RouteInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ public function getPath();
public function getAction();
public function getConfig();
public function hasCallback();
public function setArgs($args);
public function addArg($arg);
public function getArgs();
}
4 changes: 2 additions & 2 deletions PluboRoutes/Route/RouteTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public function getConfig() {
*
* @param array
*/
public function setArgs($args) {
$this->args = $args;
public function addArg($arg) {
$this->args[] = $arg;
}

/**
Expand Down
5 changes: 2 additions & 3 deletions PluboRoutes/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ public function match(array $query_variables)
private function add_rule(RouteInterface $route, $position = 'top') {
$regex_path = $this->clean_path( $route->getPath() );
$index_string = 'index.php?'.$this->route_variable.'='.$route->getName();
$route_args = array();
if( preg_match_all('#\{(.+?)\}#', $regex_path, $matches) ) {
$patterns = $matches[1];
foreach ($patterns as $key => $pattern) {
Expand All @@ -99,12 +98,12 @@ private function add_rule(RouteInterface $route, $position = 'top') {
$regex_path = str_replace($matches[0][$key], $regex_code, $regex_path);
add_rewrite_tag('%'.$name.'%', $regex_code);
$index_string .= "&$name=\$matches[$match_num]";
$route_args[] = $name;
$route->addArg($name);
}
}
}
add_rewrite_rule("^$regex_path$", $index_string, $position);
$route->setArgs($route_args);

}

private function clean_path($path) {
Expand Down

0 comments on commit 14cc2dc

Please sign in to comment.