Esempio n. 1
0
 public function testDebugbar()
 {
     Debugbar::on("create", function ($debugbar) {
         echo "Debugbar created";
         $this->assertTrue(true);
         $this->assertFalse($debugbar->hasInfo('test'));
         $debugbar->registerInfo("test", "<h1>Works!</h1>");
         $this->assertTrue($debugbar->hasInfo('test'));
         $this->assertEquals("<h1>Works!</h1>", $debugbar->getInfo('test'));
         $debugbar->setInfo("test", "<h2>Works!</h2>");
         $this->assertEquals("<h2>Works!</h2>", $debugbar->getInfo('test'));
         $this->assertFalse($debugbar->hasTab('test'));
         $debugbar->registerTab("test", "<h1>Works!</h1>", "content");
         $this->assertTrue($debugbar->hasTab('test'));
         $this->assertEquals("<h1>Works!</h1>", $debugbar->getTabTitle('test'));
         $this->assertEquals("content", $debugbar->getTabContent('test'));
     });
     echo "Creating debugbar!";
     echo Debugbar::getInstance();
 }
Esempio n. 2
0
/**
 * Alternative zu var_dump mit formatierter HTML-Ausgabe.
 *
 * @param   mixed $var
 * @param  int $indentBy
 * @param  int $indentationLevel
 */
function dump($var, $desc = '', $indentBy = 2, $indentationLevel = 0)
{
    $stringStyle = 'color:#8cc152;';
    $propertyStyle = 'color:#967adc;';
    $classStyle = 'color:#f6bb42;';
    $nullStyle = 'color:#aab2bd;';
    $integerStyle = 'color:#e9573f;';
    $doubleStyle = 'color:#e9573f;';
    $boolStyle = 'color:#aab2bd;';
    $arrayStyle = '';
    $resourceStyle = '';
    $privateStyle = '';
    $unknownTypeStyle = '';
    if (PHP_SAPI == 'cli') {
        var_dump($var);
    } else {
        if (class_exists('\\Drips\\Debugbar\\Debugbar')) {
            $output = '';
            if (!empty($desc)) {
                $output .= '<h2 style="margin-top: 25px;">' . $desc . '</h2>';
            }
            if ($indentationLevel == 0) {
                $output .= '<pre style="background-color:#434a54;color:#f5f7fa;padding:1em;">' . PHP_EOL;
            }
            $parentIndentation = str_repeat(' ', $indentationLevel);
            $indentation = str_repeat(' ', $indentBy);
            if ($var === null) {
                $output .= '<span style="' . $nullStyle . '">NULL</span>' . PHP_EOL;
            } elseif (is_array($var)) {
                $array = (array) $var;
                $type = 'array';
                $len = sizeof($array);
                $output .= $type . ' (' . $len . ') ' . '{';
                if ($len > 0) {
                    $output .= PHP_EOL;
                    foreach ($array as $key => $value) {
                        $output .= $parentIndentation . $indentation . '[' . $key . '] =&gt; ';
                        $output .= dump($value, '', $indentBy, $indentationLevel + $indentBy);
                    }
                    $output .= $parentIndentation;
                }
                $output .= '}' . PHP_EOL;
            } elseif (is_object($var)) {
                $type = 'object';
                $reflect = new ReflectionClass($var);
                $properties = $reflect->getProperties();
                $len = sizeof($properties);
                $output .= $type . '<span style="' . $classStyle . '">(' . $reflect->getName() . ')</span>' . ' (' . $len . ') ' . '{' . PHP_EOL;
                foreach ($properties as $property) {
                    $property->setAccessible(true);
                    if (!$property->getValue($var) instanceof $var) {
                        $output .= $parentIndentation . $indentation . '<span style="' . $propertyStyle . '">[' . ($property->isStatic() ? 'static ' : '') . ($property->isPublic() ? 'public ' : ($property->isProtected() ? 'protected ' : ($property->isPrivate() ? 'private ' : ''))) . '$' . $property->getName() . ']</span> =&gt; ';
                        $output .= dump($property->getValue($var), '', $indentBy, $indentationLevel + $indentBy);
                    }
                }
                $output .= $parentIndentation . '}' . PHP_EOL;
            } elseif (is_string($var)) {
                $output .= gettype($var) . ' (' . strlen($var) . ') <span style="' . $stringStyle . '">"' . htmlentities($var) . '"</span>' . PHP_EOL;
            } elseif (is_bool($var)) {
                $output .= gettype($var) . ' <span style="' . $boolStyle . '">' . ($var == 1 ? 'true' : 'false') . '</span>' . PHP_EOL;
            } else {
                $type = gettype($var);
                $output .= $type . ' (' . sizeof($var) . ') <span style="' . ${str_replace(' t', 'T', gettype($var)) . 'Style'} . '">' . $var . '</span>' . PHP_EOL;
            }
            if ($indentationLevel == 0) {
                $output .= '</pre>';
                $instance = \Drips\Debugbar\Debugbar::getInstance();
                if (!array_key_exists('dump', $instance->getTabs())) {
                    $instance->registerTab('dump', 'Dump');
                }
                $instance->appendTab('dump', $output);
            }
            return $output;
        }
    }
}
Esempio n. 3
0
<?php

use Drips\Debugbar\Debugbar;
use Drips\HTTP\Request;
use Drips\HTTP\Response;
if (!defined('DRIPS_DEBUG')) {
    define('DRIPS_DEBUG', true);
}
if (class_exists('Drips\\App')) {
    Response::on('send', function ($response) {
        $request = Request::getInstance();
        if (in_array('text/html', $request->getAccept())) {
            $debugbar = Debugbar::getInstance();
            if ($debugbar->hasTabs()) {
                $debugbarString = $debugbar->__toString();
                $bodyTag = '</body>';
                if (strpos($response->body, $bodyTag) !== false) {
                    $response->body = str_replace($bodyTag, $debugbarString . $bodyTag, $response->body);
                } else {
                    $response->body .= $debugbarString;
                }
            }
        }
    });
}
Esempio n. 4
0
<?php

include "vendor/autoload.php";
error_reporting(E_ALL);
//use Drips\Debugger;
use Drips\Debugbar\Debugbar;
Debugbar::on("create", function ($bar) {
    $bar->registerTab("test", "TestTab", "<h1>Works!</h1>");
    $bar->appendTab("test", "<h1>Works!</h1>");
    $bar->registerTab("test", "TestTab", "<h1>Works!</h1>");
    $bar->registerTab("test2", "2. Tab", "<h1>Works ebenso!</h1>");
    $bar->registerTab("dumper", "Dump it", "<h1>lelelele ebenso!</h1>");
    //$bar->registerTab("dump", "dump", "<h1>lelelele ebenso!</h1>");
    $bar->appendTab("dumper", "<h1>Works!</h1>");
    $bar->registerInfo("currentdate", date("d.m.Y"));
    $bar->registerInfo("currentweek", date("W"));
    $bar->setInfo("currentdate", "neuer name info");
    $bar->setTabTitle("test", "neuer Name");
});
/*
$arr = array(['affe', 13]);
echo dump($arr);
dump("TEAST");
*/
echo Debugbar::getInstance();