12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- <?php
- namespace PhpParser\Builder;
- use PhpParser;
- use PhpParser\Node\Name;
- use PhpParser\Node\Stmt;
- class Trait_ extends Declaration
- {
- protected $name;
- protected $properties = array();
- protected $methods = array();
-
- public function __construct($name) {
- $this->name = $name;
- }
-
- public function addStmt($stmt) {
- $stmt = $this->normalizeNode($stmt);
- if ($stmt instanceof Stmt\Property) {
- $this->properties[] = $stmt;
- } else if ($stmt instanceof Stmt\ClassMethod) {
- $this->methods[] = $stmt;
- } else {
- throw new \LogicException(sprintf('Unexpected node of type "%s"', $stmt->getType()));
- }
- return $this;
- }
-
- public function getNode() {
- return new Stmt\Trait_(
- $this->name, array_merge($this->properties, $this->methods), $this->attributes
- );
- }
- }
|