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