/** * Test * * @return void * */ public static function setUpBeforeClass() { $di = new \Anax\DI\CDIFactoryDefault(); $di->setShared('db', function () { $db = new \Mos\Database\CDatabaseBasic(); $db->setOptions(['dsn' => "sqlite:memory::", 'debug_connect' => true]); $db->connect(); return $db; }); self::$movie = new \Jovis\DatabaseModel\Movie(); self::$movie->setDI($di); self::$movie->init(); }
/** * Test * * @return void * */ public function testOverwritePreviousDefinedService() { $di = new \Anax\DI\CDIFactoryDefault(); $service = 'session'; $di->set($service, function () { $session = new \Anax\Session\CSession(); $session->configure(ANAX_APP_PATH . 'config/session.php'); $session->name(); //$session->start(); return $session; }); $session = $di->get($service); $this->assertInstanceOf('\\Anax\\Session\\CSession', $session); }
<?php /* * * Include config */ require __DIR__ . '/config.php'; /* * * Initialize Di object */ $di = new \Anax\DI\CDIFactoryDefault(); /* * * Set Shared objects */ $db = function () { $db = new \Mos\Database\CDatabaseBasic(); $db->setOptions(require ANAX_APP_PATH . 'config/database_mysql.php'); $db->connect(); return $db; }; $di->setShared('db', $db); $loginController = function () use($di) { $controller = new \Anax\Login\LoginController(); $controller->setDI($di); return $controller; }; $di->set('LoginController', $loginController); /* *
<?php /** * This is a Anax pagecontroller. * */ // Include the essential settings. require __DIR__ . '/config.php'; // Create services and inject into the app. $di = new \Anax\DI\CDIFactoryDefault(); $di->setShared('flashMessages', function () use($di) { $flashMessages = new tijo15\FlashMessage\FlashController($di); return $flashMessages; }); $app = new \Anax\Kernel\CAnax($di); // Test Route $app->router->add('', function () use($app) { $app->theme->setTitle("Testing flash"); // $app->theme->addStylesheet('css/flash.css'); $app->flashMessages->addMessage('Godkänt!', 'success'); $app->flashMessages->addMessage('Information', 'info'); $app->flashMessages->addMessage('Varning!', 'warning'); $app->flashMessages->addMessage('Error', 'error'); $app->flashMessages->addMessage('Test', 'Test'); $app->views->add('flash/flash', ['content' => $app->flashMessages->getFlashMessages()]); }); // Check for matching routes and dispatch to controller/handler of route $app->router->handle(); // Render the page $app->theme->render();
<?php /** * This is a Anax pagecontroller- * */ // Include the essential settings. require __DIR__ . '/config.php'; // Set up app $di = new \Anax\DI\CDIFactoryDefault(); $app = new \Anax\MVC\CApplicationBasic($di); $app->url->setUrlType(\Anax\Url\Curl::URL_CLEAN); $app->theme->configure(ANAX_APP_PATH . 'config/theme.php'); $app->navbar->configure(ANAX_APP_PATH . 'config/navbar.php'); // Set the database $di->set('db', function () { $db = new \Mos\Database\CDatabaseBasic(); $db->setOptions(require ANAX_APP_PATH . 'config/config_mysql.php'); $db->connect(); return $db; }); $app->db->dropTableIfExists('content')->execute(); $app->db->createTable('content', ['id' => ['integer', 'primary key', 'not null', 'auto_increment'], 'slug' => ['varchar(80)', 'unique'], 'url' => ['varchar(80)', 'unique'], 'type' => ['varchar(80)'], 'title' => ['varchar(80)'], 'data' => ['text'], 'filter' => ['char(80)'], 'created' => ['datetime'], 'published' => ['datetime'], 'updated' => ['datetime'], 'deleted' => ['datetime'], 'owner' => ['varchar(80)'], 'updated_by' => ['varchar(80)']])->execute(); $now = gmdate('Y-m-h H:i:s'); $app->db->insert('content', ['slug', 'type', 'title', 'data', 'created', 'published', 'owner']); $app->db->execute(['a-first-article', 'article', 'A first article', 'This is the text of the first article.', $now, $now, 'admin']); $url = $app->url->create(''); echo "Database has been setup."; ?> <br><a href="<?php echo $url;
<?php /** * Config file for pagecontrollers, creating an instance of $app. * */ // Get environment & autoloader. require __DIR__ . '/config.php'; // Create services and inject into the app. // dependency injector factory $di = new \Anax\DI\CDIFactoryDefault(); // create application $app = new \Anax\MVC\CApplicationBasic($di); // setup service for flashMessages $di->set('flashMessages', function () use($di) { $flashMessages = new Anax\Flash\CFlashAnax(); $flashMessages->setDI($di); return $flashMessages; }); $app->theme->setTitle("Flash-redirect"); // get messages from session in HTML format. ready to use in a view. $messages = $app->flashMessages->getMessage(); // add view to show messages in. (using a default template that has a variable $content) $app->views->add('default/article', ['content' => $messages]); // add stylesheet for styling messages $app->theme->addStylesheet('css/flash.css'); $app->theme->render();
<?php /* * * Include config */ require __DIR__ . '/config.php'; /* * * Initialize frontcontroller intances */ $di = new \Anax\DI\CDIFactoryDefault(); $di->setShared('db', function () { $db = new \Mos\Database\CDatabaseBasic(); $db->setOptions(require ANAX_APP_PATH . 'config/database_mysql.php'); $db->connect(); return $db; }); $di->set('UsersController', function () use($di) { $controller = new \Anax\Users\UsersController(); $controller->setDI($di); return $controller; }); $app = new \Anax\Kernel\CAnax($di); /* * * Theme configuration */ $app->theme->configure(ANAX_APP_PATH . 'config/theme-grid.php'); /* *
<?php /** * This is a Anax frontcontroller. * */ // Get environment & autoloader. require __DIR__ . '/config.php'; // Create services and inject into the app. $di = new \Anax\DI\CDIFactoryDefault(); $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("Anax MVC 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"]]]); } } $app->router->add('', function () use($app) { $app->dispatcher->forward(['controller' => 'test']); }); $app->router->add('t1', function () use($app) { $app->dispatchNO; $app->dispatcher->forward(['controller' => 'test']);
<?php /** * This is a Anax pagecontroller. * */ // Include the essential settings. require __DIR__ . '/config_with_app.php'; // Create services and inject into the app. $di = new \Anax\DI\CDIFactoryDefault(); $di->set('RssController', function () use($di) { $controller = new \petlid\RSSReader\RSSReaderController("http://www.historytoday.com/feed/rss.xml"); $controller->setDI($di); return $controller; }); // Standard route $app->router->add('', function () use($app) { $app->dispatcher->forward(['controller' => 'RSS', 'action' => 'view']); }); // Check for matching routes and dispatch to controller/handler of route $app->router->handle(); // Render the page $app->theme->render();
<?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(); $app = new \Anax\Kernel\CAnax($di); //Clean URL's $app->url->setUrlType(\Anax\Url\CUrl::URL_CLEAN); //Add theme $app->theme->configure(ANAX_APP_PATH . 'config/theme_gnar.php'); //Add Navbar $app->navbar->configure(ANAX_APP_PATH . 'config/navbar_gnar.php'); $di->set('form', '\\Mos\\HTMLForm\\CForm'); $di->set('time', '\\Anax\\Content\\CTime'); //Lägger till databasen $di->setShared('db', function () { $db = new \Mos\Database\CDatabaseBasic(); $db->setOptions(require ANAX_APP_PATH . 'config/config_mysql.php'); $db->connect(); return $db; }); //$di->set('CommentController', function() use ($di) { // $controller = new Phpmvc\Comment\CommentController(); // $controller->setDI($di); // return $controller; //});
<?php require __DIR__ . '/config_with_app.php'; // Create services and inject into the app. $di = new \Anax\DI\CDIFactoryDefault(); $di->set('HemController', function () use($di) { $controller = new Anax\Hem\HemController(); $controller->setDI($di); return $controller; }); $di->set('AnvandareController', function () use($di) { $controller = new Anax\Anvandare\AnvandareController(); $controller->setDI($di); return $controller; }); $di->set('FragorController', function () use($di) { $controller = new Anax\Fragor\FragorController(); $controller->setDI($di); return $controller; }); $di->set('TaggarController', function () use($di) { $controller = new Anax\Taggar\TaggarController(); $controller->setDI($di); return $controller; }); $di->set('OmossController', function () use($di) { $controller = new Anax\Omoss\OmossController(); $controller->setDI($di); return $controller; }); $di->set('ProfilController', function () use($di) {
<?php require __DIR__ . '/config_with_app.php'; //To get clean url. Notice it must be before navbar to work as expected // Create services and inject into the app. $di = new \Anax\DI\CDIFactoryDefault(); $app = new \Anax\Kernel\CAnax($di); $app->theme->configure(ANAX_APP_PATH . 'config/theme.php'); $di->set('ctable', function () use($di) { $table = new \Edtau\Table\CTable(); $table > setDI($di); return $table; }); $di->set('TableController', function () use($di) { $controller = new \Edtau\Table\TableController(); $controller->setDI($di); return $controller; }); // test route for table $app->router->add('', function () use($app) { $app->theme->setTitle("Tabletest"); $app->dispatcher->forward(['controller' => 'Table', 'action' => 'test']); }); //route to show how to use table $app->router->add('table', function () use($app) { $app->theme->setTitle("table"); $header = array('Förnamn', 'Efternamn', 'ålder'); $data = array(array('Anders', 'Andersson', '40'), array('Stig', 'Larsson', '41'), array('Anna', 'Svensson', '45'), array('Bengt', 'Andersson', '40'), array('Karin', 'Larsson', '41'), array('Ulf', 'Svensson', '45')); $id = "red"; $app->dispatcher->forward(['controller' => 'Table', 'action' => 'getTable', 'param' => $data, 'param' => $header, 'params' => [$data, $header, $id]]); });
<?php require __DIR__ . '/config_with_app.php'; $di = new \Anax\DI\CDIFactoryDefault(); $di->setShared('rss', function () { $rss = new \Anax\RSS\RSS(); return $rss; }); $app->router->add('rss', function () use($app) { $xml = "http://dbwebb.se/forum/feed.php"; $xmlDoc = new DOMDocument(); $xmlDoc->load($xml); $app->theme->setVariable('title', "RSS Flöde")->setVariable('main', "<h2>Senaste nytt/ändrat från " . $app->rss->setupAndGetTitle($xmlDoc) . " forumet</h2>"); $app->views->addString($app->rss->getContent($xmlDoc), 'main'); }); $app->router->handle(); $app->theme->render();
<?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(); // Include support for forms //$di->set('form', '\Mos\HTMLForm\CForm'); // Include controllers for comments $di->setShared('CommentsController', function () use($di) { $controller = new \Anax\Comments\CCommentsController(); $controller->setDI($di); return $controller; }); // Include controllers for users $di->setShared('UsersController', function () use($di) { $controller = new \Anax\Users\UsersController(); $controller->setDI($di); return $controller; }); // Include support for database $di->setShared('db', function () { $db = new \Mos\Database\CDatabaseBasic(); $db->setOptions(require ANAX_APP_PATH . 'config/database_sqlite.php'); $db->connect(); return $db; });
<?php /** * This is a Anax frontcontroller. * */ // Get environment & autoloader. require __DIR__ . '/config.php'; // Create services and inject into the app. $di = new \Anax\DI\CDIFactoryDefault(); $di->set('form', '\\Mos\\HTMLForm\\CForm'); $di->set('FormController', function () use($di) { $controller = new \Anax\HTMLForm\FormController(); $controller->setDI($di); return $controller; }); $di->set('FormSmallController', function () use($di) { $controller = new \Anax\HTMLForm\FormSmallController(); $controller->setDI($di); return $controller; }); $app = new \Anax\MVC\CApplicationBasic($di); // Home route $app->router->add('', function () use($app) { $app->theme->setTitle("Testing CForm with Anax"); $app->views->add('default/page', ['title' => "Try out a form using CForm", 'content' => "This is a example showing how to use CForm with Anax MVC, you must have CForm loaded as part of Anax MVC to make this frontcontroller work.", 'links' => [['href' => $app->url->create('test1'), 'text' => "Form as a route"], ['href' => $app->url->create('form'), 'text' => "Form as a controller"], ['href' => $app->url->create('form-small'), 'text' => "Form as own class, used by a controller"]]]); }); // Test form route $app->router->add('test1', function () use($app) { $app->session(); // Will load the session service which also starts the session
<?php // Get environment & autoloader. require __DIR__ . '/config.php'; // Create services and inject into the app. $di = new \Anax\DI\CDIFactoryDefault(); $di->setShared('fmsg', function () use($di) { $fmsg = new rudden\Flash\FlashMessages(); $fmsg->setDI($di); return $fmsg; }); $app = new \Anax\Kernel\CAnax($di); // Home Route $app->router->add('', function () use($app) { $app->theme->setTitle('Flash'); $app->theme->addStyleSheet('css/flash.css'); $app->fmsg->success('Success message'); $app->fmsg->info('Informative message'); $app->fmsg->error('Error message'); $app->fmsg->warning('Warning message'); $fmsg = $app->fmsg->printMessage(); $app->views->addString($fmsg, 'main'); }); $app->router->handle(); $app->theme->render();
<?php require __DIR__ . '/config_with_app.php'; $app->url->setUrlType(\Anax\Url\CUrl::URL_CLEAN); // Create services and inject into the app. $di = new \Anax\DI\CDIFactoryDefault(); $di->set('TableController', function () use($di) { $controller = new \Jovis\HTMLTable\TableController(); $controller->setDI($di); return $controller; }); $di->setShared('db', function () { $db = new \Mos\Database\CDatabaseBasic(); $db->setOptions(require ANAX_APP_PATH . 'config/config_mysql.php'); $db->connect(); return $db; }); $app = new \Anax\Kernel\CAnax($di); $app->theme->configure(ANAX_APP_PATH . 'config/theme.php'); $app->navbar->configure(ANAX_APP_PATH . 'config/navbar.php'); $app->router->add('HTMLTable', function () use($app) { $app->theme->setTitle("HTML-tabell"); $model = new Jovis\DatabaseModel\Movie(); // modellen man vill skriva ut som html-tabell $app->dispatcher->forward(['controller' => 'table', 'action' => 'init', 'params' => [$model]]); $noListing = array('password', 'Password', 'pwd'); //namn på kolumner vi inte vill ha med i tabellen //sin skrivs ut $app->dispatcher->forward(['controller' => 'table', 'action' => 'list', 'params' => [$noListing, $model]]); }); $app->router->handle();
<?php /** * This is a Anax pagecontroller. * */ // Include the essential settings. require __DIR__ . '/config.php'; // Create services and inject into the app. $di = new \Anax\DI\CDIFactoryDefault(); $di->set('CommentController', function () use($di) { $controller = new Mos\Comment\CommentController(); $controller->setDI($di); return $controller; }); $app = new \Anax\Kernel\CAnax($di); // Home route $app->router->add('', function () use($app) { $app->theme->setTitle("Welcome to Anax Guestbook"); $app->views->add('comment/index'); $app->dispatcher->forward(['controller' => 'comment', 'action' => 'view']); $app->views->add('comment/form', ['mail' => null, 'web' => null, 'name' => null, 'content' => null, 'output' => null]); }); // Check for matching routes and dispatch to controller/handler of route $app->router->handle(); // Render the page $app->theme->render();
<?php /** * Config file for pagecontrollers, creating an instance of $app. * */ // Get environment & autoloader. require ANAX_PATH . 'webroot/config.php'; // Create services and inject into the app. $di = new \Anax\DI\CDIFactoryDefault(); $app = new \Anax\Kernel\CAnax($di); $di->set('RssController', function () use($di) { $controller = new \CRssFeed\Rss\RssFeedController(); $controller->setDI($di); return $controller; }); $di->setShared('db', function () { $db = new \CRssFeed\Database\CDatabaseBasic(); $db->setOptions(require ANAX_APP_PATH . 'config/config_mysql.php'); $db->connect(); return $db; });