DeprecationLogger.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace PhpXmlRpc\Traits;
  3. use PhpXmlRpc\PhpXmlRpc;
  4. trait DeprecationLogger
  5. {
  6. use LoggerAware;
  7. protected function logDeprecation($message)
  8. {
  9. if (PhpXmlRpc::$xmlrpc_silence_deprecations) {
  10. return;
  11. }
  12. $this->getLogger()->warning('XML-RPC Deprecated: ' . $message);
  13. }
  14. /**
  15. * @param string $callee
  16. * @param string $expectedCaller atm only the method name is supported
  17. * @return void
  18. */
  19. protected function logDeprecationUnlessCalledBy($expectedCaller)
  20. {
  21. if (PhpXmlRpc::$xmlrpc_silence_deprecations) {
  22. return;
  23. }
  24. $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 3);
  25. /// @todo we should check as well $trace[2]['class'], and make sure that it is a descendent of the class passed in in $expectedCaller
  26. if ($trace[2]['function'] === $expectedCaller) {
  27. return;
  28. }
  29. $this->getLogger()->warning('XML-RPC Deprecated: ' . $trace[1]['class'] . '::' . $trace[1]['function'] .
  30. ' is only supposed to be called by ' . $expectedCaller);
  31. }
  32. }