Skip to content

Instantly share code, notes, and snippets.

@harikt
Last active August 29, 2015 14:04
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save harikt/68133164cd76ec55559b to your computer and use it in GitHub Desktop.
<?php
public function modify($di)
{
$signal = $di->get('signal_manager');
$signal->handler('*', 'before_router', function ($obj) {
$cache = dirname(__DIR__) . '/tmp/cache/' . str_replace('/', 'g5', $obj->router->request->url->get(PHP_URL_PATH));
if (is_file($cache) && $obj->router->request->method->isGet()) {
$contents = file_get_contents($cache);
$sender = unserialize($contents);
$sender->__invoke();
exit;
}
});
$signal->handler('*', 'before_dispatcher', function ($obj) {
// do what you love
});
$signal->handler('*', 'before_response', function ($obj) {
if ($obj->router->request->params['action'] != 'aura.asset' && $obj->router->request->method->isGet()) {
$cache = dirname(__DIR__) . '/tmp/cache/' . str_replace('/', 'g5', $obj->router->request->url->get(PHP_URL_PATH));
file_put_contents($cache, serialize($obj->response_sender));
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment