Skip to content

Commit

Permalink
fix: apiMode
Browse files Browse the repository at this point in the history
  • Loading branch information
ipranjal committed Nov 2, 2020
1 parent 3e007a4 commit 77091ba
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/RouterEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class RouterEngine
/**
* Stores if not found error occured
*/
private $not_found;
private $not_found = false;

//---------------------------------------------------------------//

Expand All @@ -88,12 +88,13 @@ public function __construct(Request $request, RouteCollection $collection, $apiM
*/
public function route()
{
try{

// Get URL and request method.
$this->request_method = strtolower($this->request->getMethod());

if ($this->check_manual()) {
return;
return true;
}

//Break URL into segments
Expand All @@ -109,11 +110,16 @@ public function route()
$this->request->attributes->set('_controller', $this->controller . '::' . $this->method);

$this->setArguments();

if($this->not_found)
return true;
else
return false;
} catch(\Exception $e){
if($this->apiMode){
return false;
}else{
throw $e;
}
}


}

//---------------------------------------------------------------//
Expand Down Expand Up @@ -181,8 +187,6 @@ private function getController()
protected function error($message)
{
$this->not_found = true;

if(!$this->apiMode)
throw new NotFoundException('Oops its an 404 error! :' . $message);

}
Expand All @@ -196,7 +200,7 @@ protected function error($message)
private function setArguments()
{
$controller = new $this->controller;

$arguments = [];
for ($j = 2; $j < count($this->path_info); $j++) {
array_push($arguments, $this->path_info[$j]);
Expand Down

0 comments on commit 77091ba

Please sign in to comment.