Skip to content

Instantly share code, notes, and snippets.

@agborkowski
Last active December 20, 2015 05:49
Show Gist options
  • Save agborkowski/6081551 to your computer and use it in GitHub Desktop.
Save agborkowski/6081551 to your computer and use it in GitHub Desktop.
#li3 #lithium #php logging sql queries
<?php
if (!Environment::is('production')) {
// Attach to the `Connections` adapters after dispatch.
Filters::apply('\lithium\action\Dispatcher', '_callable', function($self, $params, $chain) {
/**
* Loop over all defined `Connections` adapters and tack in our
* filter on the `_execute` method.
*/
foreach (Connections::get() as $connection) {
$connection = Connections::get($connection);
// $connection->applyFilter(['read', 'create', 'update', 'delete'], function($self, $params, $chain) {
// if ($result = $chain->next($self, $params, $chain)) {
// //Profiler::start($response->model());if($)
// if(is_string($params['query'])) {
// $queries[] = $params['query'];
// }
// if(method_exists($result, 'data')) {
// $queries[] = $result->result()->resource()->queryString;
// }
// }
// if (isset($queries) && is_array($queries)) {
// $message = implode("\r\n", $queries);
// }
// return $result;
// });
$connection->applyFilter('_execute', function($self, $params, $chain) {
$message = $params['sql'];
Logger::debug($message);
$message = urlencode($message);
shell_exec('curl "http://localhost:1337/info?title=App&group=1&message=' . $message .'"');
return $chain->next($self, $params, $chain);
});
}
// Return the controller.
return $chain->next($self, $params, $chain);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment