Ignore:
Timestamp:
08/29/10 18:30:31 (21 months ago)
Author:
vain
Message:
  • clansuite doctrine profiler is now called statically
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/core/debug/doctrineprofiler.core.php

    r4599 r4607  
    4747class Clansuite_Doctrine_Profiler 
    4848{ 
    49     public function __construct() 
    50     { 
    51         $this->connection = Doctrine_Manager::connection(); 
    52     } 
    53      
    5449    /** 
    5550     * Returns Doctrine's connection profiler 
     
    5752     * @return Doctrine_Connection_Profiler 
    5853     */ 
    59     public function getProfiler() 
     54    public static function getProfiler() 
    6055    { 
    61         return $this->connection->getListener(); 
     56        return Doctrine_Manager::connection()->getListener(); 
    6257    } 
    6358 
     
    6560     * Attached the Doctrine Profiler as Listener to the connection 
    6661     */ 
    67     public function attachProfiler() 
     62    public static function attachProfiler() 
    6863    { 
    6964        # instantiate Profiler and attach to doctrine connection 
    70         $this->connection->setListener(new Doctrine_Connection_Profiler); 
    71          
    72         register_shutdown_function(array($this,'shutdown'));   
     65        Doctrine_Manager::connection()->setListener(new Doctrine_Connection_Profiler); 
     66 
     67        register_shutdown_function('Clansuite_Doctrine_Profiler::shutdown'); 
    7368    } 
    7469 
     
    7974     * @return Direct HTML Output 
    8075     */ 
    81     public function displayProfilingHTML() 
     76    public static function displayProfilingHTML() 
    8277    { 
    8378        /** 
     
    8580         */ 
    8681        $query_counter = 0; 
     82 
    8783        /** 
    8884         * @var int time in seconds, counting the elapsed time for all queries 
     
    9086        $time = 0; 
    9187 
    92  
    93         echo '<!-- Disable Debug Mode to remove this!--> 
     88        $html = ''; 
     89        $html .= '<!-- Disable Debug Mode to remove this!--> 
    9490              <style type="text/css"> 
    9591              /*<![CDATA[*/ 
     
    126122                </style>'; 
    127123 
    128         echo '<p>&nbsp;</p><fieldset class="doctrine-profiler"><legend>Debug Console for Doctrine Queries</legend>'; 
    129         echo '<table class="doctrine-profiler" width="95%">'; 
    130         echo '<tr> 
     124        $html .= '<p>&nbsp;</p><fieldset class="doctrine-profiler"><legend>Debug Console for Doctrine Queries</legend>'; 
     125        $html .= '<table class="doctrine-profiler" width="95%">'; 
     126        $html .= '<tr> 
    131127                <th>Query Counter</th> 
    132128                <th>Command</th> 
     
    136132              </tr>'; 
    137133 
    138         foreach ( $this->getProfiler() as $event ) 
     134        foreach(self::getProfiler() as $event) 
    139135        { 
    140136            /** 
     
    155151            $time += $event->getElapsedSecs(); 
    156152 
    157             echo '<tr>'; 
    158             echo '<td style="text-align: center;">' . $query_counter . '</td>'; 
    159             echo '<td style="text-align: center;">' . $event->getName() . '</td>'; 
    160             echo '<td>' . sprintf('%f', $event->getElapsedSecs() ) . '</td>'; 
    161             echo '<td>' . $event->getQuery() . '</td>'; 
     153            $html .= '<tr>'; 
     154            $html .= '<td style="text-align: center;">' . $query_counter . '</td>'; 
     155            $html .= '<td style="text-align: center;">' . $event->getName() . '</td>'; 
     156            $html .= '<td>' . sprintf('%f', $event->getElapsedSecs()) . '</td>'; 
     157            $html .= '<td>' . $event->getQuery() . '</td>'; 
     158 
    162159            $params = $event->getParams(); 
    163             if ( empty($params) == false) 
     160            if(empty($params) == false) 
    164161            { 
    165                   echo '<td>'; 
    166                   echo wordwrap(join(', ', $params),150,"\n",true); 
    167                   echo '</td>'; 
     162                $html .= '<td>'; 
     163                $html .= wordwrap(join(', ', $params), 150, "\n", true); 
     164                $html .= '</td>'; 
    168165            } 
    169166            else 
    170167            { 
    171                   echo '<td>'; 
    172                   echo '&nbsp;'; 
    173                   echo '</td>'; 
     168                $html .= '<td>'; 
     169                $html .= '&nbsp;'; 
     170                $html .= '</td>'; 
    174171            } 
    175             echo '</tr>'; 
     172 
     173            $html .= '</tr>'; 
    176174        } 
    177         echo '</table>'; 
    178         echo '<p style="font-weight: bold;">&nbsp; &raquo; &nbsp; '.$query_counter.' statements in ' . sprintf('%2.5f', $time) . ' secs.</p>'; 
    179         echo '</fieldset>'; 
     175 
     176        $html .= '</table>'; 
     177        $html .= '<p style="font-weight: bold;">&nbsp; &raquo; &nbsp; '.$query_counter.' statements in ' . sprintf('%2.5f', $time) . ' secs.</p>'; 
     178        $html .= '</fieldset>'; 
     179 
     180        echo $html; 
    180181    } 
    181182 
     
    183184     * shutdown function for register_shutdown_function 
    184185     */ 
    185     public function shutdown() 
     186    public static function shutdown() 
    186187    { 
    187188        # append Doctrine's SQL-Profiling Report 
    188         $this->displayProfilingHTML(); 
     189        self::displayProfilingHTML(); 
    189190 
    190191        # save session before exit 
Note: See TracChangeset for help on using the changeset viewer.