Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Deprecation.php

function Deprecation::triggerIfCalledFromOutside

Trigger a deprecation for the given package and identifier when called from outside.

"Outside" means we assume that $package is currently installed as a dependency and the caller is not a file in that package. When $package is installed as a root package then deprecations triggered from the tests folder are also considered "outside".

This deprecation method assumes that you are using Composer to install the dependency and are using the default /vendor/ folder and not a Composer plugin to change the install location. The assumption is also that $package is the exact composer packge name.

Compared to {@link trigger()} this method causes some overhead when deprecation tracking is enabled even during deduplication, because it needs to call {@link debug_backtrace()}

Parameters

float|int|string $args:

6 calls to Deprecation::triggerIfCalledFromOutside()
Param::create in vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Param.php
Property::create in vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Property.php
PropertyRead::create in vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/PropertyRead.php
PropertyWrite::create in vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/PropertyWrite.php
Return_::create in vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Return_.php

... See full list

File

vendor/doctrine/deprecations/lib/Doctrine/Deprecations/Deprecation.php, line 130

Class

Deprecation
Manages Deprecation logging in different ways.

Namespace

Doctrine\Deprecations

Code

public static function triggerIfCalledFromOutside(string $package, string $link, string $message, ...$args) : void {
    $type = self::$type ?? self::getTypeFromEnv();
    if ($type === self::TYPE_NONE) {
        return;
    }
    $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
    // first check that the caller is not from a tests folder, in which case we always let deprecations pass
    if (isset($backtrace[1]['file'], $backtrace[0]['file']) && strpos($backtrace[1]['file'], DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR) === false) {
        $path = DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $package) . DIRECTORY_SEPARATOR;
        if (strpos($backtrace[0]['file'], $path) === false) {
            return;
        }
        if (strpos($backtrace[1]['file'], $path) !== false) {
            return;
        }
    }
    if (isset(self::$ignoredLinks[$link])) {
        return;
    }
    if (array_key_exists($link, self::$triggeredDeprecations)) {
        self::$triggeredDeprecations[$link]++;
    }
    else {
        self::$triggeredDeprecations[$link] = 1;
    }
    if (self::$deduplication === true && self::$triggeredDeprecations[$link] > 1) {
        return;
    }
    if (isset(self::$ignoredPackages[$package])) {
        return;
    }
    $message = sprintf($message, ...$args);
    self::delegateTriggerToBackend($message, $backtrace, $link, $package);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal