class Interface_
Same name in this branch
- 11.1.x vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Interface_.php \PhpParser\Node\Stmt\Interface_
Hierarchy
- class \PhpParser\Builder\Declaration implements \PhpParser\Builder
- class \PhpParser\Builder\Interface_ extends \PhpParser\Builder\Declaration
Expanded class hierarchy of Interface_
File
-
vendor/
nikic/ php-parser/ lib/ PhpParser/ Builder/ Interface_.php, line 11
Namespace
PhpParser\BuilderView source
class Interface_ extends Declaration {
protected string $name;
/** @var list<Name> */
protected array $extends = [];
/** @var list<Stmt\ClassConst> */
protected array $constants = [];
/** @var list<Stmt\ClassMethod> */
protected array $methods = [];
/** @var list<Node\AttributeGroup> */
protected array $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|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\ClassConst) {
$this->constants[] = $stmt;
}
elseif ($stmt instanceof Stmt\ClassMethod) {
// 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 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 interface node.
*
* @return Stmt\Interface_ The built interface node
*/
public function getNode() : PhpParser\Node {
return new Stmt\Interface_($this->name, [
'extends' => $this->extends,
'stmts' => array_merge($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<string, mixed> | |
Declaration::addStmts | public | function | Adds multiple statements. | |
Declaration::setDocComment | public | function | Sets doc comment for the declaration. | |
Interface_::$attributeGroups | protected | property | @var list<Node\AttributeGroup> | |
Interface_::$constants | protected | property | @var list<Stmt\ClassConst> | |
Interface_::$extends | protected | property | @var list<Name> | |
Interface_::$methods | protected | property | @var list<Stmt\ClassMethod> | |
Interface_::$name | protected | property | ||
Interface_::addAttribute | public | function | Adds an attribute group. | |
Interface_::addStmt | public | function | Adds a statement. | Overrides Declaration::addStmt |
Interface_::extend | public | function | Extends one or more interfaces. | |
Interface_::getNode | public | function | Returns the built interface node. | Overrides Builder::getNode |
Interface_::__construct | public | function | Creates an interface builder. |