Skip to content

Commit

Permalink
Added minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
mariuszkrzaczkowski committed Mar 22, 2018
1 parent adfc6e9 commit 52825aa
Show file tree
Hide file tree
Showing 51 changed files with 1,087 additions and 1,040 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
composer.lock
/vendor
/src/DebugBar/Resources/vendor
/src/DebugBar/Resources/vendor
/nbproject/private/
10 changes: 4 additions & 6 deletions build/namespaceFontAwesome.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@
$path = __DIR__ . '/../src/DebugBar/Resources/vendor/font-awesome/css/font-awesome.min.css';
$contents = file_get_contents($path);

if (strpos($contents, 'PhpDebugbarFontAwesome') !== false ){
exit('Already namespaced');
if (strpos($contents, 'PhpDebugbarFontAwesome') !== false) {
exit('Already namespaced');
}

// namespace FontAwesome occurrences
$contents = str_replace(['FontAwesome', 'fa-', '.fa'], ['PhpDebugbarFontAwesome', 'phpdebugbar-fa-', '.phpdebugbar-fa'], $contents);

if (file_put_contents($path, $contents)) {
echo "Updated font-awesome.min.css";
echo 'Updated font-awesome.min.css';
} else {
echo "No content written";
echo 'No content written';
}


6 changes: 3 additions & 3 deletions demo/ajax_exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
include 'bootstrap.php';

try {
throw new Exception('Something failed!');
throw new Exception('Something failed!');
} catch (Exception $e) {
$debugbar['exceptions']->addException($e);
$debugbar['exceptions']->addException($e);
}

?>
error from AJAX
<?php
echo $debugbarRenderer->render(false);
echo $debugbarRenderer->render(false);
?>
16 changes: 8 additions & 8 deletions demo/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

$debugbar = new StandardDebugBar();
$debugbarRenderer = $debugbar->getJavascriptRenderer()
->setBaseUrl('../src/DebugBar/Resources')
->setEnableJqueryNoConflict(false);
->setBaseUrl('../src/DebugBar/Resources')
->setEnableJqueryNoConflict(false);

//
// create a writable profiles folder in the demo directory to uncomment the following lines
Expand All @@ -21,11 +21,10 @@

function render_demo_page(Closure $callback = null)
{
global $debugbarRenderer;
?>
global $debugbarRenderer; ?>
<html>
<head>
<?php echo $debugbarRenderer->renderHead() ?>
<?php echo $debugbarRenderer->renderHead(); ?>
<script type="text/javascript">
$(function() {
$('.ajax').click(function() {
Expand All @@ -41,10 +40,11 @@ function render_demo_page(Closure $callback = null)
<body>
<h1>DebugBar Demo</h1>
<p>DebugBar at the bottom of the page</p>
<?php if ($callback) $callback(); ?>
<?php if ($callback) {
$callback();
} ?>
<?php
echo $debugbarRenderer->render();
?>
echo $debugbarRenderer->render(); ?>
</body>
</html>
<?php
Expand Down
15 changes: 8 additions & 7 deletions demo/bridge/doctrine/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
<?php

// bootstrap.php
use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Tools\Setup;

require_once "vendor/autoload.php";
require_once 'vendor/autoload.php';

// Create a simple "default" Doctrine ORM configuration for Annotations
$isDevMode = true;
$config = Setup::createAnnotationMetadataConfiguration(array(__DIR__."/src"), $isDevMode);
$config = Setup::createAnnotationMetadataConfiguration([__DIR__ . '/src'], $isDevMode);
// or if you prefer yaml or XML
//$config = Setup::createXMLMetadataConfiguration(array(__DIR__."/config/xml"), $isDevMode);
//$config = Setup::createYAMLMetadataConfiguration(array(__DIR__."/config/yaml"), $isDevMode);

// database configuration parameters
$conn = array(
'driver' => 'pdo_sqlite',
'path' => __DIR__ . '/db.sqlite',
);
$conn = [
'driver' => 'pdo_sqlite',
'path' => __DIR__ . '/db.sqlite',
];

// obtaining the entity manager
$entityManager = EntityManager::create($conn, $config);
11 changes: 6 additions & 5 deletions demo/bridge/doctrine/cli-config.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?php

// cli-config.php
require_once "bootstrap.php";
require_once 'bootstrap.php';

$em = $entityManager;
$helperSet = new \Symfony\Component\Console\Helper\HelperSet(array(
'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($em->getConnection()),
'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($em)
));
$helperSet = new \Symfony\Component\Console\Helper\HelperSet([
'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($em->getConnection()),
'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($em)
]);
2 changes: 1 addition & 1 deletion demo/bridge/doctrine/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
$debugbar->addCollector(new DebugBar\Bridge\DoctrineCollector($debugStack));

$product = new Demo\Product();
$product->setName("foobar");
$product->setName('foobar');

$entityManager->persist($product);
$entityManager->flush();
Expand Down
34 changes: 17 additions & 17 deletions demo/bridge/doctrine/src/Demo/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@

/**
* @Entity @Table(name="products")
**/
*/
class Product
{
/** @Id @Column(type="integer") @GeneratedValue **/
protected $id;
/** @Column(type="string") **/
protected $name;
/** @Id @Column(type="integer") @GeneratedValue */
protected $id;
/** @Column(type="string") */
protected $name;

public function getId()
{
return $this->id;
}
public function getId()
{
return $this->id;
}

public function getName()
{
return $this->name;
}
public function getName()
{
return $this->name;
}

public function setName($name)
{
$this->name = $name;
}
public function setName($name)
{
$this->name = $name;
}
}
2 changes: 1 addition & 1 deletion demo/bridge/propel/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
$debugbar->addCollector(new PropelCollector());

Propel::init('build/conf/demo-conf.php');
set_include_path("build/classes" . PATH_SEPARATOR . get_include_path());
set_include_path('build/classes' . PATH_SEPARATOR . get_include_path());

PropelCollector::enablePropelProfiling();

Expand Down
4 changes: 2 additions & 2 deletions demo/bridge/slim/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

$app = new \Slim\Slim();
$app->get('/', function () use ($app) {
$app->getLog()->info('hello world');
render_demo_page();
$app->getLog()->info('hello world');
render_demo_page();
});

$debugbar->addCollector(new DebugBar\Bridge\SlimCollector($app));
Expand Down
7 changes: 3 additions & 4 deletions demo/bridge/swiftmailer/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@
$debugbar->addCollector(new SwiftMailCollector($mailer));

$message = Swift_Message::newInstance('Wonderful Subject')
->setFrom(array('john@doe.com' => 'John Doe'))
->setTo(array('receiver@domain.org', 'other@domain.org' => 'A name'))
->setBody('Here is the message itself');
->setFrom(['john@doe.com' => 'John Doe'])
->setTo(['receiver@domain.org', 'other@domain.org' => 'A name'])
->setBody('Here is the message itself');

$mailer->send($message);


render_demo_page();
4 changes: 2 additions & 2 deletions demo/bridge/twig/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@

$debugbar->addCollector(new DebugBar\Bridge\Twig\TwigCollector($twig));

render_demo_page(function() use ($twig) {
echo $twig->render('hello.html', array('name' => 'peter pan'));
render_demo_page(function () use ($twig) {
echo $twig->render('hello.html', ['name' => 'peter pan']);
});
12 changes: 6 additions & 6 deletions demo/dump_assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
include 'bootstrap.php';

if (!isset($_GET['type'])) {
$_GET['type'] = 'js';
$_GET['type'] = 'js';
}

if ($_GET['type'] == 'css') {
header('content-type', 'text/css');
$debugbarRenderer->dumpCssAssets();
} else if ($_GET['type'] == 'js') {
header('content-type', 'text/javascript');
$debugbarRenderer->dumpJsAssets();
header('content-type', 'text/css');
$debugbarRenderer->dumpCssAssets();
} elseif ($_GET['type'] == 'js') {
header('content-type', 'text/javascript');
$debugbarRenderer->dumpJsAssets();
}
6 changes: 3 additions & 3 deletions demo/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
$debugbar['time']->stopMeasure('op2');

$debugbar['messages']->addMessage('world', 'warning');
$debugbar['messages']->addMessage(array('toto' => array('titi', 'tata')));
$debugbar['messages']->addMessage(['toto' => ['titi', 'tata']]);
$debugbar['messages']->addMessage('oups', 'error');

$debugbar['time']->startMeasure('render');

render_demo_page(function() {
?>
render_demo_page(function () {
?>
<h2>AJAX</h2>
<ul>
<li><a href="ajax.php" class="ajax">load ajax content</a></li>
Expand Down
8 changes: 4 additions & 4 deletions demo/pdo.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@

include 'bootstrap.php';

use DebugBar\DataCollector\PDO\TraceablePDO;
use DebugBar\DataCollector\PDO\PDOCollector;
use DebugBar\DataCollector\PDO\TraceablePDO;

$pdo = new TraceablePDO(new PDO('sqlite::memory:'));
$debugbar->addCollector(new PDOCollector($pdo));

$pdo->exec('create table users (name varchar)');
$stmt = $pdo->prepare('insert into users (name) values (?)');
$stmt->execute(array('foo'));
$stmt->execute(array('bar'));
$stmt->execute(['foo']);
$stmt->execute(['bar']);

$users = $pdo->query('select * from users')->fetchAll();
$stmt = $pdo->prepare('select * from users where name=?');
$stmt->execute(array('foo'));
$stmt->execute(['foo']);
$foo = $stmt->fetch();

$pdo->exec('delete from titi');
Expand Down
3 changes: 2 additions & 1 deletion src/DebugBar/Bridge/Propel2Collector.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ class Propel2Collector extends DataCollector implements Renderable, AssetProvide
* @param ConnectionInterface $connection Propel connection
*/
public function __construct(
ConnectionInterface $connection, array $logMethods = [
ConnectionInterface $connection,
array $logMethods = [
'beginTransaction',
'commit',
'rollBack',
Expand Down
3 changes: 1 addition & 2 deletions src/DebugBar/DataCollector/MessagesCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@
namespace DebugBar\DataCollector;

use DebugBar\DataFormatter\DataFormatterInterface;
use Psr\Log\AbstractLogger;

/**
* Provides a way to log messages.
*/
class MessagesCollector extends AbstractLogger implements DataCollectorInterface, MessagesAggregateInterface, Renderable
class MessagesCollector implements DataCollectorInterface, MessagesAggregateInterface, Renderable
{
protected $name;
protected $messages = [];
Expand Down
14 changes: 11 additions & 3 deletions src/DebugBar/DataCollector/PDO/PDOCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@ class PDOCollector extends DataCollector implements Renderable, AssetProvider
protected $timeCollector;
protected $renderSqlWithParams = false;
protected $sqlQuotationChar = '<>';
public $connectType = 'master';

/**
* @param TraceablePDO $pdo
* @param TimeDataCollector $timeCollector
*/
public function __construct(TraceablePDO $pdo = null, TimeDataCollector $timeCollector = null)
public function __construct(TraceablePDO $pdo = null, TimeDataCollector $timeCollector = null, $dbName = 'base')
{
$this->timeCollector = $timeCollector;
if ($pdo !== null) {
$this->addConnection($pdo, 'default');
$this->addConnection($pdo, $dbName);
}
}

Expand Down Expand Up @@ -124,6 +125,9 @@ public function collect()
*/
protected function collectPDO(TraceablePDO $pdo, TimeDataCollector $timeCollector = null)
{
$config = \App\Db::getConfig($this->connectType);
$dbName = $config['dbName'];
$driverName = $pdo->getAttribute(\PDO::ATTR_DRIVER_NAME);
$stmts = [];
foreach ($pdo->getExecutedStatements() as $stmt) {
$stmts[] = [
Expand All @@ -140,7 +144,11 @@ protected function collectPDO(TraceablePDO $pdo, TimeDataCollector $timeCollecto
'end_memory_str' => $this->getDataFormatter()->formatBytes($stmt->getEndMemory()),
'is_success' => $stmt->isSuccess(),
'error_code' => $stmt->getErrorCode(),
'error_message' => $stmt->getErrorMessage()
'error_message' => $stmt->getErrorMessage(),
'backtrace' => $stmt->getBackTrace(),
'driverName' => $driverName,
'dbName' => $dbName,
'connectType' => $this->connectType,
];
if ($timeCollector !== null) {
$timeCollector->addMeasure($stmt->getSql(), $stmt->getStartTime(), $stmt->getEndTime());
Expand Down
Loading

0 comments on commit 52825aa

Please sign in to comment.