public function __construct() { parent::__construct(); // Creating a controller service for comments $this->set('CommentController', function () { $controller = new \Phpmvc\Comment\CommentController(); $controller->setDI($this); return $controller; }); // Creating a model service for comments $this->set('comments', function () { // $comments = new \Phpmvc\Comment\CommentsInSession(); $comments = new \Phpmvc\Comment\Comment(); $comments->setDI($this); return $comments; }); // Database service (from mos vendor) $this->set('db', function () { $db = new \Mos\Database\CDatabaseBasic(); $db->setOptions(require ANAX_APP_PATH . 'config/database_sqlite.php'); $db->connect(); return $db; }); // Form service (from mos vendor) $this->set('form', '\\Mos\\HTMLForm\\CForm'); // Controller for forms $this->set('FormController', function () { $controller = new \Anax\HTMLForm\FormController(); $controller->setDI($this); return $controller; }); // Controller for User-actions $this->set('UsersController', function () { $controller = new \Anax\Users\UsersController(); $controller->setDI($this); return $controller; }); // Request-recorder service $this->set('recorder', function () { $dbh = new \Kajja\Recorder\RequestDatabase(); $dbh->setOptions(['dsn' => 'sqlite:' . ANAX_APP_PATH . '.htphpmvc.sqlite', 'fetch_mode' => \PDO::FETCH_ASSOC]); $dbh->connect(); $formatter = new \Kajja\Recorder\HTMLFormatter(); $recorder = new \Kajja\Recorder\RequestRecordAnax($dbh, $formatter, $this); return $recorder; }); }
/** * Construct. * */ public function __construct() { parent::__construct(); $this->setShared('db', function () { $db = new \Mos\Database\CDatabaseBasic(); if (isset($_SERVER['HTTP-HOST'])) { if ($_SERVER['HTTP-HOST'] == 'localhost') { $db->setOptions(require ANAX_APP_PATH . 'config/config_mysql.php'); } } else { $db->setOptions(require ANAX_APP_PATH . 'config/config_mysql_bth.php'); } $db->connect(); return $db; }); $this->setShared('form', function () { $form = new \Mos\HTMLForm\CForm(); $this->session; //$form->saveInSession = true; return $form; }); // Set controllers $this->set('CommentController', function () { $controller = new \Phpmvc\Comment\CommentController(); $controller->setDI($this); return $controller; }); $this->set('UsersController', function () { $controller = new \Anax\Users\UsersController(); $controller->setDI($this); return $controller; }); $this->set('FormController', function () { $controller = new \Anax\HTMLForm\FormController(); $controller->setDI($this); return $controller; }); $this->set('logger', function () { $logger = new \Eden\Log\Clog(); //$controller->setDI($logger); return $logger; }); }
<?php /** * Config file for pagecontrollers, creating an instance of $app. * */ // Get environment & autoloader. require __DIR__ . '/config.php'; // Create services and inject into the app. $di = new \Anax\DI\CDIFactoryDefault(); $di->set('CommentController', function () use($di) { $controller = new Phpmvc\Comment\CommentController(); $controller->setDI($di); return $controller; }); $di->set('QuestionController', function () use($di) { $controller = new Anax\Question\QuestionController(); $controller->setDI($di); return $controller; }); $di->set('AnswerController', function () use($di) { $controller = new Anax\Answer\AnswerController(); $controller->setDI($di); return $controller; }); $di->set('UsersController', function () use($di) { $controller = new \Anax\Users\UsersController(); $controller->setDI($di); return $controller; }); $di->set('RssController', function () use($di) {