<?php /** * This is a Anax frontcontroller. * */ // Get environment & autoloader. require __DIR__ . '/../config.php'; // Create services and inject into the app. $di = new \Anax\DI\CDIFactoryTest(); $app = new \Anax\Kernel\CAnax($di); $di->set('TestController', function () use($di) { $controller = new TestController(); $controller->setDI($di); return $controller; }); class TestController { use \Anax\DI\TInjectable; public function indexAction() { $this->theme->setTitle("How verbose is the error reporting"); $this->views->add('default/page', ['title' => "Testing error reporting from Anax MVC", 'content' => "Trying out some missusage of Anax MVC to see if the errors are easy to understand.", 'links' => [['href' => $this->url->create('t1'), 'text' => "Using not defined service as property of \$app"], ['href' => $this->url->create('t2'), 'text' => "Using not defined service as method of \$app"], ['href' => $this->url->create('t3'), 'text' => "Forward to non-existing controller"], ['href' => $this->url->create('t4'), 'text' => "Forward to non-existing action"], ['href' => $this->url->create('test/no-di-call'), 'text' => "Using TInjectable forgot to set \$di, accessing session() via __call()"], ['href' => $this->url->create('test/no-di-get'), 'text' => "Using TInjectable forgot to set \$di, accessing session via __get()"], ['href' => $this->url->create('test/no-such-service-property'), 'text' => "Using TInjectable forgot to set \$di, accessing session() via __call()"], ['href' => $this->url->create('test/no-such-service-method'), 'text' => "Using TInjectable forgot to set \$di, accessing session via __get()"]]]); } public function noDiCallAction() { $this->di = null; $this->session(); } public function noDiGetAction() {
<?php /** * This is a Anax frontcontroller. * */ // Get environment & autoloader. require __DIR__ . '/../config.php'; // Create services and inject into the app. $di = new \Anax\DI\CDIFactoryTest(); $app = new \Anax\Kernel\CAnax($di); $app->router->add('', function () use($app, $di) { $html = "<pre>" . print_r($di->getServices(), true) . "</pre>"; $html .= "<h2>These services are active</h2>"; $html .= "<pre>" . print_r($di->getActiveServices(), true) . "</pre>"; $app->theme->setTitle("Display available services in \$di"); $app->views->add('default/page', ['title' => "These services are available in \$di.", 'content' => $html]); }); // Check for matching routes and dispatch to controller/handler of route $app->router->handle(); // Render the page $app->theme->render();