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

Conversation

FractalizeR
Copy link
Contributor

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
License MIT
Doc PR no

@nicolas-grekas
Copy link
Member

I think we need to dump the class name all the time. At least this is what Monolog does in this case:
https://github.com/Seldaek/monolog/blob/master/src/Monolog/Formatter/NormalizerFormatter.php#L101-L120

@FractalizeR
Copy link
Contributor Author

Monolog in that source does both. It uses class name as a key, and __toString() call result as a value.

@nicolas-grekas nicolas-grekas added this to the 3.x milestone Dec 6, 2016
@nicolas-grekas
Copy link
Member

@FractalizeR that's what I meant :) And I think that's wise.

@@ -159,7 +159,9 @@ private function sanitizeQuery($connectionName, $query)
private function sanitizeParam($var)
{
if (is_object($var)) {
return array(sprintf('Object(%s)', get_class($var)), false);
return method_exists($var, '__toString') ?
array($var->__toString(), false) :
Copy link
Member

Choose a reason for hiding this comment

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

I agree that the class name should be dumped here as well. The way it is implemented will cause confusing results.

@fabpot
Copy link
Member

fabpot commented Feb 16, 2017

What's the status of this PR?

@fabpot
Copy link
Member

fabpot commented Mar 1, 2017

@FractalizeR Any news? Are still interested in finishing this PR?

@FractalizeR
Copy link
Contributor Author

Yeah, sure. But I am at lost who makes a decision about how this PR should really look like. I'm ready to make desired modifications, but someone responsible needs to tell me what needs to be adjusted.

@fabpot
Copy link
Member

fabpot commented Mar 1, 2017

I think we all agree that we need to keep the class name, even when there is a string representation.

@FractalizeR
Copy link
Contributor Author

Can we, then, use the following representation for objects, implementing __toString()

(object) className: '__toString() return result'

?

@fabpot
Copy link
Member

fabpot commented Mar 1, 2017

@FractalizeR I think that makes sense.

@FractalizeR FractalizeR force-pushed the feature-doctrine-data-collector-tostringable-params branch from 14e2631 to d3f9d16 Compare March 2, 2017 09:00
@FractalizeR
Copy link
Contributor Author

Done. Some tests fail, but this is not due my PR, but several other components. Looks like some PR was merged without ensuring tests pass.


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

@fabpot
Copy link
Member

fabpot commented Mar 2, 2017

Thank you @FractalizeR.

@fabpot fabpot closed this in 3b4a8f3 Mar 2, 2017
@FractalizeR FractalizeR deleted the feature-doctrine-data-collector-tostringable-params branch March 3, 2017 08:21
@nicolas-grekas nicolas-grekas modified the milestones: 3.x, 3.3 Mar 24, 2017
@fabpot fabpot mentioned this pull request May 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants