4 * This file is part of Psy Shell.
6 * (c) 2012-2018 Justin Hileman
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Psy\Reflection;
15 * A fake ReflectionFunction but for language constructs.
17 class ReflectionLanguageConstruct extends \ReflectionFunctionAbstract
22 * Language construct parameter definitions.
24 private static $languageConstructs = [
29 'defaultValue' => null,
37 'defaultValue' => null,
49 'defaultValue' => null,
73 * Construct a ReflectionLanguageConstruct object.
75 * @param string $keyword
77 public function __construct($keyword)
79 if (self::isLanguageConstruct($keyword)) {
80 throw new \InvalidArgumentException('Unknown language construct: ' . $keyword);
83 $this->keyword = $keyword;
87 * This can't (and shouldn't) do anything :).
89 * @throws \RuntimeException
91 public static function export($name)
93 throw new \RuntimeException('Not yet implemented because it\'s unclear what I should do here :)');
97 * Get language construct name.
101 public function getName()
103 return $this->keyword;
107 * None of these return references.
111 public function returnsReference()
117 * Get language construct params.
121 public function getParameters()
124 foreach (self::$languageConstructs[$this->keyword] as $parameter => $opts) {
125 array_push($params, new ReflectionLanguageConstructParameter($this->keyword, $parameter, $opts));
136 public function __toString()
138 return $this->getName();
142 * Check whether keyword is a (known) language construct.
144 * @param string $keyword
148 public static function isLanguageConstruct($keyword)
150 return array_key_exists($keyword, self::$languageConstructs);