From f1f91a929cac83273dd6407db2e8bfe6d137d2d3 Mon Sep 17 00:00:00 2001 From: Vladislav Rastrusny Date: Tue, 29 Nov 2016 14:10:58 +0300 Subject: [PATCH 1/4] DoctrineDataCollector: taught sanitizeParam to support classes with __toString implemented. --- .../DataCollector/DoctrineDataCollector.php | 4 ++- .../DoctrineDataCollectorTest.php | 3 +- .../StringRepresentableClass.php | 31 +++++++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 src/Symfony/Bridge/Doctrine/Tests/DataCollector/StringRepresentableClass.php diff --git a/src/Symfony/Bridge/Doctrine/DataCollector/DoctrineDataCollector.php b/src/Symfony/Bridge/Doctrine/DataCollector/DoctrineDataCollector.php index a57b9ae6ea151..090d8db29cf25 100644 --- a/src/Symfony/Bridge/Doctrine/DataCollector/DoctrineDataCollector.php +++ b/src/Symfony/Bridge/Doctrine/DataCollector/DoctrineDataCollector.php @@ -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) : + array(sprintf('Object(%s)', get_class($var)), false,); } if (is_array($var)) { diff --git a/src/Symfony/Bridge/Doctrine/Tests/DataCollector/DoctrineDataCollectorTest.php b/src/Symfony/Bridge/Doctrine/Tests/DataCollector/DoctrineDataCollectorTest.php index 3059f8aba00a3..7e586285019ea 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/DataCollector/DoctrineDataCollectorTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/DataCollector/DoctrineDataCollectorTest.php @@ -127,7 +127,8 @@ 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(), 'presentation test', false), ); } diff --git a/src/Symfony/Bridge/Doctrine/Tests/DataCollector/StringRepresentableClass.php b/src/Symfony/Bridge/Doctrine/Tests/DataCollector/StringRepresentableClass.php new file mode 100644 index 0000000000000..3f76ec1f1d954 --- /dev/null +++ b/src/Symfony/Bridge/Doctrine/Tests/DataCollector/StringRepresentableClass.php @@ -0,0 +1,31 @@ +representation = $representation; + } + + public function __toString() + { + return $this->representation; + } +} From c3ed81c566420aee40d9e6f07f44926307604a57 Mon Sep 17 00:00:00 2001 From: Vladislav Rastrusny Date: Tue, 29 Nov 2016 14:40:56 +0300 Subject: [PATCH 2/4] DoctrineDataCollector applied fabpot.io formatting hints. --- .../DataCollector/DoctrineDataCollector.php | 2 +- .../DoctrineDataCollectorTest.php | 2 +- .../StringRepresentableClass.php | 36 +++++++++---------- 3 files changed, 19 insertions(+), 21 deletions(-) diff --git a/src/Symfony/Bridge/Doctrine/DataCollector/DoctrineDataCollector.php b/src/Symfony/Bridge/Doctrine/DataCollector/DoctrineDataCollector.php index 090d8db29cf25..570ca55a18925 100644 --- a/src/Symfony/Bridge/Doctrine/DataCollector/DoctrineDataCollector.php +++ b/src/Symfony/Bridge/Doctrine/DataCollector/DoctrineDataCollector.php @@ -161,7 +161,7 @@ private function sanitizeParam($var) if (is_object($var)) { return method_exists($var, '__toString') ? array($var->__toString(), false) : - array(sprintf('Object(%s)', get_class($var)), false,); + array(sprintf('Object(%s)', get_class($var)), false); } if (is_array($var)) { diff --git a/src/Symfony/Bridge/Doctrine/Tests/DataCollector/DoctrineDataCollectorTest.php b/src/Symfony/Bridge/Doctrine/Tests/DataCollector/DoctrineDataCollectorTest.php index 7e586285019ea..5033363d70f43 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/DataCollector/DoctrineDataCollectorTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/DataCollector/DoctrineDataCollectorTest.php @@ -127,7 +127,7 @@ 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 \stdClass, array(), 'Object(stdClass)', false), + array(new \stdClass(), array(), 'Object(stdClass)', false), array(new StringRepresentableClass('presentation test'), array(), 'presentation test', false), ); } diff --git a/src/Symfony/Bridge/Doctrine/Tests/DataCollector/StringRepresentableClass.php b/src/Symfony/Bridge/Doctrine/Tests/DataCollector/StringRepresentableClass.php index 3f76ec1f1d954..443121eaaea12 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/DataCollector/StringRepresentableClass.php +++ b/src/Symfony/Bridge/Doctrine/Tests/DataCollector/StringRepresentableClass.php @@ -4,28 +4,26 @@ /** * A class for testing __toString method behaviour. It's __toString returns a value, that was passed into constructor. - * - * @package Symfony\Bridge\Doctrine\Tests\DataCollector */ class StringRepresentableClass { - /** - * @var string - */ - private $representation; + /** + * @var string + */ + private $representation; - /** - * CustomStringableClass constructor. - * - * @param string $representation - */ - public function __construct($representation) - { - $this->representation = $representation; - } + /** + * CustomStringableClass constructor. + * + * @param string $representation + */ + public function __construct($representation) + { + $this->representation = $representation; + } - public function __toString() - { - return $this->representation; - } + public function __toString() + { + return $this->representation; + } } From d3f9d165206cdb716171c08cd303b19659ab91f9 Mon Sep 17 00:00:00 2001 From: Vladislav Rastrusny Date: Thu, 2 Mar 2017 11:58:20 +0300 Subject: [PATCH 3/4] DoctrineDataCollector object stringable representation format changed --- .../Doctrine/DataCollector/DoctrineDataCollector.php | 5 +++-- .../Tests/DataCollector/DoctrineDataCollectorTest.php | 7 ++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Bridge/Doctrine/DataCollector/DoctrineDataCollector.php b/src/Symfony/Bridge/Doctrine/DataCollector/DoctrineDataCollector.php index 570ca55a18925..e0887596ee908 100644 --- a/src/Symfony/Bridge/Doctrine/DataCollector/DoctrineDataCollector.php +++ b/src/Symfony/Bridge/Doctrine/DataCollector/DoctrineDataCollector.php @@ -159,9 +159,10 @@ private function sanitizeQuery($connectionName, $query) private function sanitizeParam($var) { if (is_object($var)) { + $className = get_class($var); return method_exists($var, '__toString') ? - array($var->__toString(), false) : - array(sprintf('Object(%s)', get_class($var)), false); + array(sprintf('Object(%s): "%s"', $className, $var->__toString()), false) : + array(sprintf('Object(%s)', $className), false); } if (is_array($var)) { diff --git a/src/Symfony/Bridge/Doctrine/Tests/DataCollector/DoctrineDataCollectorTest.php b/src/Symfony/Bridge/Doctrine/Tests/DataCollector/DoctrineDataCollectorTest.php index 5033363d70f43..2a39b345e0d67 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/DataCollector/DoctrineDataCollectorTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/DataCollector/DoctrineDataCollectorTest.php @@ -128,7 +128,12 @@ public function paramProvider() array(new \DateTime('2011-09-11'), array('date'), '2011-09-11', true), array(fopen(__FILE__, 'r'), array(), 'Resource(stream)', false), array(new \stdClass(), array(), 'Object(stdClass)', false), - array(new StringRepresentableClass('presentation test'), array(), 'presentation test', false), + array( + new StringRepresentableClass('presentation test'), + array(), + 'Object(Symfony\Bridge\Doctrine\Tests\DataCollector\StringRepresentableClass): "presentation test"', + false, + ), ); } From cb4bd69408a92048c32a915111d28944754b95ea Mon Sep 17 00:00:00 2001 From: Vladislav Rastrusny Date: Thu, 2 Mar 2017 12:05:26 +0300 Subject: [PATCH 4/4] DoctrineDataCollector fabpot.io formatting hint applied --- .../Bridge/Doctrine/DataCollector/DoctrineDataCollector.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Symfony/Bridge/Doctrine/DataCollector/DoctrineDataCollector.php b/src/Symfony/Bridge/Doctrine/DataCollector/DoctrineDataCollector.php index e0887596ee908..62c6a2381a940 100644 --- a/src/Symfony/Bridge/Doctrine/DataCollector/DoctrineDataCollector.php +++ b/src/Symfony/Bridge/Doctrine/DataCollector/DoctrineDataCollector.php @@ -160,6 +160,7 @@ private function sanitizeParam($var) { if (is_object($var)) { $className = get_class($var); + return method_exists($var, '__toString') ? array(sprintf('Object(%s): "%s"', $className, $var->__toString()), false) : array(sprintf('Object(%s)', $className), false);