Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 28th, 2012  |  syntax: None  |  size: 2.04 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2.  
  3. /**
  4.  * General info:
  5.  *              Embed this code in your lithium (li3) app.
  6.  *              At the end of the app\config\connections.php for example.
  7.  *
  8.  *              Uncomment the var_dump lines OR use the lithium Logger Class
  9.  *              Use/modify the first callback, if you just want to see the query array data.
  10.  *              Use the second callback for dumping the raw sql data.
  11.  *
  12.  * @author: 2011 weluse GmbH, Marc Schwering
  13.  */
  14. use lithium\data\Connections;
  15. use lithium\analysis\Logger;
  16. use lithium\action\Dispatcher;
  17. use lithium\core\Environment;
  18.  
  19. Logger::config(array(
  20.     'default' => array('adapter' => 'FirePhp'),
  21. ));
  22.  
  23. Dispatcher::applyFilter('_call', function($self, $params, $chain) {
  24.     if (isset($params['callable']->response)) {
  25.         Logger::adapter('default')->bind($params['callable']->response);
  26.     }
  27.     return $chain->next($self, $params, $chain);
  28. });
  29.  
  30. Connections::get("default")->applyFilter("read", function($self, $params, $chain) {
  31.         $response = $chain->next($self, $params, $chain);
  32.         if (is_a($params['query'], 'lithium\data\model\Query')) {
  33.                 /**
  34.                  * dump the query-object-data as array:
  35.                  */
  36.                 //var_dump($params['query']->export($self));
  37.  
  38.                 /**
  39.                  * dump the result:
  40.                  */
  41.                 //var_dump($res->data());
  42.         } //
  43.     return $response;
  44. });
  45.  
  46.  
  47. Connections::get('default')->applyFilter("_execute", function($self, $params, $chain) {
  48.         $response = $chain->next($self, $params, $chain);
  49.         if (!Environment::is('production')) {
  50.                 Logger::info(print_r($params['sql'],true));
  51.         }
  52.         return $response;
  53. });
  54.  
  55. Connections::get('another_db')->applyFilter("_execute", function($self, $params, $chain) {
  56.         $response = $chain->next($self, $params, $chain);
  57.         if (!Environment::is('production')) {
  58.                 Logger::info(print_r($params['sql'],true));
  59.         }
  60.         return $response;
  61. });
  62.  
  63. /**
  64.  * Inspect the message, and do a string conversion via print_r
  65.  *
  66.  * @author: 2011 weluse GmbH, Marc Schwering
  67.  */
  68. Logger::applyFilter('write', function ($self, $params, $chain){
  69.         $var = $params['message'];
  70.         if(is_array($var) || is_object($var)){
  71.                 $params['message'] = print_r($var,true);
  72.         }
  73.         return $chain->next($self, $params, $chain);
  74. });
  75.  
  76. ?>