2011-04-18 19:02:30 +02:00
|
|
|
<?php
|
|
|
|
|
2014-02-06 14:44:16 +01:00
|
|
|
namespace PhpParser\Node\Stmt;
|
|
|
|
|
|
|
|
use PhpParser\Error;
|
2016-11-23 22:58:18 +01:00
|
|
|
use PhpParser\Node;
|
2014-02-06 14:44:16 +01:00
|
|
|
|
2015-01-31 22:59:38 +01:00
|
|
|
class Class_ extends ClassLike
|
2011-04-18 19:02:30 +02:00
|
|
|
{
|
|
|
|
const MODIFIER_PUBLIC = 1;
|
|
|
|
const MODIFIER_PROTECTED = 2;
|
|
|
|
const MODIFIER_PRIVATE = 4;
|
|
|
|
const MODIFIER_STATIC = 8;
|
|
|
|
const MODIFIER_ABSTRACT = 16;
|
|
|
|
const MODIFIER_FINAL = 32;
|
|
|
|
|
2014-11-13 20:18:49 +01:00
|
|
|
const VISIBILITY_MODIFER_MASK = 7; // 1 | 2 | 4
|
|
|
|
|
2015-02-28 18:44:28 +01:00
|
|
|
/** @var int Type */
|
2016-07-25 13:33:19 +02:00
|
|
|
public $flags;
|
2015-02-28 18:44:28 +01:00
|
|
|
/** @var null|Node\Name Name of extended class */
|
|
|
|
public $extends;
|
|
|
|
/** @var Node\Name[] Names of implemented interfaces */
|
|
|
|
public $implements;
|
|
|
|
|
2016-07-25 13:33:19 +02:00
|
|
|
/** @deprecated Use $flags instead */
|
|
|
|
public $type;
|
|
|
|
|
2011-11-27 12:53:48 +01:00
|
|
|
protected static $specialNames = array(
|
2011-10-28 19:06:24 +02:00
|
|
|
'self' => true,
|
|
|
|
'parent' => true,
|
|
|
|
'static' => true,
|
|
|
|
);
|
2011-08-04 12:03:34 +02:00
|
|
|
|
2011-10-28 19:06:24 +02:00
|
|
|
/**
|
|
|
|
* Constructs a class node.
|
|
|
|
*
|
2015-04-26 23:04:31 +02:00
|
|
|
* @param string|null $name Name
|
2011-10-28 19:06:24 +02:00
|
|
|
* @param array $subNodes Array of the following optional subnodes:
|
2016-07-25 13:33:19 +02:00
|
|
|
* 'flags' => 0 : Flags
|
2011-10-28 19:06:24 +02:00
|
|
|
* 'extends' => null : Name of extended class
|
|
|
|
* 'implements' => array(): Names of implemented interfaces
|
|
|
|
* '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);
|
2016-07-25 13:33:19 +02:00
|
|
|
$this->flags = isset($subNodes['flags']) ? $subNodes['flags']
|
|
|
|
: (isset($subNodes['type']) ? $subNodes['type'] : 0);
|
|
|
|
$this->type = $this->flags;
|
2015-02-28 18:44:28 +01:00
|
|
|
$this->name = $name;
|
|
|
|
$this->extends = isset($subNodes['extends']) ? $subNodes['extends'] : null;
|
|
|
|
$this->implements = isset($subNodes['implements']) ? $subNodes['implements'] : array();
|
|
|
|
$this->stmts = isset($subNodes['stmts']) ? $subNodes['stmts'] : array();
|
2011-08-04 12:03:34 +02:00
|
|
|
}
|
|
|
|
|
2015-02-28 18:44:28 +01:00
|
|
|
public function getSubNodeNames() {
|
2016-07-25 13:33:19 +02:00
|
|
|
return array('flags', 'name', 'extends', 'implements', 'stmts');
|
2015-02-28 18:44:28 +01:00
|
|
|
}
|
|
|
|
|
2012-07-07 16:08:37 +02:00
|
|
|
public function isAbstract() {
|
2016-07-25 13:33:19 +02:00
|
|
|
return (bool) ($this->flags & self::MODIFIER_ABSTRACT);
|
2012-07-07 16:08:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function isFinal() {
|
2016-07-25 13:33:19 +02:00
|
|
|
return (bool) ($this->flags & self::MODIFIER_FINAL);
|
2012-07-07 16:08:37 +02:00
|
|
|
}
|
|
|
|
|
2015-04-26 23:04:31 +02:00
|
|
|
public function isAnonymous() {
|
|
|
|
return null === $this->name;
|
|
|
|
}
|
|
|
|
|
2014-09-30 20:23:25 +02:00
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
*/
|
2011-04-18 19:02:30 +02:00
|
|
|
public static function verifyModifier($a, $b) {
|
2014-11-13 20:18:49 +01:00
|
|
|
if ($a & self::VISIBILITY_MODIFER_MASK && $b & self::VISIBILITY_MODIFER_MASK) {
|
2014-02-06 14:44:16 +01:00
|
|
|
throw new Error('Multiple access type modifiers are not allowed');
|
2011-05-29 12:20:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($a & self::MODIFIER_ABSTRACT && $b & self::MODIFIER_ABSTRACT) {
|
2014-02-06 14:44:16 +01:00
|
|
|
throw new Error('Multiple abstract modifiers are not allowed');
|
2011-05-29 12:20:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($a & self::MODIFIER_STATIC && $b & self::MODIFIER_STATIC) {
|
2014-02-06 14:44:16 +01:00
|
|
|
throw new Error('Multiple static modifiers are not allowed');
|
2011-05-29 12:20:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($a & self::MODIFIER_FINAL && $b & self::MODIFIER_FINAL) {
|
2014-02-06 14:44:16 +01:00
|
|
|
throw new Error('Multiple final modifiers are not allowed');
|
2011-05-29 12:20:47 +02:00
|
|
|
}
|
|
|
|
|
2011-06-03 17:44:23 +02:00
|
|
|
if ($a & 48 && $b & 48) {
|
2014-02-12 20:23:12 +01:00
|
|
|
throw new Error('Cannot use the final modifier on an abstract class member');
|
2011-05-29 12:20:47 +02:00
|
|
|
}
|
2011-04-18 19:02:30 +02:00
|
|
|
}
|
2014-01-23 13:33:02 +01:00
|
|
|
}
|