DeprecatedServicePropertyTrait.php 818 B

12345678910111213141516171819202122232425262728
  1. <?php
  2. namespace Drupal\Core\DependencyInjection;
  3. /**
  4. * Provides a standard way to announce deprecated properties.
  5. */
  6. trait DeprecatedServicePropertyTrait {
  7. /**
  8. * Allows to access deprecated/removed properties.
  9. *
  10. * This method must be public.
  11. */
  12. public function __get($name) {
  13. if (!isset($this->deprecatedProperties)) {
  14. throw new \LogicException('The deprecatedProperties property must be defined to use this trait.');
  15. }
  16. if (isset($this->deprecatedProperties[$name])) {
  17. $service_name = $this->deprecatedProperties[$name];
  18. $class_name = static::class;
  19. @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);
  20. return \Drupal::service($service_name);
  21. }
  22. }
  23. }