Skip to content

Instantly share code, notes, and snippets.

@andersonfraga
Created November 20, 2012 13:31
Show Gist options
  • Save andersonfraga/4117950 to your computer and use it in GitHub Desktop.
Save andersonfraga/4117950 to your computer and use it in GitHub Desktop.
Devaneios. Microframework baseado no Zend2
<?php
use Picoznd/Session;
use Picoznd/Http/Request;
use Picoznd/Http/Response;
use Picoznd/Http/Response/CacheControl;
use Picoznd/IoC/Inject/Bag as InjectBag;
use Picoznd/Http/Request/Params as ParamsBag;
class Index
{
function __construct(Session $session, Response $response) {
$this->session = $session;
$this->response = $response;
}
public function get(CacheControl $cache, InjectBag $inject) {
$this->response['content_type'] = array('html', 'xml');
$cache->setPublic()->setMustRevalidate()->setMaxAge(60);
return $inject['news']->getLastCreated(30);
}
};
class News
{
function __construct(Response $response, ParamsBag $param) {
$this->response = $response;
$param->validate('slug', '[a-z0-9\_]', 'get');
/** OR **/
$param->sanitize('slug', function($val) {
return preg_replace('/[a-z0-9\_]+/', '$1', $val);
}, 'get');
}
public function get($slug, CacheControl $cache, InjectBag $inject) {
$this->response['content_type'] = array('html', 'xml');
$cache->setPublic()->setMustRevalidate()->setMaxAge(60);
return $inject['news']->getBySlug($slug);
}
};
/** **/
$app = new Picoznd();
$app->mount(new Index, null, true); // true sets default
$app->mount(new News, '/news_pt'); // if route != 'news' (classname)
$app->run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment