Elgg  Version 1.11
DeprecationService.php
Go to the documentation of this file.
1 <?php
2 namespace Elgg;
3 
16 
20  protected $session;
21 
25  protected $logger;
26 
33  public function __construct(\ElggSession $session, Logger $logger) {
34  $this->session = $session;
35  $this->logger = $logger;
36  }
37 
49  function sendNotice($msg, $dep_version, $backtrace_level = 1) {
50  if (!$dep_version) {
51  return false;
52  }
53 
54  $elgg_version = elgg_get_version(true);
55  $elgg_version_arr = explode('.', $elgg_version);
56  $elgg_major_version = (int)$elgg_version_arr[0];
57  $elgg_minor_version = (int)$elgg_version_arr[1];
58 
59  $dep_version_arr = explode('.', (string)$dep_version);
60  $dep_major_version = (int)$dep_version_arr[0];
61  $dep_minor_version = (int)$dep_version_arr[1];
62 
63  $msg = "Deprecated in $dep_major_version.$dep_minor_version: $msg Called from ";
64 
65  // Get a file and line number for the log. Skip over the function that
66  // sent this notice and see who called the deprecated function itself.
67  $stack = array();
68  $backtrace = debug_backtrace();
69  // never show this call.
70  array_shift($backtrace);
71  $i = count($backtrace);
72 
73  foreach ($backtrace as $trace) {
74  $stack[] = "[#$i] {$trace['file']}:{$trace['line']}";
75  $i--;
76 
77  if ($backtrace_level > 0) {
78  if ($backtrace_level <= 1) {
79  break;
80  }
81  $backtrace_level--;
82  }
83  }
84 
85  $msg .= implode("<br /> -> ", $stack);
86 
87  $this->logger->warn($msg);
88 
89  return true;
90  }
91 }
sendNotice($msg, $dep_version, $backtrace_level=1)
Sends a notice about deprecated use of a function, view, etc.
__construct(\ElggSession $session, Logger $logger)
Constructor.
Save menu items.
elgg_get_version($human_readable=false)
Get the current Elgg version information.
Definition: elgglib.php:976
$session
Definition: login.php:9