2014-12-19 17:21:46 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace PhpParser\Builder;
|
|
|
|
|
|
|
|
use PhpParser;
|
|
|
|
use PhpParser\Node;
|
|
|
|
use PhpParser\Node\Stmt;
|
|
|
|
|
|
|
|
abstract class FunctionLike extends Declaration
|
|
|
|
{
|
|
|
|
protected $returnByRef = false;
|
|
|
|
protected $params = array();
|
2016-04-09 11:41:38 +02:00
|
|
|
protected $returnType = null;
|
2014-12-19 17:21:46 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Make the function return by reference.
|
|
|
|
*
|
|
|
|
* @return $this The builder instance (for fluid interface)
|
|
|
|
*/
|
|
|
|
public function makeReturnByRef() {
|
|
|
|
$this->returnByRef = true;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a parameter.
|
|
|
|
*
|
|
|
|
* @param Node\Param|Param $param The parameter to add
|
|
|
|
*
|
|
|
|
* @return $this The builder instance (for fluid interface)
|
|
|
|
*/
|
|
|
|
public function addParam($param) {
|
|
|
|
$param = $this->normalizeNode($param);
|
|
|
|
|
|
|
|
if (!$param instanceof Node\Param) {
|
|
|
|
throw new \LogicException(sprintf('Expected parameter node, got "%s"', $param->getType()));
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->params[] = $param;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds multiple parameters.
|
|
|
|
*
|
|
|
|
* @param array $params The parameters to add
|
|
|
|
*
|
|
|
|
* @return $this The builder instance (for fluid interface)
|
|
|
|
*/
|
|
|
|
public function addParams(array $params) {
|
|
|
|
foreach ($params as $param) {
|
|
|
|
$this->addParam($param);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
2016-04-09 11:41:38 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* set the return type for php7
|
|
|
|
*
|
|
|
|
* @param string $type support string, int, float, bool, array,
|
|
|
|
* class names, interface and callable.
|
|
|
|
*
|
|
|
|
* @return $this The builder instance (for fluid interface)
|
|
|
|
*/
|
|
|
|
public function setReturnType($type)
|
|
|
|
{
|
|
|
|
if (in_array($type, array('array', 'callable', 'string', 'int', 'float', 'bool'))) {
|
|
|
|
$this->returnType = $type;
|
|
|
|
} else {
|
|
|
|
$this->returnType = $this->normalizeName($type);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
}
|