/** * Constructs a try catch node. * * @param PHPParser_Node[] $stmts Statements * @param PHPParser_Node_Stmt_Catch[] $catches Catches * @param PHPParser_Node[] $finallyStmts Finally statements (null means no finally clause) * @param array|null $attributes Additional attributes */ public function __construct(array $stmts, array $catches, array $finallyStmts = null, array $attributes = array()) { if (empty($catches) && null === $finallyStmts) { throw new PHPParser_Error('Cannot use try without catch or finally'); } parent::__construct(array('stmts' => $stmts, 'catches' => $catches, 'finallyStmts' => $finallyStmts), $attributes); }
/** * Constructs a class method node. * * @param string $name Name * @param array $subNodes Array of the following optional subnodes: * 'type' => MODIFIER_PUBLIC: Type * 'byRef' => false : Whether to return by reference * 'params' => array() : Parameters * 'stmts' => array() : Statements * @param int $line Line * @param null|string $docComment Nearest doc comment */ public function __construct($name, array $subNodes = array(), $line = -1, $docComment = null) { parent::__construct($subNodes + array('type' => PHPParser_Node_Stmt_Class::MODIFIER_PUBLIC, 'byRef' => false, 'params' => array(), 'stmts' => array()), $line, $docComment); $this->name = $name; if ($this->type & PHPParser_Node_Stmt_Class::MODIFIER_STATIC && ('__construct' == $this->name || '__destruct' == $this->name || '__clone' == $this->name)) { throw new PHPParser_Error(sprintf('"%s" method cannot be static', $this->name)); } }
/** * Constructs an alias (use) node. * * @param PHPParser_Node_Name $name Namespace/Class to alias * @param null|string $alias Alias * @param array $attributes Additional attributes */ public function __construct(PHPParser_Node_Name $name, $alias = null, array $attributes = array()) { if (null === $alias) { $alias = $name->getLast(); } if ('self' == $alias || 'parent' == $alias) { throw new PHPParser_Error(sprintf('Cannot use "%s" as "%s" because "%2$s" is a special class name', $name, $alias)); } parent::__construct(array('name' => $name, 'alias' => $alias), $attributes); }
/** * Constructs a class node. * * @param string $name Name * @param array $subNodes Array of the following optional subnodes: * 'extends' => array(): Name of extended interfaces * 'stmts' => array(): Statements * @param array $attributes Additional attributes */ public function __construct($name, array $subNodes = array(), array $attributes = array()) { parent::__construct($subNodes + array('extends' => array(), 'stmts' => array()), $attributes); $this->name = $name; if (isset(self::$specialNames[(string) $this->name])) { throw new PHPParser_Error(sprintf('Cannot use "%s" as interface name as it is reserved', $this->name)); } foreach ($this->extends as $interface) { if (isset(self::$specialNames[(string) $interface])) { throw new PHPParser_Error(sprintf('Cannot use "%s" as interface name as it is reserved', $interface)); } } }
/** * 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); }
/** * Constructs a namespace node. * * @param null|PHPParser_Node_Name $name Name * @param PHPParser_Node[] $stmts Statements * @param int $line Line * @param null|string $docComment Nearest doc comment */ public function __construct(PHPParser_Node_Name $name = null, $stmts = array(), $line = -1, $docComment = null) { parent::__construct(array('name' => $name, 'stmts' => $stmts), $line, $docComment); if (isset(self::$specialNames[(string) $this->name])) { throw new PHPParser_Error(sprintf('Cannot use "%s" as namespace name as it is reserved', $this->name)); } if (null !== $this->stmts) { foreach ($this->stmts as $stmt) { if ($stmt instanceof PHPParser_Node_Stmt_Namespace) { throw new PHPParser_Error('Namespace declarations cannot be nested', $stmt->getLine()); } } } }
/** * Constructs a class method node. * * @param string $name Name * @param array $subNodes Array of the following optional subnodes: * 'type' => MODIFIER_PUBLIC: Type * 'byRef' => false : Whether to return by reference * 'params' => array() : Parameters * 'stmts' => array() : Statements * @param array $attributes Additional attributes */ public function __construct($name, array $subNodes = array(), array $attributes = array()) { parent::__construct($subNodes + array('type' => PHPParser_Node_Stmt_Class::MODIFIER_PUBLIC, 'byRef' => false, 'params' => array(), 'stmts' => array()), $attributes); $this->name = $name; if ($this->type & PHPParser_Node_Stmt_Class::MODIFIER_STATIC) { switch (strtolower($this->name)) { case '__construct': throw new PHPParser_Error(sprintf('Constructor %s() cannot be static', $this->name)); case '__destruct': throw new PHPParser_Error(sprintf('Destructor %s() cannot be static', $this->name)); case '__clone': throw new PHPParser_Error(sprintf('Clone method %s() cannot be static', $this->name)); } } }
/** * Constructs a class node. * * @param string $name Name * @param array $subNodes Array of the following optional subnodes: * 'type' => 0 : Type * 'extends' => null : Name of extended class * 'implements' => array(): Names of implemented interfaces * 'stmts' => array(): Statements * @param int $line Line * @param null|string $docComment Nearest doc comment */ public function __construct($name, array $subNodes = array(), $line = -1, $docComment = null) { parent::__construct($subNodes + array('type' => 0, 'extends' => null, 'implements' => array(), 'stmts' => array()), $line, $docComment); $this->name = $name; if (isset(self::$specialNames[(string) $this->name])) { throw new PHPParser_Error(sprintf('Cannot use "%s" as class name as it is reserved', $this->name)); } if (isset(self::$specialNames[(string) $this->extends])) { throw new PHPParser_Error(sprintf('Cannot use "%s" as class name as it is reserved', $this->extends)); } foreach ($this->implements as $interface) { if (isset(self::$specialNames[(string) $interface])) { throw new PHPParser_Error(sprintf('Cannot use "%s" as interface name as it is reserved', $interface)); } } }
/** * Constructs a case node. * * @param null|PHPParser_Node_Expr $cond Condition (null for default) * @param PHPParser_Node[] $stmts Statements * @param int $line Line * @param null|string $docComment Nearest doc comment */ public function __construct($cond, array $stmts = array(), $line = -1, $docComment = null) { parent::__construct(array('stmts' => $stmts, 'cond' => $cond), $line, $docComment); }
/** * Constructs a class property list node. * * @param int $type Modifiers * @param PHPParser_Node_Stmt_PropertyProperty[] $props Properties * @param array $attributes Additional attributes */ public function __construct($type, array $props, array $attributes = array()) { parent::__construct(array('type' => $type, 'props' => $props), $attributes); }
/** * Constructs an if node. * * @param PHPParser_Node_Expr $cond Condition * @param array $subNodes Array of the following optional subnodes: * 'stmts' => array(): Statements * 'elseifs' => array(): Elseif clauses * 'else' => null : Else clause * @param array $attributes Additional attributes */ public function __construct(PHPParser_Node_Expr $cond, array $subNodes = array(), array $attributes = array()) { parent::__construct($subNodes + array('stmts' => array(), 'elseifs' => array(), 'else' => null), $attributes); $this->cond = $cond; }
/** * Constructs an unset node. * * @param PHPParser_Node_Expr[] $vars Variables to unset * @param int $line Line * @param null|string $docComment Nearest doc comment */ public function __construct(array $vars, $line = -1, $docComment = null) { parent::__construct(array('vars' => $vars), $line, $docComment); }
/** * Constructs a declare key=>value pair node. * * @param string $key Key * @param PHPParser_Node_Expr $value Value * @param array $attributes Additional attributes */ public function __construct($key, PHPParser_Node_Expr $value, array $attributes = array()) { parent::__construct(array('key' => $key, 'value' => $value), $attributes); }
/** * Returns the line number where this object starts. * * @return int */ public function getLinenumber() { return $this->node->getLine(); }
/** * Constructs an inline HTML node. * * @param string $value String * @param array $attributes Additional attributes */ public function __construct($value, array $attributes = array()) { parent::__construct(array('value' => $value), $attributes); }
/** * Constructs a class property list node. * * @param int $type Modifiers * @param PHPParser_Node_Stmt_PropertyProperty[] $props Properties * @param int $line Line * @param null|string $docComment Nearest doc comment */ public function __construct($stmts, $line = -1, $docComment = null) { parent::__construct(array('stmts' => $stmts), $line, $docComment); }
/** * Constructs a class const list node. * * @param PHPParser_Node_Const[] $consts Constant declarations * @param int $line Line * @param null|string $docComment Nearest doc comment */ public function __construct($name, PHPParser_Node_Scalar $value, $line = -1, $docComment = null) { parent::__construct(array('name' => $name, 'value' => array($value)), $line, $docComment); }
/** * Constructs a for loop node. * * @param array $subNodes Array of the following optional subnodes: * 'init' => array(): Init expressions * 'cond' => array(): Loop conditions * 'loop' => array(): Loop expressions * 'stmts' => array(): Statements * @param array $attributes Additional attributes */ public function __construct(array $subNodes = array(), array $attributes = array()) { parent::__construct($subNodes + array('init' => array(), 'cond' => array(), 'loop' => array(), 'stmts' => array()), $attributes); }
/** * Constructs a case node. * * @param PHPParser_Node_Expr $cond Condition * @param PHPParser_Node_Stmt_Case[] $cases Case list * @param array $attributes Additional attributes */ public function __construct(PHPParser_Node_Expr $cond, array $cases, array $attributes = array()) { parent::__construct(array('cond' => $cond, 'cases' => $cases), $attributes); }
/** * Constructs a continue node. * * @param null|PHPParser_Node_Expr $num Number of loops to continue * @param int $line Line * @param null|string $docComment Nearest doc comment */ public function __construct($name, $line = -1, $docComment = null) { parent::__construct(array('name' => ltrim($name, '$')), $line, $docComment); }
/** * Constructs an else node. * * @param PHPParser_Node[] $stmts Statements * @param array $attributes Additional attributes */ public function __construct(array $stmts = array(), array $attributes = array()) { parent::__construct(array('stmts' => $stmts), $attributes); }
/** * Constructs a function node. * * @param string $name Name * @param array $subNodes Array of the following optional subnodes: * 'byRef' => false : Whether to return by reference * 'params' => array(): Parameters * 'stmts' => array(): Statements * @param array $attributes Additional attributes */ public function __construct($name, array $subNodes = array(), array $attributes = array()) { parent::__construct($subNodes + array('byRef' => false, 'params' => array(), 'stmts' => array()), $attributes); $this->name = $name; }
/** * Constructs a static variable node. * * @param string $name Name * @param null|PHPParser_Node_Expr $default Default value * @param int $line Line * @param null|string $docComment Nearest doc comment */ public function __construct($name, PHPParser_Node_Expr $default = null, $line = -1, $docComment = null) { parent::__construct(array('name' => $name, 'default' => $default), $line, $docComment); }
/** * Constructs a class const list node. * * @param PHPParser_Node_Const[] $consts Constant declarations * @param array $attributes Additional attributes */ public function __construct(array $consts, array $attributes = array()) { parent::__construct(array('consts' => $consts), $attributes); }
/** * Constructs a __halt_compiler node. * * @param string $remaining Remaining text after halt compiler statement. * @param array $attributes Additional attributes */ public function __construct($remaining, array $attributes = array()) { parent::__construct(array('remaining' => $remaining), $attributes); }
/** * Constructs a static variable node. * * @param string $name Name * @param null|PHPParser_Node_Expr $default Default value * @param array $attributes Additional attributes */ public function __construct($name, PHPParser_Node_Expr $default = null, array $attributes = array()) { parent::__construct(array('name' => $name, 'default' => $default), $attributes); }
/** * Constructs a continue node. * * @param null|PHPParser_Node_Expr $num Number of loops to continue * @param array $attributes Additional attributes */ public function __construct(PHPParser_Node_Expr $num = null, array $attributes = array()) { parent::__construct(array('num' => $num), $attributes); }
/** * Constructs a foreach node. * * @param PHPParser_Node_Expr $expr Expression to iterate * @param PHPParser_Node_Expr $valueVar Variable to assign value to * @param array $subNodes Array of the following optional subnodes: * 'keyVar' => null : Variable to assign key to * 'byRef' => false : Whether to assign value by reference * 'stmts' => array(): Statements * @param array $attributes Additional attributes */ public function __construct(PHPParser_Node_Expr $expr, PHPParser_Node_Expr $valueVar, array $subNodes = array(), array $attributes = array()) { parent::__construct($subNodes + array('keyVar' => null, 'byRef' => false, 'stmts' => array()), $attributes); $this->expr = $expr; $this->valueVar = $valueVar; }
/** * Constructs a continue node. * * @param null|PHPParser_Node_Expr $num Number of loops to continue * @param int $line Line * @param null|string $docComment Nearest doc comment */ public function __construct(array $import_paths, array $imports, $line = -1, $docComment = null) { parent::__construct(array('import_paths' => $import_paths, 'imports' => $imports), $line, $docComment); }
/** * Constructs a __halt_compiler node. * * @param string $remaining Remaining text after halt compiler statement. * @param int $line Line * @param null|string $docComment Nearest doc comment */ public function __construct($remaining, $line = -1, $docComment = null) { parent::__construct(array('remaining' => $remaining), $line, $docComment); }