Skip to content

Commit

Permalink
some cleaning up
Browse files Browse the repository at this point in the history
  • Loading branch information
ipranjal committed May 14, 2018
1 parent 8102bf2 commit 9934a9a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/ControllerResolver.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/**
* Argument Resolver Class
* Controller Resolver Class
*
* @author : Pranjal Pandey
*/
Expand Down
7 changes: 6 additions & 1 deletion src/NotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
*/
namespace Scrawler\Router;

class NotFoundException extends \Exception{
use Throwable;

class NotFoundException extends \Exception {
public function __construct(string $message = "", int $code = 0, Throwable $previous = null) {
http_response_code(404);
parent::__construct($message, $code, $previous);
}
}
16 changes: 3 additions & 13 deletions src/RouterEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,10 @@ public function route() {
$this->path_info = $this->request->getPathInfo();

//Break URL into segments
if ($this->path_info === 'Index.php') {
$this->path_info = '/';
}

$this->path_info = explode('/', $this->path_info);
array_shift($this->path_info);



//Set corrosponding controller
if (isset($this->path_info[0]) && !empty($this->path_info[0])) {
$this->controller = $this->collection->getController(ucfirst($this->path_info[0]));
Expand All @@ -97,7 +92,7 @@ public function route() {
$this->method = $this->getMethod($this->controller);
$this->request->attributes->set('_controller',$this->controller.'::'.$this->method);
}else{
$this->error('No Controller could be found');
$this->error('No Controller could be resolved');
}
}
$this->setArguments();
Expand All @@ -111,11 +106,6 @@ public function route() {
*@param string $message
*/
protected function error($message) {
$controllers = $this->collection->getControllers();
$list="";
foreach($controllers as $name => $class){
$list = $list.''.$name.':'.$class;
}

throw new NotFoundException('Oops its an 404 error! :'.$message);
}
Expand Down Expand Up @@ -181,7 +171,7 @@ private function getMethod($controller) {
} elseif (method_exists($controller, 'allIndex')) {
return 'allIndex';
} else {
$this->error('The index method could not be found in given controller');
$this->error('The allIndex method you are looking for is not found in '.$controller.' controller');
}
}
}
Expand All @@ -198,7 +188,7 @@ public function getRoutedController(){
}

//----------------------------------------------------------------//
/*
/**
* Returns the method to be called
*
* @return String
Expand Down

0 comments on commit 9934a9a

Please sign in to comment.