public function __construct(\PHPParser_Node_Stmt_Class $class, \PHPParser_Node_Stmt_Trait $trait, \PHPParser_Node_Stmt_TraitUse $traitUse) { foreach ($class->getMethods() as $method) { $this->classMethods[] = $method->name; } $this->trait = $trait; $this->traitUse = $traitUse; }
public function buildClassObjectFromNode(PHPParser_Node_Stmt_Class $classNode) { $classObject = new Tx_PhpParser_Domain_Model_Class($classNode->getName()); $classObject->setNode($classNode); foreach ($classNode->getImplements() as $interfaceNode) { $classObject->addInterfaceName(Tx_PhpParser_Parser_Utility_NodeConverter::getValueFromNode($interfaceNode), FALSE); } $classObject->setParentClassName(Tx_PhpParser_Parser_Utility_NodeConverter::getValueFromNode($classNode->getExtends()), FALSE); $classObject->setModifiers($classNode->getType()); $classObject->initDocComment(); return $classObject; }
/** * Constructs a class property list node. * * @param array $tree Tree * @param int $line Line * @param null|string $docComment Nearest doc comment */ public function __construct(array $tree, $line = -1, $docComment = null) { $modifier = 0; while (is_array($tree[1])) { PHPParser_Node_Stmt_Class::verifyModifier($modifier, $tree[0]); $modifier |= $tree[0]; $tree = $tree[1]; } if (is_int($tree[0])) { PHPParser_Node_Stmt_Class::verifyModifier($modifier, $tree[0]); $modifier |= $tree[0]; } parent::__construct(array('modifier' => $modifier, 'stmts' => isset($tree[1]->stmts) ? $tree[1]->stmts : array($tree)), $line, $docComment); }
/** * validate if the modifier can be added to the current modifiers or not * * @param $modifier * @throws \EBT\ExtensionBuilder\Exception\FileNotFoundException * @throws \EBT\ExtensionBuilder\Exception\SyntaxErrorException */ protected function validateModifier($modifier) { if ($modifier == \PHPParser_Node_Stmt_Class::MODIFIER_FINAL && $this->isAbstract() || $modifier == \PHPParser_Node_Stmt_Class::MODIFIER_ABSTRACT && $this->isFinal()) { throw new \EBT\ExtensionBuilder\Exception\SyntaxErrorException('Abstract and Final can\'t be applied both to same object'); } elseif ($modifier == \PHPParser_Node_Stmt_Class::MODIFIER_STATIC && $this->isAbstract() || $modifier == \PHPParser_Node_Stmt_Class::MODIFIER_ABSTRACT && $this->isStatic()) { throw new \EBT\ExtensionBuilder\Exception\FileNotFoundException('Abstract and Static can\'t be applied both to same object'); } try { \PHPParser_Node_Stmt_Class::verifyModifier($this->modifiers, $modifier); } catch (\PHPParser_Error $e) { throw new \EBT\ExtensionBuilder\Exception\SyntaxErrorException('Only one access modifier can be applied to one object. Use setModifier to avoid this exception'); } }
protected function yyn166($attributes) { PHPParser_Node_Stmt_Class::verifyModifier($this->yyastk[$this->stackPos - (2 - 1)], $this->yyastk[$this->stackPos - (2 - 2)]); $this->yyval = $this->yyastk[$this->stackPos - (2 - 1)] | $this->yyastk[$this->stackPos - (2 - 2)]; }
protected function yyn142($line, $docComment) { PHPParser_Node_Stmt_Class::verifyModifier($this->yyastk[$this->yysp - (2 - 1)], $this->yyastk[$this->yysp - (2 - 2)]); $this->yyval = $this->yyastk[$this->yysp - (2 - 1)] | $this->yyastk[$this->yysp - (2 - 2)]; }
/** * validate if the modifier can be added to the current modifiers or not * * @param $modifier * @throws Tx_PhpParser_Exception_SyntaxErrorException */ protected function validateModifier($modifier) { if ($modifier == PHPParser_Node_Stmt_Class::MODIFIER_FINAL && $this->isAbstract() || $modifier == PHPParser_Node_Stmt_Class::MODIFIER_ABSTRACT && $this->isFinal()) { throw new Tx_PhpParser_Exception_SyntaxErrorException('Abstract and Final can\'t be applied both to same object'); } elseif ($modifier == PHPParser_Node_Stmt_Class::MODIFIER_STATIC && $this->isAbstract() || $modifier == PHPParser_Node_Stmt_Class::MODIFIER_ABSTRACT && $this->isStatic()) { throw new Tx_PhpParser_Exception_SyntaxErrorException('Abstract and Static can\'t be applied both to same object'); } try { PHPParser_Node_Stmt_Class::verifyModifier($this->modifiers, $modifier); } catch (Exception $e) { //debug('Error: ' . $e->getMessage(), 'Error'); throw new Tx_PhpParser_Exception_SyntaxErrorException('Only one access modifier can be applied to one object. Use setModifier to avoid this exception'); //return FALSE; } }
public function testGetMethods() { $methods = array(new PHPParser_Node_Stmt_ClassMethod('foo'), new PHPParser_Node_Stmt_ClassMethod('bar'), new PHPParser_Node_Stmt_ClassMethod('fooBar')); $class = new PHPParser_Node_Stmt_Class('Foo', array('stmts' => array(new PHPParser_Node_Stmt_TraitUse(array()), $methods[0], new PHPParser_Node_Stmt_Const(array()), $methods[1], new PHPParser_Node_Stmt_Property(0, array()), $methods[2]))); $this->assertEquals($methods, $class->getMethods()); }
/** * Sets a modifier in the $this->type property. * * @param int $modifier Modifier to set */ protected function setModifier($modifier) { PHPParser_Node_Stmt_Class::verifyModifier($this->type, $modifier); $this->type |= $modifier; }