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

Breadcrumb

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

class Enum_

Same name in this branch
  1. 11.1.x vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Enum_.php \PhpParser\Node\Stmt\Enum_

Hierarchy

  • class \PhpParser\Builder\Declaration implements \PhpParser\Builder
    • class \PhpParser\Builder\Enum_ extends \PhpParser\Builder\Declaration

Expanded class hierarchy of Enum_

File

vendor/nikic/php-parser/lib/PhpParser/Builder/Enum_.php, line 12

Namespace

PhpParser\Builder
View source
class Enum_ extends Declaration {
    protected string $name;
    protected ?Identifier $scalarType = null;
    
    /** @var list<Name> */
    protected array $implements = [];
    
    /** @var list<Stmt\TraitUse> */
    protected array $uses = [];
    
    /** @var list<Stmt\EnumCase> */
    protected array $enumCases = [];
    
    /** @var list<Stmt\ClassConst> */
    protected array $constants = [];
    
    /** @var list<Stmt\ClassMethod> */
    protected array $methods = [];
    
    /** @var list<Node\AttributeGroup> */
    protected array $attributeGroups = [];
    
    /**
     * Creates an enum builder.
     *
     * @param string $name Name of the enum
     */
    public function __construct(string $name) {
        $this->name = $name;
    }
    
    /**
     * Sets the scalar type.
     *
     * @param string|Identifier $scalarType
     *
     * @return $this
     */
    public function setScalarType($scalarType) {
        $this->scalarType = BuilderHelpers::normalizeType($scalarType);
        return $this;
    }
    
    /**
     * Implements one or more interfaces.
     *
     * @param Name|string ...$interfaces Names of interfaces to implement
     *
     * @return $this The builder instance (for fluid interface)
     */
    public function implement(...$interfaces) {
        foreach ($interfaces as $interface) {
            $this->implements[] = BuilderHelpers::normalizeName($interface);
        }
        return $this;
    }
    
    /**
     * Adds a statement.
     *
     * @param Stmt|PhpParser\Builder $stmt The statement to add
     *
     * @return $this The builder instance (for fluid interface)
     */
    public function addStmt($stmt) {
        $stmt = BuilderHelpers::normalizeNode($stmt);
        if ($stmt instanceof Stmt\EnumCase) {
            $this->enumCases[] = $stmt;
        }
        elseif ($stmt instanceof Stmt\ClassMethod) {
            $this->methods[] = $stmt;
        }
        elseif ($stmt instanceof Stmt\TraitUse) {
            $this->uses[] = $stmt;
        }
        elseif ($stmt instanceof Stmt\ClassConst) {
            $this->constants[] = $stmt;
        }
        else {
            throw new \LogicException(sprintf('Unexpected node of type "%s"', $stmt->getType()));
        }
        return $this;
    }
    
    /**
     * Adds an attribute group.
     *
     * @param Node\Attribute|Node\AttributeGroup $attribute
     *
     * @return $this The builder instance (for fluid interface)
     */
    public function addAttribute($attribute) {
        $this->attributeGroups[] = BuilderHelpers::normalizeAttribute($attribute);
        return $this;
    }
    
    /**
     * Returns the built class node.
     *
     * @return Stmt\Enum_ The built enum node
     */
    public function getNode() : PhpParser\Node {
        return new Stmt\Enum_($this->name, [
            'scalarType' => $this->scalarType,
            'implements' => $this->implements,
            'stmts' => array_merge($this->uses, $this->enumCases, $this->constants, $this->methods),
            'attrGroups' => $this->attributeGroups,
        ], $this->attributes);
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
Declaration::$attributes protected property @var array&lt;string, mixed&gt;
Declaration::addStmts public function Adds multiple statements.
Declaration::setDocComment public function Sets doc comment for the declaration.
Enum_::$attributeGroups protected property @var list&lt;Node\AttributeGroup&gt;
Enum_::$constants protected property @var list&lt;Stmt\ClassConst&gt;
Enum_::$enumCases protected property @var list&lt;Stmt\EnumCase&gt;
Enum_::$implements protected property @var list&lt;Name&gt;
Enum_::$methods protected property @var list&lt;Stmt\ClassMethod&gt;
Enum_::$name protected property
Enum_::$scalarType protected property
Enum_::$uses protected property @var list&lt;Stmt\TraitUse&gt;
Enum_::addAttribute public function Adds an attribute group.
Enum_::addStmt public function Adds a statement. Overrides Declaration::addStmt
Enum_::getNode public function Returns the built class node. Overrides Builder::getNode
Enum_::implement public function Implements one or more interfaces.
Enum_::setScalarType public function Sets the scalar type.
Enum_::__construct public function Creates an enum builder.

API Navigation

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