27trait DolDeprecationHandler
46 public function __get($name)
48 $deprecatedProperties = $this->deprecatedProperties();
49 if (isset($deprecatedProperties[$name])) {
50 $newProperty = $deprecatedProperties[$name];
51 $msg =
"DolDeprecationHandler: Accessing deprecated property '".$name.
"' on class ".get_class($this).
". Use '".$newProperty.
"' instead.".
self::getCallerInfoString();
53 if ($this->isDeprecatedReportingEnabled()) {
54 trigger_error($msg, E_USER_DEPRECATED);
56 return $this->$newProperty;
58 if ($this->isDynamicPropertiesEnabled()) {
63 trigger_error($msg, E_USER_NOTICE);
74 public function __set($name, $value)
76 $deprecatedProperties = $this->deprecatedProperties();
77 if (isset($deprecatedProperties[$name])) {
78 $newProperty = $deprecatedProperties[$name];
88 $this->$newProperty = $value;
91 if (!$this->isDynamicPropertiesEnabled()) {
93 trigger_error($msg, E_USER_NOTICE);
94 $this->$name = $value;
96 $this->$name = $value;
106 public function __unset($name)
108 $deprecatedProperties = $this->deprecatedProperties();
109 if (isset($deprecatedProperties[$name])) {
110 $newProperty = $deprecatedProperties[$name];
119 unset($this->$newProperty);
122 if (!$this->isDynamicPropertiesEnabled()) {
125 trigger_error($msg, E_USER_NOTICE);
135 public function __isset($name)
137 $deprecatedProperties = $this->deprecatedProperties();
138 if (isset($deprecatedProperties[$name])) {
139 $newProperty = $deprecatedProperties[$name];
140 $msg =
"DolDeprecationHandler: Accessing deprecated property '".$name.
"' on class ".get_class($this).
". Use '".$newProperty.
"' instead.".
self::getCallerInfoString();
142 if ($this->isDeprecatedReportingEnabled()) {
143 trigger_error($msg, E_USER_DEPRECATED);
145 return isset($newProperty);
146 } elseif ($this->isDynamicPropertiesEnabled()) {
147 return isset($this->$name);
152 return isset($this->$name);
162 public function __call($name, $arguments)
164 $deprecatedMethods = $this->deprecatedMethods();
165 if (isset($deprecatedMethods[$name])) {
166 $newMethod = $deprecatedMethods[$name];
167 if ($this->isDeprecatedReportingEnabled()) {
168 trigger_error(
"Calling deprecated method '".$name.
"' on class ".get_class($this).
". Use '".$newMethod.
"' instead.".self::getCallerInfoString(), E_USER_DEPRECATED);
170 if (method_exists($this, $newMethod)) {
171 return call_user_func_array([$this, $newMethod], $arguments);
173 trigger_error(
"Replacement method '".$newMethod.
"' not implemented.", E_USER_NOTICE);
176 trigger_error(
"Call to undefined method '".$name.
"'.".self::getCallerInfoString(), E_USER_ERROR);
185 private function isDeprecatedReportingEnabled()
189 if (property_exists($this,
'enableDeprecatedReporting')) {
191 return (
bool) $this->enableDeprecatedReporting;
194 return (error_reporting() & E_DEPRECATED) === E_DEPRECATED;
202 private function isDynamicPropertiesEnabled()
206 if (property_exists($this,
'enableDynamicProperties')) {
208 return (
bool) $this->enableDynamicProperties;
230 protected function deprecatedProperties()
246 protected function deprecatedMethods()
263 $backtrace = debug_backtrace();
265 if (count($backtrace) >= 2) {
266 $trace = $backtrace[1];
267 if (isset($trace[
'file'], $trace[
'line'])) {
268 $msg =
" From {$trace['file']}:{$trace['line']}.";
getCallerInfoString()
Get caller info as a string that can be appended to a log message.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.