Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3b4a8f3

Browse filesBrowse files
committed
feature #20680 DoctrineDataCollector: taught sanitizeParam to support classes with __toString implemented. (FractalizeR)
This PR was squashed before being merged into the 3.3-dev branch (closes #20680). Discussion ---------- DoctrineDataCollector: taught sanitizeParam to support classes with __toString implemented. This PR teaches \Symfony\Bridge\Doctrine\DataCollector\DoctrineDataCollector::sanitizeParam support objects, which implement __toString and therefore can be represented as a string with more sense, than "(object) ClassName". It also includes test for the feature. | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | [20673](#20673) | License | MIT | Doc PR | no Commits ------- f2970f2 DoctrineDataCollector: taught sanitizeParam to support classes with __toString implemented.
2 parents e2e9c94 + f2970f2 commit 3b4a8f3
Copy full SHA for 3b4a8f3

File tree

3 files changed

+41
-2
lines changed
Filter options

3 files changed

+41
-2
lines changed

‎src/Symfony/Bridge/Doctrine/DataCollector/DoctrineDataCollector.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/DataCollector/DoctrineDataCollector.php
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,11 @@ private function sanitizeQuery($connectionName, $query)
159159
private function sanitizeParam($var)
160160
{
161161
if (is_object($var)) {
162-
return array(sprintf('Object(%s)', get_class($var)), false);
162+
$className = get_class($var);
163+
164+
return method_exists($var, '__toString') ?
165+
array(sprintf('Object(%s): "%s"', $className, $var->__toString()), false) :
166+
array(sprintf('Object(%s)', $className), false);
163167
}
164168

165169
if (is_array($var)) {

‎src/Symfony/Bridge/Doctrine/Tests/DataCollector/DoctrineDataCollectorTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/Tests/DataCollector/DoctrineDataCollectorTest.php
+7-1Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,13 @@ public function paramProvider()
127127
array(null, array(), null, true),
128128
array(new \DateTime('2011-09-11'), array('date'), '2011-09-11', true),
129129
array(fopen(__FILE__, 'r'), array(), 'Resource(stream)', false),
130-
array(new \SplFileInfo(__FILE__), array(), 'Object(SplFileInfo)', false),
130+
array(new \stdClass(), array(), 'Object(stdClass)', false),
131+
array(
132+
new StringRepresentableClass('presentation test'),
133+
array(),
134+
'Object(Symfony\Bridge\Doctrine\Tests\DataCollector\StringRepresentableClass): "presentation test"',
135+
false,
136+
),
131137
);
132138
}
133139

+29Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace Symfony\Bridge\Doctrine\Tests\DataCollector;
4+
5+
/**
6+
* A class for testing __toString method behaviour. It's __toString returns a value, that was passed into constructor.
7+
*/
8+
class StringRepresentableClass
9+
{
10+
/**
11+
* @var string
12+
*/
13+
private $representation;
14+
15+
/**
16+
* CustomStringableClass constructor.
17+
*
18+
* @param string $representation
19+
*/
20+
public function __construct($representation)
21+
{
22+
$this->representation = $representation;
23+
}
24+
25+
public function __toString()
26+
{
27+
return $this->representation;
28+
}
29+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.