comparison vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Class_.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children 5fb285c0d0e3
comparison
equal deleted inserted replaced
-1:000000000000 0:4c8ae668cc8c
1 <?php
2
3 namespace PhpParser\Node\Stmt;
4
5 use PhpParser\Error;
6 use PhpParser\Node;
7
8 class Class_ extends ClassLike
9 {
10 const MODIFIER_PUBLIC = 1;
11 const MODIFIER_PROTECTED = 2;
12 const MODIFIER_PRIVATE = 4;
13 const MODIFIER_STATIC = 8;
14 const MODIFIER_ABSTRACT = 16;
15 const MODIFIER_FINAL = 32;
16
17 const VISIBILITY_MODIFIER_MASK = 7; // 1 | 2 | 4
18 /** @deprecated */
19 const VISIBILITY_MODIFER_MASK = self::VISIBILITY_MODIFIER_MASK;
20
21 /** @var int Type */
22 public $flags;
23 /** @var null|Node\Name Name of extended class */
24 public $extends;
25 /** @var Node\Name[] Names of implemented interfaces */
26 public $implements;
27
28 /** @deprecated Use $flags instead */
29 public $type;
30
31 protected static $specialNames = array(
32 'self' => true,
33 'parent' => true,
34 'static' => true,
35 );
36
37 /**
38 * Constructs a class node.
39 *
40 * @param string|null $name Name
41 * @param array $subNodes Array of the following optional subnodes:
42 * 'flags' => 0 : Flags
43 * 'extends' => null : Name of extended class
44 * 'implements' => array(): Names of implemented interfaces
45 * 'stmts' => array(): Statements
46 * @param array $attributes Additional attributes
47 */
48 public function __construct($name, array $subNodes = array(), array $attributes = array()) {
49 parent::__construct($attributes);
50 $this->flags = isset($subNodes['flags']) ? $subNodes['flags']
51 : (isset($subNodes['type']) ? $subNodes['type'] : 0);
52 $this->type = $this->flags;
53 $this->name = $name;
54 $this->extends = isset($subNodes['extends']) ? $subNodes['extends'] : null;
55 $this->implements = isset($subNodes['implements']) ? $subNodes['implements'] : array();
56 $this->stmts = isset($subNodes['stmts']) ? $subNodes['stmts'] : array();
57 }
58
59 public function getSubNodeNames() {
60 return array('flags', 'name', 'extends', 'implements', 'stmts');
61 }
62
63 public function isAbstract() {
64 return (bool) ($this->flags & self::MODIFIER_ABSTRACT);
65 }
66
67 public function isFinal() {
68 return (bool) ($this->flags & self::MODIFIER_FINAL);
69 }
70
71 public function isAnonymous() {
72 return null === $this->name;
73 }
74
75 /**
76 * @internal
77 */
78 public static function verifyModifier($a, $b) {
79 if ($a & self::VISIBILITY_MODIFIER_MASK && $b & self::VISIBILITY_MODIFIER_MASK) {
80 throw new Error('Multiple access type modifiers are not allowed');
81 }
82
83 if ($a & self::MODIFIER_ABSTRACT && $b & self::MODIFIER_ABSTRACT) {
84 throw new Error('Multiple abstract modifiers are not allowed');
85 }
86
87 if ($a & self::MODIFIER_STATIC && $b & self::MODIFIER_STATIC) {
88 throw new Error('Multiple static modifiers are not allowed');
89 }
90
91 if ($a & self::MODIFIER_FINAL && $b & self::MODIFIER_FINAL) {
92 throw new Error('Multiple final modifiers are not allowed');
93 }
94
95 if ($a & 48 && $b & 48) {
96 throw new Error('Cannot use the final modifier on an abstract class member');
97 }
98 }
99 }