本文整理汇总了PHP中PHPParser_Node_Stmt类的典型用法代码示例。如果您正苦于以下问题:PHP PHPParser_Node_Stmt类的具体用法?PHP PHPParser_Node_Stmt怎么用?PHP PHPParser_Node_Stmt使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PHPParser_Node_Stmt类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* 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);
}
示例2: __construct
/**
* 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));
}
}
示例3: __construct
/**
* 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);
}
示例4: __construct
/**
* 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());
}
}
}
}
示例5: __construct
/**
* 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));
}
}
}
示例6: __construct
/**
* 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);
}
示例7: __construct
/**
* 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);
}
示例8: __construct
/**
* 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);
}
示例9: __construct
/**
* 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);
}
示例10: __construct
/**
* 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));
}
}
}
示例11: __construct
/**
* 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));
}
}
}
示例12: __construct
/**
* 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);
}
示例13: __construct
/**
* 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;
}
示例14: __construct
/**
* 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);
}
示例15: __construct
/**
* 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);
}