Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
193 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
use Anax\Route\Exception\NotFoundException; | ||
|
||
/** | ||
* Routes to ease development and debugging. | ||
*/ | ||
return [ | ||
// Path where to mount the routes, is added to each route path. | ||
"mount" => "dev", | ||
|
||
// All routes in order | ||
"routes" => [ | ||
[ | ||
"info" => "Development and debugging information.", | ||
"method" => null, | ||
"path" => "*", | ||
"handler" => function ($di) { | ||
$title = " | Anax development utilities"; | ||
$pages = [ | ||
"" => "index", | ||
"di" => "di", | ||
"request" => "request", | ||
"router" => "router", | ||
"session" => "session", | ||
"view" => "view", | ||
]; | ||
|
||
$path = $di->get("router")->getMatchedPath(); | ||
if (!array_key_exists($path, $pages)) { | ||
throw new NotFoundException(); | ||
} | ||
|
||
$page = $di->get("page"); | ||
$page->add( | ||
"anax/v2/dev/{$pages[$path]}", | ||
[ | ||
"mount" => "dev/" | ||
] | ||
); | ||
|
||
return $page->render([ | ||
"title" => ucfirst($pages[$path]) . $title | ||
]); | ||
}, | ||
], | ||
[ | ||
"info" => "Add +1 to session.", | ||
"path" => "session/increment", | ||
"handler" => function ($di) { | ||
$session = $di->get("session"); | ||
$number = $session->get("number", 0); | ||
$session->set("number", $number + 1); | ||
var_dump($session); | ||
return "Reload page to increment 'number' in the session."; | ||
}, | ||
], | ||
[ | ||
"info" => "Destroy the session.", | ||
"path" => "session/destroy", | ||
"handler" => function ($di) { | ||
$session = $di->get("session"); | ||
var_dump($session); | ||
$session->destroy(); | ||
var_dump($session); | ||
return "The session was destroyed."; | ||
}, | ||
], | ||
] | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
namespace Anax\Controller; | ||
|
||
use Anax\Commons\ContainerInjectableInterface; | ||
use Anax\Commons\ContainerInjectableTrait; | ||
use Anax\Route\Exception\NotFoundException; | ||
|
||
/** | ||
* A controller to ease with development and debugging information. | ||
*/ | ||
class DevelopmentController implements ContainerInjectableInterface | ||
{ | ||
use ContainerInjectableTrait; | ||
|
||
|
||
|
||
/** | ||
* Render views that are supported. | ||
* | ||
* @throws Anax\Route\Exception\NotFoundException when route is not found. | ||
* @return object as the response. | ||
*/ | ||
public function catchAll() : object | ||
{ | ||
$title = " | Anax development utilities"; | ||
$pages = [ | ||
"" => "index", | ||
"di" => "di", | ||
"request" => "request", | ||
"router" => "router", | ||
"session" => "session", | ||
"view" => "view", | ||
]; | ||
|
||
$path = $this->di->get("router")->getMatchedPath(); | ||
|
||
if (!array_key_exists($path, $pages)) { | ||
throw new NotFoundException(); | ||
} | ||
|
||
$page = $this->di->get("page"); | ||
$page->add( | ||
"anax/v2/dev/{$pages[$path]}", | ||
[ | ||
"mount" => "dev/" | ||
] | ||
); | ||
|
||
return $page->render([ | ||
"title" => ucfirst($pages[$path]) . $title | ||
]); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
namespace Anax\Controller; | ||
|
||
use Anax\Commons\ContainerInjectableInterface; | ||
use Anax\Commons\ContainerInjectableTrait; | ||
use Anax\Route\Exception\NotFoundException; | ||
|
||
/** | ||
* A controller to ease with development and debugging information. | ||
*/ | ||
class ErrorHandlerController implements ContainerInjectableInterface | ||
{ | ||
use ContainerInjectableTrait; | ||
|
||
|
||
|
||
/** | ||
* Add internal routes for 403, 404 and 500. | ||
* | ||
* @throws Anax\Route\Exception\NotFoundException | ||
* @return void | ||
*/ | ||
public function catchAll() | ||
{ | ||
$title = " | Anax"; | ||
$pages = [ | ||
"403" => [ | ||
"Anax 403: Forbidden", | ||
"You are not permitted to do this." | ||
], | ||
"404" => [ | ||
"Anax 404: Not Found", | ||
"The page you are looking for is not here." | ||
], | ||
"500" => [ | ||
"Anax 500: Internal Server Error", | ||
"An unexpected condition was encountered." | ||
], | ||
]; | ||
|
||
$path = $this->di->get("router")->getMatchedPath(); | ||
if (!array_key_exists($path, $pages)) { | ||
throw new NotFoundException("Internal route for '$path' is not found."); | ||
} | ||
|
||
$page = $this->di->get("page"); | ||
$page->add( | ||
"anax/v2/error/default", | ||
[ | ||
"header" => $pages[$path][0], | ||
"text" => $pages[$path][1], | ||
] | ||
); | ||
|
||
return $page->render([ | ||
"title" => $pages[$path][0] . $title | ||
], $path); | ||
} | ||
} |