예제 #1
0
 /**
  * Based on Twig_Extension_Debug / twig_var_dump
  * (c) 2011 Fabien Potencier
  *
  * @param Twig_Environment $env
  * @param $context
  *
  * @return string
  */
 public function dump(Twig_Environment $env, $context)
 {
     $output = '';
     $count = func_num_args();
     if (2 === $count) {
         $data = array();
         foreach ($context as $key => $value) {
             if (is_object($value)) {
                 if (method_exists($value, 'toArray')) {
                     $data[$key] = $value->toArray();
                 } else {
                     $data[$key] = "Object (" . get_class($value) . ")";
                 }
             } else {
                 $data[$key] = $value;
             }
         }
         $output .= $this->formatter->formatVar($data);
     } else {
         for ($i = 2; $i < $count; $i++) {
             $output .= $this->formatter->formatVar(func_get_arg($i));
         }
     }
     return '<pre>' . $output . '</pre>';
 }
 public function testFormatBytes()
 {
     $f = new DataFormatter();
     $this->assertEquals("0B", $f->formatBytes(0));
     $this->assertEquals("1B", $f->formatBytes(1));
     $this->assertEquals("1KB", $f->formatBytes(1024));
     $this->assertEquals("1MB", $f->formatBytes(1024 * 1024));
 }
예제 #3
0
 /**
  * Test collect config, format var, order config
  */
 public function testCollect()
 {
     $config = new Config();
     $config->set('foo', 'bar');
     $config->set('bar', 'foo');
     $configDataCollector = new ConfigDataCollector($config);
     $dataFormatter = new DataFormatter();
     $this->assertEquals(array('bar' => $dataFormatter->formatVar('foo'), 'foo' => $dataFormatter->formatVar('bar')), $configDataCollector->collect());
 }
예제 #4
0
 public function testCollect()
 {
     $params = array('controller' => 'My\\Simple\\Controller', 'action' => 'index', 'route' => '/my_route', 'params' => array('id' => 12));
     $rEvent = new RouteEvent('/my_route', $params);
     $params2 = array('controller' => 'My\\Internal\\Controller', 'action' => 'show', 'route' => '/my_internal_route', 'params' => array('id' => 12));
     $rEvent2 = new RouteEvent('/my_internal_route', $params2);
     $dbcollector = new RouteDataCollector();
     $dbcollector->onRouteMatch($rEvent);
     $dbcollector->onRouteMatch($rEvent2);
     $dataFormatter = new DataFormatter();
     $this->assertEquals(array(0 => $dataFormatter->formatVar(array('Route match' => $params)), 1 => $dataFormatter->formatVar(array('Route match' => $params2))), $dbcollector->collect());
 }
예제 #5
0
 public function testCollect()
 {
     $query = 'SELECT * FROM MY_TABLE';
     $data = array('my resultSET');
     $executionTime = 0.12;
     $dbEvent = new DatabaseEvent($query, $executionTime, $data);
     $dbcollector = new DatabaseDataCollector();
     $dbcollector->onPostQueryExecute($dbEvent);
     $dbcollector->onPostQueryExecute($dbEvent);
     $dataFormatter = new DataFormatter();
     $this->assertEquals(array(0 => $dataFormatter->formatVar(array('query' => $query, 'data' => $data)), 1 => $dataFormatter->formatVar(array('query' => $query, 'data' => $data))), $dbcollector->collect());
 }
예제 #6
0
 public function testCollect()
 {
     $loadCacheEvent = new CacheEvent(new CacheableData('my_cache_key', 86400, 'test'));
     $removeCacheEvent = new CacheEvent(new CacheableData('my_cache_key_remove', 86400, 'other test'));
     $setCacheEvent = new CacheEvent(new CacheableData('my_cache_key_set', 86400, 'test'));
     $collector = new CacheDataCollector();
     $collector->onCacheLoad($loadCacheEvent);
     // Test double load same cache
     $collector->onCacheLoad($loadCacheEvent);
     $collector->onCacheSet($setCacheEvent);
     // Test double set same cache
     $collector->onCacheSet($setCacheEvent);
     $collector->onCacheRemove($removeCacheEvent);
     // Test double remove same cache
     $collector->onCacheRemove($removeCacheEvent);
     $dataFormatter = new DataFormatter();
     $result = array('general' => $dataFormatter->formatVar(array('Cache count' => 3, 'Cache load' => 2, 'Cache remove' => 2, 'Cache set' => 2, 'Cache size (bytes) ' => 16)), 'my_cache_key' => $dataFormatter->formatVar(array('name' => 'my_cache_key', 'load' => 2, 'set' => 0, 'remove' => 0, 'size' => 4)), 'my_cache_key_remove' => $dataFormatter->formatVar(array('name' => 'my_cache_key_remove', 'load' => 0, 'set' => 0, 'remove' => 2, 'size' => 0)), 'my_cache_key_set' => $dataFormatter->formatVar(array('name' => 'my_cache_key_set', 'load' => 0, 'set' => 2, 'remove' => 0, 'size' => 4)));
     $this->assertEquals($result, $collector->collect());
 }
 /**
  * Transforms a PHP variable to a string representation.
  *
  * @param mixed $data The data to format.
  *
  * @return string.
  */
 public function formatVar($data)
 {
     $result = parent::formatVar($data);
     $result = str_replace(array('[[', ']]', '{{', '}}'), array('&#91;&#91;', '&#93;&#93;', '&#123;&#123;', '&#124;&#124;'), $result);
     return $result;
 }