{ if ($this->identity()->anonymous()) { throw new k_NotAuthorized(); } return parent::dispatch(); } function renderHtml() { return sprintf("<p>Hello %s, anon=%s</p>", htmlspecialchars($this->identity()->user()), $this->identity()->anonymous() ? 't' : 'f') . sprintf("<form method='post' action='%s'><p><input type='submit' value='Log out' /></p></form>", htmlspecialchars($this->url('/logout'))) . sprintf("<p><a href='%s'>the dojo</a></p>", htmlspecialchars($this->url('dojo'))); } } class DojoController extends k_Component { function dispatch() { if ($this->identity()->user() != 'ninja') { throw new k_Forbidden(); } return parent::dispatch(); } function renderHtml() { return "Welcome to the dojo, where only ninjas are allowed"; } } if (realpath($_SERVER['SCRIPT_FILENAME']) == __FILE__) { $components = new k_DefaultComponentCreator(); $components->setImplementation('k_DefaultNotAuthorizedComponent', 'NotAuthorizedComponent'); $identity_loader = new k_SessionIdentityLoader(); k()->setComponentCreator($components)->setIdentityLoader($identity_loader)->run('Root')->out(); }
function createBrowser() { $components = new k_DefaultComponentCreator(); $components->setImplementation('k_DefaultNotAuthorizedComponent', 'NotAuthorizedComponent'); return new k_VirtualSimpleBrowser('Root', $components, null, new k_SessionIdentityLoader()); }