Exemplo n.º 1
0
 /**
  * The Autoloader initialisation
  *
  * @return void
  */
 public static function _init()
 {
     // is the profiler enabled?
     if (!(static::$_enabled = ClanCats::$config->get('profiler.enabled'))) {
         return;
     }
     // enable profiling only in development mode
     if (ClanCats::in_development()) {
         // add a hook to the resposne so that we can
         // append a table with the profiler data to the body
         CCEvent::mind('response.output', function ($output) {
             if (strpos($output, '</body>') === false) {
                 return $output;
             }
             $table = \UI\Table::create(array('style' => array('width' => '100%'), 'cellpadding' => '5', 'class' => 'table debug-table debug-table-profiler'));
             $table->header(array('#', 'message', 'memory', 'time'));
             foreach (\CCProfiler::data() as $key => $item) {
                 $table->row(array($key + 1, $item[0], $item[1], $item[2]));
             }
             // add the table before the body end
             return str_replace('</body>', $table . "\n</body>", $output);
         });
         // also add an error inspector hook so that we can access the
         // profiler data in the error handler
         CCError_Inspector::info_callback('Profiler', function () {
             $table = array();
             foreach (\CCProfiler::data() as $key => $check) {
                 $table['#' . ($key + 1) . ': ' . $check[2]] = $check[0];
             }
             return $table;
         });
     }
 }
Exemplo n.º 2
0
 /**
  * CCProfiler::check tests
  */
 public function test_enable_disable()
 {
     $checks = count(CCProfiler::data());
     CCProfiler::check('check 1');
     $this->assertEquals(count(CCProfiler::data()), $checks + 1);
     CCProfiler::disable();
     CCProfiler::check('check 2');
     $this->assertEquals(count(CCProfiler::data()), $checks + 1);
     CCProfiler::enable();
     CCProfiler::check('check 3');
     $this->assertEquals(count(CCProfiler::data()), $checks + 2);
 }