Mercurial > hg > isophonics-drupal-site
comparison vendor/psy/psysh/src/Reflection/ReflectionLanguageConstruct.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 | |
children | c2387f117808 |
comparison
equal
deleted
inserted
replaced
12:7a779792577d | 13:5fb285c0d0e3 |
---|---|
1 <?php | |
2 | |
3 /* | |
4 * This file is part of Psy Shell. | |
5 * | |
6 * (c) 2012-2018 Justin Hileman | |
7 * | |
8 * For the full copyright and license information, please view the LICENSE | |
9 * file that was distributed with this source code. | |
10 */ | |
11 | |
12 namespace Psy\Reflection; | |
13 | |
14 /** | |
15 * A fake ReflectionFunction but for language constructs. | |
16 */ | |
17 class ReflectionLanguageConstruct extends \ReflectionFunctionAbstract | |
18 { | |
19 public $keyword; | |
20 | |
21 /** | |
22 * Language construct parameter definitions. | |
23 */ | |
24 private static $languageConstructs = [ | |
25 'isset' => [ | |
26 'var' => [], | |
27 '...' => [ | |
28 'isOptional' => true, | |
29 'defaultValue' => null, | |
30 ], | |
31 ], | |
32 | |
33 'unset' => [ | |
34 'var' => [], | |
35 '...' => [ | |
36 'isOptional' => true, | |
37 'defaultValue' => null, | |
38 ], | |
39 ], | |
40 | |
41 'empty' => [ | |
42 'var' => [], | |
43 ], | |
44 | |
45 'echo' => [ | |
46 'arg1' => [], | |
47 '...' => [ | |
48 'isOptional' => true, | |
49 'defaultValue' => null, | |
50 ], | |
51 ], | |
52 | |
53 'print' => [ | |
54 'arg' => [], | |
55 ], | |
56 | |
57 'die' => [ | |
58 'status' => [ | |
59 'isOptional' => true, | |
60 'defaultValue' => 0, | |
61 ], | |
62 ], | |
63 | |
64 'exit' => [ | |
65 'status' => [ | |
66 'isOptional' => true, | |
67 'defaultValue' => 0, | |
68 ], | |
69 ], | |
70 ]; | |
71 | |
72 /** | |
73 * Construct a ReflectionLanguageConstruct object. | |
74 * | |
75 * @param string $keyword | |
76 */ | |
77 public function __construct($keyword) | |
78 { | |
79 if (self::isLanguageConstruct($keyword)) { | |
80 throw new \InvalidArgumentException('Unknown language construct: ' . $keyword); | |
81 } | |
82 | |
83 $this->keyword = $keyword; | |
84 } | |
85 | |
86 /** | |
87 * This can't (and shouldn't) do anything :). | |
88 * | |
89 * @throws \RuntimeException | |
90 */ | |
91 public static function export($name) | |
92 { | |
93 throw new \RuntimeException('Not yet implemented because it\'s unclear what I should do here :)'); | |
94 } | |
95 | |
96 /** | |
97 * Get language construct name. | |
98 * | |
99 * @return string | |
100 */ | |
101 public function getName() | |
102 { | |
103 return $this->keyword; | |
104 } | |
105 | |
106 /** | |
107 * None of these return references. | |
108 * | |
109 * @return bool | |
110 */ | |
111 public function returnsReference() | |
112 { | |
113 return false; | |
114 } | |
115 | |
116 /** | |
117 * Get language construct params. | |
118 * | |
119 * @return array | |
120 */ | |
121 public function getParameters() | |
122 { | |
123 $params = []; | |
124 foreach (self::$languageConstructs[$this->keyword] as $parameter => $opts) { | |
125 array_push($params, new ReflectionLanguageConstructParameter($this->keyword, $parameter, $opts)); | |
126 } | |
127 | |
128 return $params; | |
129 } | |
130 | |
131 /** | |
132 * To string. | |
133 * | |
134 * @return string | |
135 */ | |
136 public function __toString() | |
137 { | |
138 return $this->getName(); | |
139 } | |
140 | |
141 /** | |
142 * Check whether keyword is a (known) language construct. | |
143 * | |
144 * @param string $keyword | |
145 * | |
146 * @return bool | |
147 */ | |
148 public static function isLanguageConstruct($keyword) | |
149 { | |
150 return array_key_exists($keyword, self::$languageConstructs); | |
151 } | |
152 } |