2011-05-27 18:20:44 +02:00
|
|
|
<?php
|
|
|
|
|
2014-02-06 14:44:16 +01:00
|
|
|
namespace PhpParser\Node\Stmt;
|
|
|
|
|
|
|
|
use PhpParser\Node;
|
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 ClassMethod extends Node\Stmt implements FunctionLike
|
2011-05-27 18:20:44 +02:00
|
|
|
{
|
2016-07-25 13:33:19 +02:00
|
|
|
/** @var int Flags */
|
|
|
|
public $flags;
|
2015-02-28 18:44:28 +01:00
|
|
|
/** @var bool Whether to return by reference */
|
|
|
|
public $byRef;
|
|
|
|
/** @var string Name */
|
|
|
|
public $name;
|
|
|
|
/** @var Node\Param[] Parameters */
|
|
|
|
public $params;
|
2016-12-05 13:30:29 +01:00
|
|
|
/** @var null|string|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-28 19:06:24 +02:00
|
|
|
|
2017-04-22 14:37:53 +02:00
|
|
|
private static $magicNames = array(
|
|
|
|
'__construct' => true,
|
|
|
|
'__destruct' => true,
|
|
|
|
'__call' => true,
|
|
|
|
'__callstatic' => true,
|
|
|
|
'__get' => true,
|
|
|
|
'__set' => true,
|
|
|
|
'__isset' => true,
|
|
|
|
'__unset' => true,
|
|
|
|
'__sleep' => true,
|
|
|
|
'__wakeup' => true,
|
|
|
|
'__tostring' => true,
|
|
|
|
'__set_state' => true,
|
|
|
|
'__clone' => true,
|
|
|
|
'__invoke' => true,
|
|
|
|
'__debuginfo' => true,
|
|
|
|
);
|
|
|
|
|
2011-10-28 19:06:24 +02:00
|
|
|
/**
|
|
|
|
* Constructs a class method node.
|
|
|
|
*
|
|
|
|
* @param string $name Name
|
|
|
|
* @param array $subNodes Array of the following optional subnodes:
|
2016-07-25 13:33:19 +02:00
|
|
|
* 'flags => MODIFIER_PUBLIC: Flags
|
2015-03-12 13:17:31 +01:00
|
|
|
* 'byRef' => false : Whether to return by reference
|
|
|
|
* 'params' => array() : Parameters
|
|
|
|
* 'returnType' => null : Return type
|
|
|
|
* 'stmts' => array() : Statements
|
2012-04-29 23:32:09 +02:00
|
|
|
* @param array $attributes Additional attributes
|
2011-10-28 19:06:24 +02:00
|
|
|
*/
|
2012-04-29 23:32:09 +02:00
|
|
|
public function __construct($name, array $subNodes = array(), array $attributes = array()) {
|
2015-05-02 22:17:34 +02:00
|
|
|
parent::__construct($attributes);
|
2017-04-24 22:32:40 +02:00
|
|
|
$this->flags = $subNodes['flags'] ?? $subNodes['type'] ?? 0;
|
|
|
|
$this->byRef = $subNodes['byRef'] ?? false;
|
2015-02-28 18:44:28 +01:00
|
|
|
$this->name = $name;
|
2017-04-24 22:32:40 +02:00
|
|
|
$this->params = $subNodes['params'] ?? array();
|
|
|
|
$this->returnType = $subNodes['returnType'] ?? null;
|
2015-02-28 18:44:28 +01:00
|
|
|
$this->stmts = array_key_exists('stmts', $subNodes) ? $subNodes['stmts'] : array();
|
2011-08-04 12:03:34 +02:00
|
|
|
}
|
2012-07-07 16:08:37 +02:00
|
|
|
|
2015-02-28 18:44:28 +01:00
|
|
|
public function getSubNodeNames() {
|
2016-07-25 13:33:19 +02:00
|
|
|
return array('flags', 'byRef', 'name', 'params', 'returnType', 'stmts');
|
2015-02-28 18:44:28 +01:00
|
|
|
}
|
|
|
|
|
2015-06-01 18:32:25 +02:00
|
|
|
public function returnsByRef() {
|
|
|
|
return $this->byRef;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getParams() {
|
|
|
|
return $this->params;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getReturnType() {
|
|
|
|
return $this->returnType;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getStmts() {
|
|
|
|
return $this->stmts;
|
|
|
|
}
|
|
|
|
|
2017-01-24 08:38:55 +01:00
|
|
|
/**
|
2017-01-26 00:16:54 +01:00
|
|
|
* Whether the method is explicitly or implicitly public.
|
|
|
|
*
|
2017-01-24 08:38:55 +01:00
|
|
|
* @return bool
|
|
|
|
*/
|
2012-07-07 16:08:37 +02:00
|
|
|
public function isPublic() {
|
2016-07-25 13:33:19 +02:00
|
|
|
return ($this->flags & Class_::MODIFIER_PUBLIC) !== 0
|
2017-04-19 11:20:05 +02:00
|
|
|
|| ($this->flags & Class_::VISIBILITY_MODIFIER_MASK) === 0;
|
2012-07-07 16:08:37 +02:00
|
|
|
}
|
|
|
|
|
2017-01-24 08:38:55 +01:00
|
|
|
/**
|
2017-01-26 00:16:54 +01:00
|
|
|
* Whether the method is protected.
|
|
|
|
*
|
2017-01-24 08:38:55 +01:00
|
|
|
* @return bool
|
|
|
|
*/
|
2012-07-07 16:08:37 +02:00
|
|
|
public function isProtected() {
|
2016-07-25 13:33:19 +02:00
|
|
|
return (bool) ($this->flags & Class_::MODIFIER_PROTECTED);
|
2012-07-07 16:08:37 +02:00
|
|
|
}
|
|
|
|
|
2017-01-24 08:38:55 +01:00
|
|
|
/**
|
2017-01-26 00:16:54 +01:00
|
|
|
* Whether the method is private.
|
|
|
|
*
|
2017-01-24 08:38:55 +01:00
|
|
|
* @return bool
|
|
|
|
*/
|
2012-07-07 16:08:37 +02:00
|
|
|
public function isPrivate() {
|
2016-07-25 13:33:19 +02:00
|
|
|
return (bool) ($this->flags & Class_::MODIFIER_PRIVATE);
|
2012-07-07 16:08:37 +02:00
|
|
|
}
|
|
|
|
|
2017-01-24 08:38:55 +01:00
|
|
|
/**
|
2017-01-26 00:16:54 +01:00
|
|
|
* Whether the method is abstract.
|
|
|
|
*
|
2017-01-24 08:38:55 +01:00
|
|
|
* @return bool
|
|
|
|
*/
|
2012-07-07 16:08:37 +02:00
|
|
|
public function isAbstract() {
|
2016-07-25 13:33:19 +02:00
|
|
|
return (bool) ($this->flags & Class_::MODIFIER_ABSTRACT);
|
2012-07-07 16:08:37 +02:00
|
|
|
}
|
|
|
|
|
2017-01-24 08:38:55 +01:00
|
|
|
/**
|
2017-01-26 00:16:54 +01:00
|
|
|
* Whether the method is final.
|
|
|
|
* #
|
2017-01-24 08:38:55 +01:00
|
|
|
* @return bool
|
|
|
|
*/
|
2012-07-07 16:08:37 +02:00
|
|
|
public function isFinal() {
|
2016-07-25 13:33:19 +02:00
|
|
|
return (bool) ($this->flags & Class_::MODIFIER_FINAL);
|
2012-07-07 16:08:37 +02:00
|
|
|
}
|
|
|
|
|
2017-01-24 08:38:55 +01:00
|
|
|
/**
|
2017-01-26 00:16:54 +01:00
|
|
|
* Whether the method is static.
|
|
|
|
*
|
2017-01-24 08:38:55 +01:00
|
|
|
* @return bool
|
|
|
|
*/
|
2012-07-07 16:08:37 +02:00
|
|
|
public function isStatic() {
|
2016-07-25 13:33:19 +02:00
|
|
|
return (bool) ($this->flags & Class_::MODIFIER_STATIC);
|
2012-07-07 16:08:37 +02:00
|
|
|
}
|
2017-04-22 14:37:53 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether the method is magic.
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function isMagic() {
|
|
|
|
return isset(self::$magicNames[strtolower($this->name)]);
|
|
|
|
}
|
2014-01-23 13:33:02 +01:00
|
|
|
}
|