/**
  * Registers services on the given app.
  *
  * This method should only be used to configure services and parameters.
  * It should not get services.
  *
  * @param Application $app An Application instance
  */
 public function register(Application $app)
 {
     $app['ladybug.options'] = array('theme' => 'modern', 'expanded' => false, 'silenced' => false, 'array_max_nesting_level' => 9, 'object_max_nesting_level' => 3);
     $app['ladybug.dumper'] = $app->share(function () use($app) {
         $dumper = new Dumper();
         $dumper->setOptions($app['ladybug.options']);
         return $dumper;
     });
     $app['ladybug'] = $app->share(function () use($app) {
         return new LadybugDataCollector($app['ladybug.dumper']);
     });
     $app['twig'] = $app->share($app->extend('twig', function (\Twig_Environment $twig, $app) {
         $twig->addExtension(new LadybugExtension($app));
         return $twig;
     }));
     if (isset($app['profiler'])) {
         $app['twig.loader.filesystem'] = $app->share($app->extend('twig.loader.filesystem', function ($loader, $app) {
             $loader->addPath($app['rswork.templates_path'], 'Rswork');
             return $loader;
         }));
         $app['rswork.templates_path'] = function () {
             return realpath(__DIR__ . '/../../views');
         };
         $app['data_collector.templates'] = array_merge($app['data_collector.templates'], array(array('ladybug', '@Rswork/collector/ladybug.html.twig')));
         $app['data_collectors'] = $app->share($app->extend('data_collectors', function ($collectors, $app) {
             $collectors['ladubug'] = $app->share(function ($app) {
                 return $app['ladybug'];
             });
             return $collectors;
         }));
     }
 }
Ejemplo n.º 2
0
 public function testDumpXmlFormat()
 {
     if (!class_exists('\\JMS\\Serializer\\SerializerBuilder')) {
         $this->markTestSkipped('Serializer is not available.');
     }
     $var = 1;
     $this->dumper->setFormat(Format\XmlFormat::FORMAT_NAME);
     $dump = new \SimpleXMLElement($this->dumper->dump($var));
     $this->assertEquals(1, $dump->entry->count());
     $this->assertEquals('int', $dump->entry[0]['type']);
     $this->assertEquals('1', $dump->entry[0]->value);
 }
Ejemplo n.º 3
0
 /**
  * Log an info.
  */
 public function log()
 {
     $ladybug = \Ladybug\Dumper::getInstance();
     $content = call_user_func_array(array($ladybug, 'dump'), func_get_args());
     $trace = debug_backtrace();
     $this->data['vars'][] = array('file' => isset($trace[0]['file']) ? $trace[0]['file'] : '', 'line' => isset($trace[0]['line']) ? $trace[0]['line'] : '', 'content' => $content);
 }
 public function testLogDataWorksAsExpected()
 {
     $this->dumper->shouldReceive('dump')->once()->withArgs(array('#foo#', '#bar#'))->andReturn('#html#');
     $this->dumper->shouldReceive('dump')->once()->withArgs(array('#foo2#', '#bar2#'))->andReturn('#html2#');
     $ladybugDataCollector = new LadybugDataCollector($this->dumper);
     $ladybugDataCollector->log('#foo#', '#bar#');
     $ladybugDataCollector->log('#foo2#', '#bar2#');
     $collectedVars = $ladybugDataCollector->getVars();
     $this->assertCount(2, $collectedVars);
     foreach ($collectedVars as $collected) {
         $this->assertArrayHasKey('file', $collected);
         $this->assertArrayHasKey('line', $collected);
         $this->assertArrayHasKey('content', $collected);
     }
     $this->assertEquals('#html#', $collectedVars[0]['content']);
     $this->assertEquals('#html2#', $collectedVars[1]['content']);
 }
Ejemplo n.º 5
0
 /**
  * Getter.
  *
  * @return string
  */
 public function ladybug_dump()
 {
     $ladybug = \Ladybug\Dumper::getInstance();
     $html = call_user_func_array(array($ladybug, 'dump'), func_get_args());
     return $html;
 }
 /**
  * Main constructor
  *
  * @param Dumper $ladybug Ladybyg Dumper
  */
 public function __construct(Dumper $ladybug)
 {
     $this->ladybug = $ladybug;
     $this->ladybug->setFormat('html');
 }
Ejemplo n.º 7
0
 protected function renderTreeSwitcher($label, $array_key = NULL)
 {
     $tree_id = \Ladybug\Dumper::getTreeId();
     $result = '<label for="tree_' . $this->type . '_' . $tree_id . '">';
     $result .= $this->renderArrayKey($array_key);
     $result .= '<span class="switcher">' . $label . '</span>';
     $result .= '</label>';
     $result .= '<input type="checkbox" id="tree_' . $this->type . '_' . $tree_id . '"';
     if ($this->options->getOption('general.expanded')) {
         $result .= ' checked';
     }
     $result .= ' />';
     return $result;
 }
 public function testLadybugDumpWorksAsExpectedInsideTwigExtension()
 {
     $this->dumper->shouldReceive('dump')->once()->withArgs(array('#foo#', '#bar#'))->andReturn('#html#');
     $ladybugExtension = new LadybugExtension($this->dumper);
     $this->assertEquals('#html#', $ladybugExtension->ladybug_dump('#foo#', '#bar#'));
 }
Ejemplo n.º 9
0
function ladybug_dump_return()
{
    $ladybug = \Ladybug\Dumper::getInstance();
    $result = call_user_func_array(array($ladybug, 'export'), func_get_args());
    return $result;
}