No Description

Trait_.php 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace PhpParser\Builder;
  3. use PhpParser;
  4. use PhpParser\Node\Name;
  5. use PhpParser\Node\Stmt;
  6. class Trait_ extends Declaration
  7. {
  8. protected $name;
  9. protected $methods = array();
  10. /**
  11. * Creates an interface builder.
  12. *
  13. * @param string $name Name of the interface
  14. */
  15. public function __construct($name) {
  16. $this->name = $name;
  17. }
  18. /**
  19. * Adds a statement.
  20. *
  21. * @param Stmt|PhpParser\Builder $stmt The statement to add
  22. *
  23. * @return $this The builder instance (for fluid interface)
  24. */
  25. public function addStmt($stmt) {
  26. $stmt = $this->normalizeNode($stmt);
  27. if (!$stmt instanceof Stmt\ClassMethod) {
  28. throw new \LogicException(sprintf('Unexpected node of type "%s"', $stmt->getType()));
  29. }
  30. $this->methods[] = $stmt;
  31. return $this;
  32. }
  33. /**
  34. * Returns the built trait node.
  35. *
  36. * @return Stmt\Trait_ The built interface node
  37. */
  38. public function getNode() {
  39. return new Stmt\Trait_($this->name, $this->methods, $this->attributes);
  40. }
  41. }