Mercurial > hg > isophonics-drupal-site
comparison vendor/nikic/php-parser/lib/PhpParser/Builder/Class_.php @ 13:5fb285c0d0e3
Update Drupal core to 8.4.7 via Composer. Security update; I *think* we've
been lucky to get away with this so far, as we don't support self-registration
which seems to be used by the so-called "drupalgeddon 2" attack that 8.4.5
was vulnerable to.
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:33:26 +0100 |
parents | 4c8ae668cc8c |
children |
comparison
equal
deleted
inserted
replaced
12:7a779792577d | 13:5fb285c0d0e3 |
---|---|
1 <?php | 1 <?php declare(strict_types=1); |
2 | 2 |
3 namespace PhpParser\Builder; | 3 namespace PhpParser\Builder; |
4 | 4 |
5 use PhpParser; | 5 use PhpParser; |
6 use PhpParser\BuilderHelpers; | |
6 use PhpParser\Node\Name; | 7 use PhpParser\Node\Name; |
7 use PhpParser\Node\Stmt; | 8 use PhpParser\Node\Stmt; |
8 | 9 |
9 class Class_ extends Declaration | 10 class Class_ extends Declaration |
10 { | 11 { |
11 protected $name; | 12 protected $name; |
12 | 13 |
13 protected $extends = null; | 14 protected $extends = null; |
14 protected $implements = array(); | 15 protected $implements = []; |
15 protected $flags = 0; | 16 protected $flags = 0; |
16 | 17 |
17 protected $uses = array(); | 18 protected $uses = []; |
18 protected $constants = array(); | 19 protected $constants = []; |
19 protected $properties = array(); | 20 protected $properties = []; |
20 protected $methods = array(); | 21 protected $methods = []; |
21 | 22 |
22 /** | 23 /** |
23 * Creates a class builder. | 24 * Creates a class builder. |
24 * | 25 * |
25 * @param string $name Name of the class | 26 * @param string $name Name of the class |
26 */ | 27 */ |
27 public function __construct($name) { | 28 public function __construct(string $name) { |
28 $this->name = $name; | 29 $this->name = $name; |
29 } | 30 } |
30 | 31 |
31 /** | 32 /** |
32 * Extends a class. | 33 * Extends a class. |
34 * @param Name|string $class Name of class to extend | 35 * @param Name|string $class Name of class to extend |
35 * | 36 * |
36 * @return $this The builder instance (for fluid interface) | 37 * @return $this The builder instance (for fluid interface) |
37 */ | 38 */ |
38 public function extend($class) { | 39 public function extend($class) { |
39 $this->extends = $this->normalizeName($class); | 40 $this->extends = BuilderHelpers::normalizeName($class); |
40 | 41 |
41 return $this; | 42 return $this; |
42 } | 43 } |
43 | 44 |
44 /** | 45 /** |
46 * | 47 * |
47 * @param Name|string ...$interfaces Names of interfaces to implement | 48 * @param Name|string ...$interfaces Names of interfaces to implement |
48 * | 49 * |
49 * @return $this The builder instance (for fluid interface) | 50 * @return $this The builder instance (for fluid interface) |
50 */ | 51 */ |
51 public function implement() { | 52 public function implement(...$interfaces) { |
52 foreach (func_get_args() as $interface) { | 53 foreach ($interfaces as $interface) { |
53 $this->implements[] = $this->normalizeName($interface); | 54 $this->implements[] = BuilderHelpers::normalizeName($interface); |
54 } | 55 } |
55 | 56 |
56 return $this; | 57 return $this; |
57 } | 58 } |
58 | 59 |
60 * Makes the class abstract. | 61 * Makes the class abstract. |
61 * | 62 * |
62 * @return $this The builder instance (for fluid interface) | 63 * @return $this The builder instance (for fluid interface) |
63 */ | 64 */ |
64 public function makeAbstract() { | 65 public function makeAbstract() { |
65 $this->setModifier(Stmt\Class_::MODIFIER_ABSTRACT); | 66 $this->flags = BuilderHelpers::addModifier($this->flags, Stmt\Class_::MODIFIER_ABSTRACT); |
66 | 67 |
67 return $this; | 68 return $this; |
68 } | 69 } |
69 | 70 |
70 /** | 71 /** |
71 * Makes the class final. | 72 * Makes the class final. |
72 * | 73 * |
73 * @return $this The builder instance (for fluid interface) | 74 * @return $this The builder instance (for fluid interface) |
74 */ | 75 */ |
75 public function makeFinal() { | 76 public function makeFinal() { |
76 $this->setModifier(Stmt\Class_::MODIFIER_FINAL); | 77 $this->flags = BuilderHelpers::addModifier($this->flags, Stmt\Class_::MODIFIER_FINAL); |
77 | 78 |
78 return $this; | 79 return $this; |
79 } | 80 } |
80 | 81 |
81 /** | 82 /** |
84 * @param Stmt|PhpParser\Builder $stmt The statement to add | 85 * @param Stmt|PhpParser\Builder $stmt The statement to add |
85 * | 86 * |
86 * @return $this The builder instance (for fluid interface) | 87 * @return $this The builder instance (for fluid interface) |
87 */ | 88 */ |
88 public function addStmt($stmt) { | 89 public function addStmt($stmt) { |
89 $stmt = $this->normalizeNode($stmt); | 90 $stmt = BuilderHelpers::normalizeNode($stmt); |
90 | 91 |
91 $targets = array( | 92 $targets = [ |
92 'Stmt_TraitUse' => &$this->uses, | 93 Stmt\TraitUse::class => &$this->uses, |
93 'Stmt_ClassConst' => &$this->constants, | 94 Stmt\ClassConst::class => &$this->constants, |
94 'Stmt_Property' => &$this->properties, | 95 Stmt\Property::class => &$this->properties, |
95 'Stmt_ClassMethod' => &$this->methods, | 96 Stmt\ClassMethod::class => &$this->methods, |
96 ); | 97 ]; |
97 | 98 |
98 $type = $stmt->getType(); | 99 $class = \get_class($stmt); |
99 if (!isset($targets[$type])) { | 100 if (!isset($targets[$class])) { |
100 throw new \LogicException(sprintf('Unexpected node of type "%s"', $type)); | 101 throw new \LogicException(sprintf('Unexpected node of type "%s"', $stmt->getType())); |
101 } | 102 } |
102 | 103 |
103 $targets[$type][] = $stmt; | 104 $targets[$class][] = $stmt; |
104 | 105 |
105 return $this; | 106 return $this; |
106 } | 107 } |
107 | 108 |
108 /** | 109 /** |
109 * Returns the built class node. | 110 * Returns the built class node. |
110 * | 111 * |
111 * @return Stmt\Class_ The built class node | 112 * @return Stmt\Class_ The built class node |
112 */ | 113 */ |
113 public function getNode() { | 114 public function getNode() : PhpParser\Node { |
114 return new Stmt\Class_($this->name, array( | 115 return new Stmt\Class_($this->name, [ |
115 'flags' => $this->flags, | 116 'flags' => $this->flags, |
116 'extends' => $this->extends, | 117 'extends' => $this->extends, |
117 'implements' => $this->implements, | 118 'implements' => $this->implements, |
118 'stmts' => array_merge($this->uses, $this->constants, $this->properties, $this->methods), | 119 'stmts' => array_merge($this->uses, $this->constants, $this->properties, $this->methods), |
119 ), $this->attributes); | 120 ], $this->attributes); |
120 } | 121 } |
121 } | 122 } |