Example #1
0
 /**
  * Loads the template view object
  *
  * @return	void
  */
 public function before()
 {
     if ($this->template === NULL) {
         // Load the template
         $this->template = $this->template_name($this->request->controller(), $this->request->action());
     }
     $this->template = Twig_View::factory($this->template);
     // run parent before method after twig is loaded
     // so template is avaiable to entire application
     parent::before();
 }
Example #2
0
    public function any_handler()
    {
        $this->template('any');
    }
    // Add a custom header
    public function add_header()
    {
        echo '<h1>My custom header</h1>';
    }
    // Output a template
    protected function template($template)
    {
        include dirname(__FILE__) . "/templates/{$template}.html";
    }
}
// Create the instance
$app = new Application();
// Run a before filter
$app->before('get_info', 'add_header');
// Link up the urls
$app->get('', 'get_index');
$app->get('info', 'get_info');
$app->get('json', 'get_json');
$app->get('xml', 'get_xml');
$app->get('redirect', 'get_redirect');
$app->get('page/<page>', 'get_page');
$app->any('any', 'any_handler');
$app->get('page/<page:\\d{4}>/<id>', 'get_page');
$app->get('page/<page:.*>', 'get_page');
// Run the application
$app->run();
Example #3
0
 public function testBeforeApplicationFiltersShouldBeCalledBeforeRouteExecution()
 {
     $app = new Application();
     $app->get('/test', function (Response $response) {
         $response->appendContents('route');
     });
     $app->before(function (Response $response) {
         $response->appendContents('before1');
     });
     $app->before(function (Response $response) {
         $response->appendContents('before2');
     });
     $response = new ResponseMock();
     $app->run(Request::create(false, 'localhost', '/test'), $response);
     $this->assertEquals('before1before2route', $response->contents());
 }
Example #4
0
 /**
  *
  *
  *
  */
 public function before()
 {
     $this->template = new Json('json:');
     parent::before();
 }