From aca6bd9bd6772e3e8c36bb280a04e73acf51fd12 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Thu, 1 Oct 2015 18:01:41 +0200 Subject: [PATCH] [DomCrawler] fix deprecation triggers The SplObjectStorage class performs calls to its own methods. These method calls must not lead to triggered deprecation notices. --- src/Symfony/Component/DomCrawler/Crawler.php | 45 ++++++++++++++------ 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/src/Symfony/Component/DomCrawler/Crawler.php b/src/Symfony/Component/DomCrawler/Crawler.php index 52cdddb348..d4e452f6f0 100644 --- a/src/Symfony/Component/DomCrawler/Crawler.php +++ b/src/Symfony/Component/DomCrawler/Crawler.php @@ -832,7 +832,7 @@ class Crawler extends \SplObjectStorage */ public function attach($object, $data = null) { - @trigger_error('The '.__METHOD__.' method is deprecated as of 2.8 and will be removed in 3.0.', E_USER_DEPRECATED); + $this->triggerDeprecation(__METHOD__); parent::attach($object, $data); } @@ -842,7 +842,7 @@ class Crawler extends \SplObjectStorage */ public function detach($object) { - @trigger_error('The '.__METHOD__.' method is deprecated as of 2.8 and will be removed in 3.0.', E_USER_DEPRECATED); + $this->triggerDeprecation(__METHOD__); parent::detach($object); } @@ -852,7 +852,7 @@ class Crawler extends \SplObjectStorage */ public function contains($object) { - @trigger_error('The '.__METHOD__.' method is deprecated as of 2.8 and will be removed in 3.0.', E_USER_DEPRECATED); + $this->triggerDeprecation(__METHOD__); return parent::contains($object); } @@ -862,7 +862,7 @@ class Crawler extends \SplObjectStorage */ public function addAll($storage) { - @trigger_error('The '.__METHOD__.' method is deprecated as of 2.8 and will be removed in 3.0.', E_USER_DEPRECATED); + $this->triggerDeprecation(__METHOD__); parent::addAll($storage); } @@ -872,7 +872,7 @@ class Crawler extends \SplObjectStorage */ public function removeAll($storage) { - @trigger_error('The '.__METHOD__.' method is deprecated as of 2.8 and will be removed in 3.0.', E_USER_DEPRECATED); + $this->triggerDeprecation(__METHOD__); parent::removeAll($storage); } @@ -882,7 +882,7 @@ class Crawler extends \SplObjectStorage */ public function removeAllExcept($storage) { - @trigger_error('The '.__METHOD__.' method is deprecated as of 2.8 and will be removed in 3.0.', E_USER_DEPRECATED); + $this->triggerDeprecation(__METHOD__); parent::removeAllExcept($storage); } @@ -892,7 +892,7 @@ class Crawler extends \SplObjectStorage */ public function getInfo() { - @trigger_error('The '.__METHOD__.' method is deprecated as of 2.8 and will be removed in 3.0.', E_USER_DEPRECATED); + $this->triggerDeprecation(__METHOD__); return parent::getInfo(); } @@ -902,7 +902,7 @@ class Crawler extends \SplObjectStorage */ public function setInfo($data) { - @trigger_error('The '.__METHOD__.' method is deprecated as of 2.8 and will be removed in 3.0.', E_USER_DEPRECATED); + $this->triggerDeprecation(__METHOD__); parent::setInfo($data); } @@ -912,7 +912,7 @@ class Crawler extends \SplObjectStorage */ public function offsetExists($object) { - @trigger_error('The '.__METHOD__.' method is deprecated as of 2.8 and will be removed in 3.0.', E_USER_DEPRECATED); + $this->triggerDeprecation(__METHOD__); return parent::offsetExists($object); } @@ -922,7 +922,7 @@ class Crawler extends \SplObjectStorage */ public function offsetSet($object, $data = null) { - @trigger_error('The '.__METHOD__.' method is deprecated as of 2.8 and will be removed in 3.0.', E_USER_DEPRECATED); + $this->triggerDeprecation(__METHOD__); parent::offsetSet($object, $data); } @@ -932,7 +932,7 @@ class Crawler extends \SplObjectStorage */ public function offsetUnset($object) { - @trigger_error('The '.__METHOD__.' method is deprecated as of 2.8 and will be removed in 3.0.', E_USER_DEPRECATED); + $this->triggerDeprecation(__METHOD__); parent::offsetUnset($object); } @@ -942,7 +942,7 @@ class Crawler extends \SplObjectStorage */ public function offsetGet($object) { - @trigger_error('The '.__METHOD__.' method is deprecated as of 2.8 and will be removed in 3.0.', E_USER_DEPRECATED); + $this->triggerDeprecation(__METHOD__); return parent::offsetGet($object); } @@ -952,7 +952,7 @@ class Crawler extends \SplObjectStorage */ public function getHash($object) { - // Cannot trigger a deprecation warning here because SplObjectStorage calls this method when attaching an object. + $this->triggerDeprecation(__METHOD__, true); return parent::getHash($object); } @@ -1155,4 +1155,23 @@ class Crawler extends \SplObjectStorage return $crawler; } + + private function triggerDeprecation($methodName, $useTrace = false) + { + $traces = array(); + $caller = array(); + + if ($useTrace || defined('HHVM_VERSION')) { + $traces = debug_backtrace(); + $caller = $traces[2]; + } + + // The SplObjectStorage class performs calls to its own methods. These + // method calls must not lead to triggered deprecation notices. + if (isset($caller['class']) && 'SplObjectStorage' === $caller['class']) { + return; + } + + @trigger_error('The '.$methodName.' method is deprecated as of 2.8 and will be removed in 3.0.', E_USER_DEPRECATED); + } }