123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- <?php
- namespace PhpParser\Builder;
- use PhpParser;
- use PhpParser\Node;
- use PhpParser\Node\Stmt;
- abstract class FunctionLike extends Declaration
- {
- protected $returnByRef = false;
- protected $params = array();
- protected $returnType = null;
-
- public function makeReturnByRef() {
- $this->returnByRef = true;
- return $this;
- }
-
- 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;
- }
-
- public function addParams(array $params) {
- foreach ($params as $param) {
- $this->addParam($param);
- }
- return $this;
- }
-
- 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;
- }
- }
|