2011-05-27 18:20:44 +02:00
|
|
|
<?php
|
|
|
|
|
2014-02-06 14:44:16 +01:00
|
|
|
namespace PhpParser\Node\Stmt;
|
|
|
|
|
|
|
|
use PhpParser\Node;
|
|
|
|
use PhpParser\Error;
|
|
|
|
|
|
|
|
class ClassMethod extends Node\Stmt
|
2011-05-27 18:20:44 +02:00
|
|
|
{
|
2015-02-28 18:44:28 +01:00
|
|
|
/** @var int Type */
|
|
|
|
public $type;
|
|
|
|
/** @var bool Whether to return by reference */
|
|
|
|
public $byRef;
|
|
|
|
/** @var string Name */
|
|
|
|
public $name;
|
|
|
|
/** @var Node\Param[] Parameters */
|
|
|
|
public $params;
|
2015-03-12 13:17:31 +01:00
|
|
|
/** @var null|string|Node\Name[] Return type */
|
|
|
|
public $returnType;
|
2015-02-28 18:44:28 +01:00
|
|
|
/** @var Node[] Statements */
|
|
|
|
public $stmts;
|
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:
|
2015-03-12 13:17:31 +01:00
|
|
|
* 'type' => MODIFIER_PUBLIC: Type
|
|
|
|
* '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-02-28 18:44:28 +01:00
|
|
|
parent::__construct(null, $attributes);
|
|
|
|
$this->type = isset($subNodes['type']) ? $subNodes['type'] : 0;
|
|
|
|
$this->byRef = isset($subNodes['byRef']) ? $subNodes['byRef'] : false;
|
|
|
|
$this->name = $name;
|
|
|
|
$this->params = isset($subNodes['params']) ? $subNodes['params'] : array();
|
2015-03-12 13:17:31 +01:00
|
|
|
$this->returnType = isset($subNodes['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
|
|
|
|
2014-02-12 20:23:12 +01:00
|
|
|
if ($this->type & Class_::MODIFIER_STATIC) {
|
2014-01-23 13:33:02 +01:00
|
|
|
switch (strtolower($this->name)) {
|
|
|
|
case '__construct':
|
2014-02-12 20:23:12 +01:00
|
|
|
throw new Error(sprintf('Constructor %s() cannot be static', $this->name));
|
2014-01-23 13:33:02 +01:00
|
|
|
case '__destruct':
|
2014-02-12 20:23:12 +01:00
|
|
|
throw new Error(sprintf('Destructor %s() cannot be static', $this->name));
|
2014-01-23 13:33:02 +01:00
|
|
|
case '__clone':
|
2014-02-12 20:23:12 +01:00
|
|
|
throw new Error(sprintf('Clone method %s() cannot be static', $this->name));
|
2014-01-23 13:33:02 +01:00
|
|
|
}
|
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() {
|
2015-03-12 13:17:31 +01:00
|
|
|
return array('type', 'byRef', 'name', 'params', 'returnType', 'stmts');
|
2015-02-28 18:44:28 +01:00
|
|
|
}
|
|
|
|
|
2012-07-07 16:08:37 +02:00
|
|
|
public function isPublic() {
|
2015-03-02 11:33:41 +01:00
|
|
|
return ($this->type & Class_::MODIFIER_PUBLIC) !== 0 || $this->type === 0;
|
2012-07-07 16:08:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function isProtected() {
|
2014-02-06 14:44:16 +01:00
|
|
|
return (bool) ($this->type & Class_::MODIFIER_PROTECTED);
|
2012-07-07 16:08:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function isPrivate() {
|
2014-02-06 14:44:16 +01:00
|
|
|
return (bool) ($this->type & Class_::MODIFIER_PRIVATE);
|
2012-07-07 16:08:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function isAbstract() {
|
2014-02-06 14:44:16 +01:00
|
|
|
return (bool) ($this->type & Class_::MODIFIER_ABSTRACT);
|
2012-07-07 16:08:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function isFinal() {
|
2014-02-06 14:44:16 +01:00
|
|
|
return (bool) ($this->type & Class_::MODIFIER_FINAL);
|
2012-07-07 16:08:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function isStatic() {
|
2014-02-06 14:44:16 +01:00
|
|
|
return (bool) ($this->type & Class_::MODIFIER_STATIC);
|
2012-07-07 16:08:37 +02:00
|
|
|
}
|
2014-01-23 13:33:02 +01:00
|
|
|
}
|