Skip to content

Commit

Permalink
Integrate with Anax Flat.
Browse files Browse the repository at this point in the history
  • Loading branch information
mosbth committed Aug 13, 2018
1 parent b8b6901 commit 4f6cf9e
Show file tree
Hide file tree
Showing 5 changed files with 193 additions and 82 deletions.
7 changes: 7 additions & 0 deletions REVISION.md
Expand Up @@ -3,6 +3,13 @@ Revision history



v2.0.0-alpha.2 (2018-08-13)
---------------------------------

* Integrate with Anax Flat.



v2.0.0-alpha.1 (2018-08-10)
---------------------------------

Expand Down
70 changes: 70 additions & 0 deletions config/router/710_development.php
@@ -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.";
},
],
]
];
55 changes: 55 additions & 0 deletions src/Controller/DevelopmentController.php
@@ -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
]);
}
}
82 changes: 0 additions & 82 deletions src/Controller/ErrorController.php

This file was deleted.

61 changes: 61 additions & 0 deletions src/Controller/ErrorHandlerController.php
@@ -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);
}
}

0 comments on commit 4f6cf9e

Please sign in to comment.