summaryrefslogtreecommitdiffstatshomepage
path: root/core/lib/Drupal/Core/DependencyInjection/DeprecatedServicePropertyTrait.php
blob: ba81fac98be910f6f199bd08a4de285ab876bf42 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php

namespace Drupal\Core\DependencyInjection;

/**
 * Provides a standard way to announce deprecated properties.
 */
trait DeprecatedServicePropertyTrait {

  /**
   * Allows to access deprecated/removed properties.
   *
   * This method must be public.
   */
  public function __get(string $name): mixed {
    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;
      // phpcs:ignore Drupal.Semantics.FunctionTriggerError
      @trigger_error("The property $name ($service_name service) is deprecated in $class_name and will be removed before Drupal 11.0.0.", E_USER_DEPRECATED);
      return \Drupal::service($service_name);
    }

    return NULL;
  }

}