Skip to content

Commit

Permalink
Switched sanitizeParameter() for existing varToString()-method; now a…
Browse files Browse the repository at this point in the history
…lways stores a string representation of each parameter
  • Loading branch information
aboks committed Dec 8, 2011
1 parent 4fe4dfd commit bb0d202
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 20 deletions.
38 changes: 23 additions & 15 deletions src/Symfony/Bridge/Doctrine/DataCollector/DoctrineDataCollector.php
Expand Up @@ -89,36 +89,44 @@ private function sanitizeQueries($queries)
{
foreach ($queries as $i => $query) {
foreach ($query['params'] as $j => $param) {
$queries[$i]['params'][$j] = $this->sanitizeParameter($param);
$queries[$i]['params'][$j] = $this->varToString($param);
}
}

return $queries;
}

private function sanitizeParameter($param)
private function varToString($var)
{
if (is_array($param)) {
foreach ($param as $key => $value) {
$param[$key] = $this->sanitizeParameter($value);
if (is_object($var)) {
return sprintf('Object(%s)', get_class($var));
}

if (is_array($var)) {
$a = array();
foreach ($var as $k => $v) {
$a[] = sprintf('%s => %s', $k, $this->varToString($v));
}

return $param;
return sprintf("Array(%s)", implode(', ', $a));
}

if (is_resource($param)) {
return sprintf('Resource(%s)', get_resource_type($param));
if (is_resource($var)) {
return sprintf('Resource(%s)', get_resource_type($var));
}

if (is_object($param) && $this->isNotSerializable($param)) {
return sprintf('Object(%s)', get_class($param));
if (null === $var) {
return 'null';
}

return $param;
}
if (false === $var) {
return 'false';
}

private function isNotSerializable($object)
{
return $object instanceof \SplFileInfo;
if (true === $var) {
return 'true';
}

return (string) $var;
}
}
Expand Up @@ -36,7 +36,7 @@
<code>{{ query.sql }}</code>
</div>
<small>
<strong>Parameters</strong>: {{ query.params|yaml_encode }}<br />
<strong>Parameters</strong>: {{ query.params }}<br />
<strong>Time</strong>: {{ '%0.2f'|format(query.executionMS * 1000) }} ms
</small>
</li>
Expand Down
Expand Up @@ -102,10 +102,10 @@ public function paramProvider()
{
return array(
array('some value', 'some value'),
array(1, 1),
array(true, true),
array(null, null),
array(new \stdClass(), new \stdClass()),
array(1, '1'),
array(true, 'true'),
array(null, 'null'),
array(new \stdClass(), 'Object(stdClass)'),
array(fopen(__FILE__, 'r'), 'Resource(stream)'),
array(new \SplFileInfo(__FILE__), 'Object(SplFileInfo)'),
);
Expand Down

0 comments on commit bb0d202

Please sign in to comment.