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

Breadcrumb

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

function NameContext::addAlias

Add an alias / import.

Parameters

Name $name Original name:

string $aliasName Aliased name:

Stmt\Use_::TYPE_* $type One of Stmt\Use_::TYPE_*:

array<string, mixed> $errorAttrs Attributes to use to report an error:

File

vendor/nikic/php-parser/lib/PhpParser/NameContext.php, line 55

Class

NameContext

Namespace

PhpParser

Code

public function addAlias(Name $name, string $aliasName, int $type, array $errorAttrs = []) : void {
    // Constant names are case sensitive, everything else case insensitive
    if ($type === Stmt\Use_::TYPE_CONSTANT) {
        $aliasLookupName = $aliasName;
    }
    else {
        $aliasLookupName = strtolower($aliasName);
    }
    if (isset($this->aliases[$type][$aliasLookupName])) {
        $typeStringMap = [
            Stmt\Use_::TYPE_NORMAL => '',
            Stmt\Use_::TYPE_FUNCTION => 'function ',
            Stmt\Use_::TYPE_CONSTANT => 'const ',
        ];
        $this->errorHandler
            ->handleError(new Error(sprintf('Cannot use %s%s as %s because the name is already in use', $typeStringMap[$type], $name, $aliasName), $errorAttrs));
        return;
    }
    $this->aliases[$type][$aliasLookupName] = $name;
    $this->origAliases[$type][$aliasName] = $name;
}

API Navigation

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