Mercurial > hg > isophonics-drupal-site
annotate vendor/nikic/php-parser/lib/PhpParser/Builder/Trait_.php @ 2:92f882872392
Trusted hosts, + remove migration modules
author | Chris Cannam |
---|---|
date | Tue, 05 Dec 2017 09:26:43 +0000 |
parents | 4c8ae668cc8c |
children | 5fb285c0d0e3 |
rev | line source |
---|---|
Chris@0 | 1 <?php |
Chris@0 | 2 |
Chris@0 | 3 namespace PhpParser\Builder; |
Chris@0 | 4 |
Chris@0 | 5 use PhpParser; |
Chris@0 | 6 use PhpParser\Node\Stmt; |
Chris@0 | 7 |
Chris@0 | 8 class Trait_ extends Declaration |
Chris@0 | 9 { |
Chris@0 | 10 protected $name; |
Chris@0 | 11 protected $uses = array(); |
Chris@0 | 12 protected $properties = array(); |
Chris@0 | 13 protected $methods = array(); |
Chris@0 | 14 |
Chris@0 | 15 /** |
Chris@0 | 16 * Creates an interface builder. |
Chris@0 | 17 * |
Chris@0 | 18 * @param string $name Name of the interface |
Chris@0 | 19 */ |
Chris@0 | 20 public function __construct($name) { |
Chris@0 | 21 $this->name = $name; |
Chris@0 | 22 } |
Chris@0 | 23 |
Chris@0 | 24 /** |
Chris@0 | 25 * Adds a statement. |
Chris@0 | 26 * |
Chris@0 | 27 * @param Stmt|PhpParser\Builder $stmt The statement to add |
Chris@0 | 28 * |
Chris@0 | 29 * @return $this The builder instance (for fluid interface) |
Chris@0 | 30 */ |
Chris@0 | 31 public function addStmt($stmt) { |
Chris@0 | 32 $stmt = $this->normalizeNode($stmt); |
Chris@0 | 33 |
Chris@0 | 34 if ($stmt instanceof Stmt\Property) { |
Chris@0 | 35 $this->properties[] = $stmt; |
Chris@0 | 36 } else if ($stmt instanceof Stmt\ClassMethod) { |
Chris@0 | 37 $this->methods[] = $stmt; |
Chris@0 | 38 } else if ($stmt instanceof Stmt\TraitUse) { |
Chris@0 | 39 $this->uses[] = $stmt; |
Chris@0 | 40 } else { |
Chris@0 | 41 throw new \LogicException(sprintf('Unexpected node of type "%s"', $stmt->getType())); |
Chris@0 | 42 } |
Chris@0 | 43 |
Chris@0 | 44 return $this; |
Chris@0 | 45 } |
Chris@0 | 46 |
Chris@0 | 47 /** |
Chris@0 | 48 * Returns the built trait node. |
Chris@0 | 49 * |
Chris@0 | 50 * @return Stmt\Trait_ The built interface node |
Chris@0 | 51 */ |
Chris@0 | 52 public function getNode() { |
Chris@0 | 53 return new Stmt\Trait_( |
Chris@0 | 54 $this->name, array( |
Chris@0 | 55 'stmts' => array_merge($this->uses, $this->properties, $this->methods) |
Chris@0 | 56 ), $this->attributes |
Chris@0 | 57 ); |
Chris@0 | 58 } |
Chris@0 | 59 } |