Skip to content

Commit

Permalink
Merge pull request #12 from kivudesign/version_boss
Browse files Browse the repository at this point in the history
[UPD] Refacroring and review view routing
  • Loading branch information
bim-g authored Aug 16, 2022
2 parents 359516a + 243fe14 commit 76c8f34
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/Core/Routing/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private function paramMatch($match): string
return '([^/]+)';
}

function with($param, $regex): \Wepesi\App\Core\Route
function with($param, $regex): Route
{
$this->_params[$param] = str_replace('(', '(?:', $regex);
return $this;
Expand Down
46 changes: 17 additions & 29 deletions src/Core/Routing/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,64 +8,52 @@
class Router{

private $_url;
private $routes=[];
private $_nameRoute=[];
private array $routes;
private array $_nameRoute;

function __construct()
{
$this->_url=$this->getMethodeUrl();
}

/**
* @return mixed|void
*/
private function getMethodeUrl(){
foreach($_GET as $url) return $url;
}

/**
* @return mixed|void
*/
function geturl(){
return $this->_url;
$this->_nameRoute =[];
$this->routes = [];
$this->_url = $_SERVER['REQUEST_URI'];
}

/**
* @param $path
* @param $collable
* @param $callable
* @param null $name
* @return Route
*/
function get($path, $collable,$name=null): Route
function get($path, $callable, $name=null): Route
{
return $this->add($path,$collable,$name,"GET");
return $this->add($path,$callable,$name,"GET");
}

/**
* @param $path
* @param $collable
* @param $callable
* @param null $name
* @return Route
*/
function post($path, $collable,$name=null): Route
function post($path, $callable, $name=null): Route
{
return $this->add($path,$collable,$name,"POST");
return $this->add($path,$callable,$name,"POST");
}

/**
* @param $path
* @param $collable
* @param $callable
* @param $name
* @param $methode
* @return Route
*/
private function add($path,$collable,$name,$methode): Route
private function add($path, $callable, $name, $methode): Route
{
$route = new Route($path, $collable);
$route = new Route($path, $callable);
$this->routes[$methode][] = $route;

if(is_string($collable) && $name==null){
$name=$collable;
if(is_string($callable) && $name==null){
$name=$callable;
}

if($name){
Expand All @@ -77,7 +65,7 @@ private function add($path,$collable,$name,$methode): Route
/**
* @throws Exception
*/
function url($name, $params=[]): string
protected function url($name, $params=[]): string
{
try{
if(!isset($this->_nameRoute[$name])){
Expand Down

0 comments on commit 76c8f34

Please sign in to comment.