Packages

  • dibi
    • drivers
    • nette
    • reflection
  • None
  • PHP

Classes

  • dibi
  • DibiConnection
  • DibiDataSource
  • DibiDateTime
  • DibiEvent
  • DibiFileLogger
  • DibiFirePhpLogger
  • DibiFluent
  • DibiObject
  • DibiResult
  • DibiResultIterator
  • DibiRow
  • DibiTranslator

Interfaces

  • IDataSource
  • IDibiDriver
  • IDibiReflector
  • IDibiResultDriver

Exceptions

  • DibiDriverException
  • DibiException
  • DibiNotImplementedException
  • DibiNotSupportedException
  • DibiPcreException
  • Overview
  • Package
  • Class
  • Tree
 1: <?php
 2: 
 3: /**
 4:  * This file is part of the "dibi" - smart database abstraction layer.
 5:  *
 6:  * Copyright (c) 2005 David Grudl (http://davidgrudl.com)
 7:  *
 8:  * For the full copyright and license information, please view
 9:  * the file license.txt that was distributed with this source code.
10:  */
11: 
12: 
13: 
14: /**
15:  * dibi FirePHP logger.
16:  *
17:  * @author     David Grudl
18:  * @package    dibi
19:  */
20: class DibiFirePhpLogger extends DibiObject
21: {
22:     /** maximum number of rows */
23:     static public $maxQueries = 30;
24: 
25:     /** maximum SQL length */
26:     static public $maxLength = 1000;
27: 
28:     /** @var int */
29:     public $filter;
30: 
31:     /** @var array */
32:     private static $fireTable = array(array('Time', 'SQL Statement', 'Rows', 'Connection'));
33: 
34: 
35: 
36:     /**
37:      * @return bool
38:      */
39:     public static function isAvailable()
40:     {
41:         return isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'FirePHP/');
42:     }
43: 
44: 
45: 
46:     public function __construct($filter = NULL)
47:     {
48:         $this->filter = $filter ? (int) $filter : DibiEvent::QUERY;
49:     }
50: 
51: 
52: 
53:     /**
54:      * After event notification.
55:      * @return void
56:      */
57:     public function logEvent(DibiEvent $event)
58:     {
59:         if (headers_sent() || ($event->type & $this->filter) === 0 || count(self::$fireTable) > self::$maxQueries) {
60:             return;
61:         }
62: 
63:         self::$fireTable[] = array(
64:             sprintf('%0.3f', $event->time * 1000),
65:             strlen($event->sql) > self::$maxLength ? substr($event->sql, 0, self::$maxLength) . '...' : $event->sql,
66:             $event->result instanceof Exception ? 'ERROR' : $event->count,
67:             $event->connection->getConfig('driver') . '/' . $event->connection->getConfig('name')
68:         );
69: 
70:         header('X-Wf-Protocol-dibi: http://meta.wildfirehq.org/Protocol/JsonStream/0.2');
71:         header('X-Wf-dibi-Plugin-1: http://meta.firephp.org/Wildfire/Plugin/FirePHP/Library-FirePHPCore/0.2.0');
72:         header('X-Wf-dibi-Structure-1: http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1');
73: 
74:         $payload = json_encode(array(
75:             array(
76:                 'Type' => 'TABLE',
77:                 'Label' => 'dibi profiler (' . dibi::$numOfQueries . ' SQL queries took ' . sprintf('%0.3f', dibi::$totalTime * 1000) . ' ms)',
78:             ),
79:             self::$fireTable,
80:         ));
81:         foreach (str_split($payload, 4990) as $num => $s) {
82:             $num++;
83:             header("X-Wf-dibi-1-1-d$num: |$s|\\"); // protocol-, structure-, plugin-, message-index
84:         }
85:         header("X-Wf-dibi-1-1-d$num: |$s|");
86:     }
87: 
88: }
89: 
dibi API documentation API documentation generated by ApiGen 2.3.0