[DomCrawler] fix deprecation triggers

The SplObjectStorage class performs calls to its own methods. These
method calls must not lead to triggered deprecation notices.
This commit is contained in:
Christian Flothmann 2015-10-01 18:01:41 +02:00
parent 1309cfbe9d
commit aca6bd9bd6

View File

@ -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);
}
}