2011-10-26 18:34:12 +02:00
|
|
|
<?php
|
|
|
|
|
2014-02-06 14:44:16 +01:00
|
|
|
namespace PhpParser\Node\Expr;
|
|
|
|
|
|
|
|
use PhpParser\Node;
|
|
|
|
use PhpParser\Node\Expr;
|
2015-06-01 18:32:25 +02:00
|
|
|
use PhpParser\Node\FunctionLike;
|
2014-02-06 14:44:16 +01:00
|
|
|
|
2015-06-01 18:32:25 +02:00
|
|
|
class Closure extends Expr implements FunctionLike
|
2011-10-26 18:34:12 +02:00
|
|
|
{
|
2015-02-28 18:44:28 +01:00
|
|
|
/** @var bool Whether the closure is static */
|
|
|
|
public $static;
|
|
|
|
/** @var bool Whether to return by reference */
|
|
|
|
public $byRef;
|
|
|
|
/** @var Node\Param[] Parameters */
|
|
|
|
public $params;
|
|
|
|
/** @var ClosureUse[] use()s */
|
|
|
|
public $uses;
|
2017-04-28 19:09:39 +02:00
|
|
|
/** @var null|Node\Identifier|Node\Name|Node\NullableType Return type */
|
2015-03-12 13:17:31 +01:00
|
|
|
public $returnType;
|
2017-01-19 22:46:28 +01:00
|
|
|
/** @var Node\Stmt[] Statements */
|
2015-02-28 18:44:28 +01:00
|
|
|
public $stmts;
|
|
|
|
|
2011-10-26 18:34:12 +02:00
|
|
|
/**
|
|
|
|
* Constructs a lambda function node.
|
|
|
|
*
|
2012-04-29 23:32:09 +02:00
|
|
|
* @param array $subNodes Array of the following optional subnodes:
|
2015-03-12 13:17:31 +01:00
|
|
|
* 'static' => false : Whether the closure is static
|
|
|
|
* 'byRef' => false : Whether to return by reference
|
|
|
|
* 'params' => array(): Parameters
|
|
|
|
* 'uses' => array(): use()s
|
|
|
|
* 'returnType' => null : Return type
|
|
|
|
* 'stmts' => array(): Statements
|
2012-04-29 23:32:09 +02:00
|
|
|
* @param array $attributes Additional attributes
|
2011-10-26 18:34:12 +02:00
|
|
|
*/
|
2017-08-13 14:06:08 +02:00
|
|
|
public function __construct(array $subNodes = [], array $attributes = []) {
|
2015-05-02 22:17:34 +02:00
|
|
|
parent::__construct($attributes);
|
2017-04-24 22:32:40 +02:00
|
|
|
$this->static = $subNodes['static'] ?? false;
|
|
|
|
$this->byRef = $subNodes['byRef'] ?? false;
|
2017-08-13 14:06:08 +02:00
|
|
|
$this->params = $subNodes['params'] ?? [];
|
|
|
|
$this->uses = $subNodes['uses'] ?? [];
|
2017-04-28 19:09:39 +02:00
|
|
|
$returnType = $subNodes['returnType'] ?? null;
|
|
|
|
$this->returnType = \is_string($returnType) ? new Node\Identifier($returnType) : $returnType;
|
2017-08-13 14:06:08 +02:00
|
|
|
$this->stmts = $subNodes['stmts'] ?? [];
|
2015-02-28 18:44:28 +01:00
|
|
|
}
|
|
|
|
|
2017-04-28 21:40:59 +02:00
|
|
|
public function getSubNodeNames() : array {
|
2017-08-13 14:06:08 +02:00
|
|
|
return ['static', 'byRef', 'params', 'uses', 'returnType', 'stmts'];
|
2011-10-26 18:34:12 +02:00
|
|
|
}
|
2015-06-01 18:32:25 +02:00
|
|
|
|
2017-04-28 21:40:59 +02:00
|
|
|
public function returnsByRef() : bool {
|
2015-06-01 18:32:25 +02:00
|
|
|
return $this->byRef;
|
|
|
|
}
|
|
|
|
|
2017-04-28 21:40:59 +02:00
|
|
|
public function getParams() : array {
|
2015-06-01 18:32:25 +02:00
|
|
|
return $this->params;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getReturnType() {
|
|
|
|
return $this->returnType;
|
|
|
|
}
|
|
|
|
|
2017-05-07 19:54:32 +02:00
|
|
|
/** @return Node\Stmt[] */
|
2017-04-28 21:40:59 +02:00
|
|
|
public function getStmts() : array {
|
2015-06-01 18:32:25 +02:00
|
|
|
return $this->stmts;
|
|
|
|
}
|
2015-02-28 18:44:28 +01:00
|
|
|
}
|