public function testEventManager() { $func = function () { return 'Hello World'; }; $p = new Project(); $p->attachEvent('route.pre', $func, 2); $this->assertEquals(1, count($p->getEventManager()->get('route.pre'))); $p->detachEvent('route.pre', $func); $this->assertEquals(0, count($p->getEventManager()->get('route.pre'))); }
$this->view = View::factory($this->viewPath . '/index.phtml', array('title' => 'Test Event', 'subtitle' => 'Home Page', 'content' => 'This is the home page')); $this->send(); } public function users() { $this->view = View::factory($this->viewPath . '/index.phtml', array('title' => 'Test Event', 'subtitle' => 'Users Page', 'content' => 'This is the users page')); $this->send(); } public function error() { $this->view = View::factory($this->viewPath . '/index.phtml', array('title' => 'Test Event', 'subtitle' => 'Error Page', 'content' => 'Page not found.')); $this->send(404); } } try { $project = new Project(null, null, new Router(array('/' => 'IndexController'))); $project->attachEvent('dispatch', function ($controller) { if ($controller->getRequest()->getRequestUri() == '/') { $controller->getView()->set('subtitle', 'This is the REVISED Home Page Subtitle.'); return 'Hello World! This is the home page!'; } }); $project->attachEvent('dispatch', function ($controller, $result) { if ($controller->getRequest()->getRequestUri() == '/') { $controller->getView()->set('content', $result); } }); $project->run(); } catch (\Exception $e) { echo $e->getMessage(); }