Skip to content

Commit

Permalink
adds new RouteGroup methods, Route::controller returns RouteGroup
Browse files Browse the repository at this point in the history
  • Loading branch information
tenmajkl committed Jan 22, 2022
1 parent d225b6e commit f96bcde
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
/vendor/
**/*.swp
.phpunit.result.cache
composer.lock
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Lemon is dead simple php micro framework.

Latest version: 2.6.8
Latest version: 2.6.9

Documentation: https://github.com/Lemon-Framework/docs

Expand Down
2 changes: 1 addition & 1 deletion src/Http/Routing/RouteCore.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public static function controller(String $base, String $controller)
}
}

return $routes;
return new RouteGroup([], $routes);
}

/**
Expand Down
43 changes: 41 additions & 2 deletions src/Http/Routing/RouteGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function __construct(Array $parameters, Array $routes)
/**
* Resolves nested route groups and arays of routes
*/
public function resolve()
private function resolve()
{
foreach ($this->routes as $pos => $route)
{
Expand All @@ -67,12 +67,51 @@ public function resolve()
/**
* Resolves routes that aren't Route instance
*/
public function resolveRoute($pos, $routes)
private function resolveRoute($pos, $routes)
{
array_push($this->unset_positions, $pos);
$this->routes = array_merge($this->routes, $routes);
}

/**
* Adds middlewares to each route in group
*
* @param array $middlewares
* @return self
*/
public function middlewares(array $middlewares)
{
$this->middlewares = array_merge($this->middlewares, $middlewares);
$this->update();
return $this;
}

/**
* Sets route uri prefix to each route in group
*
* @param string $prefix
* @return self
*/
public function prefix(string $prefix)
{
$this->prefix = $prefix;
$this->update();
return $this;
}

/**
* Updates route name to each route in group
*
* @param string $name
* @return self
*/
public function name(string $name)
{
$this->name = $name;
$this->update();
return $this;
}

/**
* Updates every group member to given parameters
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Kernel/Lemonade/Helpers/info.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
";

const VERSION = "2.6.8";
const VERSION = "2.6.9";

// Shows help
function help()
Expand Down

0 comments on commit f96bcde

Please sign in to comment.