Elgg  Version 3.0
DeprecationService.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg;
4 
6 
19 
20  use Loggable;
21 
27  public function __construct(LoggerInterface $logger) {
28  $this->logger = $logger;
29  }
30 
42  public function sendNotice($msg, $dep_version, $backtrace_level = 1) {
43 
44  $msg = "Deprecated in $dep_version: $msg Called from ";
45 
46  // Get a file and line number for the log. Skip over the function that
47  // sent this notice and see who called the deprecated function itself.
48  $stack = [];
49  $backtrace = debug_backtrace();
50  // never show this call.
51  array_shift($backtrace);
52  $i = count($backtrace);
53 
54  foreach ($backtrace as $trace) {
55  if (empty($trace['file'])) {
56  // file/line not set for Closures
57  $stack[] = "[#$i] unknown";
58  } else {
59  $stack[] = "[#$i] {$trace['file']}:{$trace['line']}";
60  }
61 
62  $i--;
63 
64  if ($backtrace_level > 0) {
65  if ($backtrace_level <= 1) {
66  break;
67  }
68  $backtrace_level--;
69  }
70  }
71 
72  $msg .= implode(PHP_EOL . " -> ", $stack);
73 
74  $this->logger->warning($msg);
75 
76  return true;
77  }
78 }
sendNotice($msg, $dep_version, $backtrace_level=1)
Sends a notice about deprecated use of a function, view, etc.
trait Loggable
Enables adding a logger.
Definition: Loggable.php:12
Configuration exception.
__construct(LoggerInterface $logger)
Constructor.
WARNING: API IN FLUX.