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

namespace 
PhpParserBuilder;

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

class 
Interface_ extends Declaration
{
    protected 
$name;
    protected 
$extends = [];
    protected 
$constants = [];
    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;
    }

    
/**
     * Extends one or more interfaces.
     *
     * @param Name|string ...$interfaces Names of interfaces to extend
     *
     * @return $this The builder instance (for fluid interface)
     */
    
public function extend(...$interfaces) {
        foreach (
$interfaces as $interface) {
            
$this->extends[] = BuilderHelpers::normalizeName($interface);
        }

        return 
$this;
    }

    
/**
     * 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 StmtClassConst) {
            
$this->constants[] = $stmt;
        } elseif (
$stmt instanceof StmtClassMethod) {
            
// we erase all statements in the body of an interface method
            
$stmt->stmts null;
            
$this->methods[] = $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 interface node.
     *
     * @return StmtInterface_ The built interface node
     */
    
public function getNode() : PhpParserNode {
        return new 
StmtInterface_($this->name, [
            
'extends' => $this->extends,
            
'stmts' => array_merge($this->constants$this->methods),
            
'attrGroups' => $this->attributeGroups,
        ], 
$this->attributes);
    }
}
Онлайн: 0
Реклама