Chris@0: name = $name; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Extends a class. Chris@0: * Chris@0: * @param Name|string $class Name of class to extend Chris@0: * Chris@0: * @return $this The builder instance (for fluid interface) Chris@0: */ Chris@0: public function extend($class) { Chris@0: $this->extends = $this->normalizeName($class); Chris@0: Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Implements one or more interfaces. Chris@0: * Chris@0: * @param Name|string ...$interfaces Names of interfaces to implement Chris@0: * Chris@0: * @return $this The builder instance (for fluid interface) Chris@0: */ Chris@0: public function implement() { Chris@0: foreach (func_get_args() as $interface) { Chris@0: $this->implements[] = $this->normalizeName($interface); Chris@0: } Chris@0: Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Makes the class abstract. Chris@0: * Chris@0: * @return $this The builder instance (for fluid interface) Chris@0: */ Chris@0: public function makeAbstract() { Chris@0: $this->setModifier(Stmt\Class_::MODIFIER_ABSTRACT); Chris@0: Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Makes the class final. Chris@0: * Chris@0: * @return $this The builder instance (for fluid interface) Chris@0: */ Chris@0: public function makeFinal() { Chris@0: $this->setModifier(Stmt\Class_::MODIFIER_FINAL); Chris@0: Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Adds a statement. Chris@0: * Chris@0: * @param Stmt|PhpParser\Builder $stmt The statement to add Chris@0: * Chris@0: * @return $this The builder instance (for fluid interface) Chris@0: */ Chris@0: public function addStmt($stmt) { Chris@0: $stmt = $this->normalizeNode($stmt); Chris@0: Chris@0: $targets = array( Chris@0: 'Stmt_TraitUse' => &$this->uses, Chris@0: 'Stmt_ClassConst' => &$this->constants, Chris@0: 'Stmt_Property' => &$this->properties, Chris@0: 'Stmt_ClassMethod' => &$this->methods, Chris@0: ); Chris@0: Chris@0: $type = $stmt->getType(); Chris@0: if (!isset($targets[$type])) { Chris@0: throw new \LogicException(sprintf('Unexpected node of type "%s"', $type)); Chris@0: } Chris@0: Chris@0: $targets[$type][] = $stmt; Chris@0: Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the built class node. Chris@0: * Chris@0: * @return Stmt\Class_ The built class node Chris@0: */ Chris@0: public function getNode() { Chris@0: return new Stmt\Class_($this->name, array( Chris@0: 'flags' => $this->flags, Chris@0: 'extends' => $this->extends, Chris@0: 'implements' => $this->implements, Chris@0: 'stmts' => array_merge($this->uses, $this->constants, $this->properties, $this->methods), Chris@0: ), $this->attributes); Chris@0: } Chris@0: }