Вход Регистрация
Файл: vendor/nikic/php-parser/lib/PhpParser/Builder/Trait_.php
Строк: 57
<?php declare(strict_types=1);

namespace 
PhpParserBuilder;

use 
PhpParser;
use 
PhpParserBuilderHelpers;
use 
PhpParserNode;
use 
PhpParserNodeStmt;

class 
Trait_ extends Declaration
{
    protected 
$name;
    protected 
$uses = [];
    protected 
$properties = [];
    protected 
$methods = [];

    
/** @var NodeAttributeGroup[] */
    
protected $attributeGroups = [];

    
/**
     * Creates an interface builder.
     *
     * @param string $name Name of the interface
     */
    
public function __construct(string $name) {
        
$this->name $name;
    }

    
/**
     * Adds a statement.
     *
     * @param Stmt|PhpParserBuilder $stmt The statement to add
     *
     * @return $this The builder instance (for fluid interface)
     */
    
public function addStmt($stmt) {
        
$stmt BuilderHelpers::normalizeNode($stmt);

        if (
$stmt instanceof StmtProperty) {
            
$this->properties[] = $stmt;
        } elseif (
$stmt instanceof StmtClassMethod) {
            
$this->methods[] = $stmt;
        } elseif (
$stmt instanceof StmtTraitUse) {
            
$this->uses[] = $stmt;
        } else {
            throw new 
LogicException(sprintf('Unexpected node of type "%s"'$stmt->getType()));
        }

        return 
$this;
    }

    
/**
     * Adds an attribute group.
     *
     * @param NodeAttribute|NodeAttributeGroup $attribute
     *
     * @return $this The builder instance (for fluid interface)
     */
    
public function addAttribute($attribute) {
        
$this->attributeGroups[] = BuilderHelpers::normalizeAttribute($attribute);

        return 
$this;
    }

    
/**
     * Returns the built trait node.
     *
     * @return StmtTrait_ The built interface node
     */
    
public function getNode() : PhpParserNode {
        return new 
StmtTrait_(
            
$this->name, [
                
'stmts' => array_merge($this->uses$this->properties$this->methods),
                
'attrGroups' => $this->attributeGroups,
            ], 
$this->attributes
        
);
    }
}
Онлайн: 0
Реклама