Skip to content

DoctrineDataCollector: taught sanitizeParam to support classes with __toString implemented. #20680

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,11 @@ private function sanitizeQuery($connectionName, $query)
private function sanitizeParam($var)
{
if (is_object($var)) {
return array(sprintf('Object(%s)', get_class($var)), false);
$className = get_class($var);

return method_exists($var, '__toString') ?
array(sprintf('Object(%s): "%s"', $className, $var->__toString()), false) :
array(sprintf('Object(%s)', $className), false);
}

if (is_array($var)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,13 @@ public function paramProvider()
array(null, array(), null, true),
array(new \DateTime('2011-09-11'), array('date'), '2011-09-11', true),
array(fopen(__FILE__, 'r'), array(), 'Resource(stream)', false),
array(new \SplFileInfo(__FILE__), array(), 'Object(SplFileInfo)', false),
array(new \stdClass(), array(), 'Object(stdClass)', false),
array(
new StringRepresentableClass('presentation test'),
array(),
'Object(Symfony\Bridge\Doctrine\Tests\DataCollector\StringRepresentableClass): "presentation test"',
false,
),
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Symfony\Bridge\Doctrine\Tests\DataCollector;

/**
* A class for testing __toString method behaviour. It's __toString returns a value, that was passed into constructor.
*/
class StringRepresentableClass
{
/**
* @var string
*/
private $representation;

/**
* CustomStringableClass constructor.
*
* @param string $representation
*/
public function __construct($representation)
{
$this->representation = $representation;
}

public function __toString()
{
return $this->representation;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we simplify this class by removing the representation property and hardcode the text here directly?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see 26c54c7

}
}