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

Breadcrumb

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

function BuilderHelpers::normalizeName

Normalizes a name: Converts string names to Name nodes.

Parameters

Name|string $name The name to normalize:

Return value

Name The normalized name

13 calls to BuilderHelpers::normalizeName()
BuilderFactory::attribute in vendor/nikic/php-parser/lib/PhpParser/BuilderFactory.php
Creates an attribute node.
BuilderFactory::constFetch in vendor/nikic/php-parser/lib/PhpParser/BuilderFactory.php
Creates a constant fetch node.
BuilderHelpers::normalizeNameOrExpr in vendor/nikic/php-parser/lib/PhpParser/BuilderHelpers.php
Normalizes a name: Converts string names to Name nodes, while also allowing expressions.
BuilderHelpers::normalizeType in vendor/nikic/php-parser/lib/PhpParser/BuilderHelpers.php
Normalizes a type: Converts plain-text type names into proper AST representation.
Class_::extend in vendor/nikic/php-parser/lib/PhpParser/Builder/Class_.php
Extends a class.

... See full list

File

vendor/nikic/php-parser/lib/PhpParser/BuilderHelpers.php, line 106

Class

BuilderHelpers
This class defines helpers used in the implementation of builders. Don't use it directly.

Namespace

PhpParser

Code

public static function normalizeName($name) : Name {
    if ($name instanceof Name) {
        return $name;
    }
    if (is_string($name)) {
        if (!$name) {
            throw new \LogicException('Name cannot be empty');
        }
        if ($name[0] === '\\') {
            return new Name\FullyQualified(substr($name, 1));
        }
        if (0 === strpos($name, 'namespace\\')) {
            return new Name\Relative(substr($name, strlen('namespace\\')));
        }
        return new Name($name);
    }
    throw new \LogicException('Name must be a string or an instance of Node\\Name');
}

API Navigation

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