diff core/lib/Drupal/Core/DependencyInjection/DeprecatedServicePropertyTrait.php @ 5:12f9dff5fda9 tip

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:34:47 +0100
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/core/lib/Drupal/Core/DependencyInjection/DeprecatedServicePropertyTrait.php	Thu May 09 15:34:47 2019 +0100
@@ -0,0 +1,28 @@
+<?php
+
+namespace Drupal\Core\DependencyInjection;
+
+/**
+ * Provides a standard way to announce deprecated properties.
+ */
+trait DeprecatedServicePropertyTrait {
+
+  /**
+   * Alows to access deprecated/removed properties.
+   *
+   * This method must be public.
+   */
+  public function __get($name) {
+    if (!isset($this->deprecatedProperties)) {
+      throw new \LogicException('The deprecatedProperties property must be defined to use this trait.');
+    }
+
+    if (isset($this->deprecatedProperties[$name])) {
+      $service_name = $this->deprecatedProperties[$name];
+      $class_name = static::class;
+      @trigger_error("The property $name ($service_name service) is deprecated in $class_name and will be removed before Drupal 9.0.0.", E_USER_DEPRECATED);
+      return \Drupal::service($service_name);
+    }
+  }
+
+}