Chris@13
|
1 <?php
|
Chris@13
|
2
|
Chris@13
|
3 /*
|
Chris@13
|
4 * This file is part of Psy Shell.
|
Chris@13
|
5 *
|
Chris@13
|
6 * (c) 2012-2018 Justin Hileman
|
Chris@13
|
7 *
|
Chris@13
|
8 * For the full copyright and license information, please view the LICENSE
|
Chris@13
|
9 * file that was distributed with this source code.
|
Chris@13
|
10 */
|
Chris@13
|
11
|
Chris@13
|
12 namespace Psy\Reflection;
|
Chris@13
|
13
|
Chris@13
|
14 /**
|
Chris@13
|
15 * A fake ReflectionParameter but for language construct parameters.
|
Chris@13
|
16 *
|
Chris@13
|
17 * It stubs out all the important bits and returns whatever was passed in $opts.
|
Chris@13
|
18 */
|
Chris@13
|
19 class ReflectionLanguageConstructParameter extends \ReflectionParameter
|
Chris@13
|
20 {
|
Chris@13
|
21 private $function;
|
Chris@13
|
22 private $parameter;
|
Chris@13
|
23 private $opts;
|
Chris@13
|
24
|
Chris@13
|
25 public function __construct($function, $parameter, array $opts)
|
Chris@13
|
26 {
|
Chris@13
|
27 $this->function = $function;
|
Chris@13
|
28 $this->parameter = $parameter;
|
Chris@13
|
29 $this->opts = $opts;
|
Chris@13
|
30 }
|
Chris@13
|
31
|
Chris@13
|
32 /**
|
Chris@13
|
33 * No class here.
|
Chris@13
|
34 */
|
Chris@13
|
35 public function getClass()
|
Chris@13
|
36 {
|
Chris@13
|
37 return;
|
Chris@13
|
38 }
|
Chris@13
|
39
|
Chris@13
|
40 /**
|
Chris@13
|
41 * Is the param an array?
|
Chris@13
|
42 *
|
Chris@13
|
43 * @return bool
|
Chris@13
|
44 */
|
Chris@13
|
45 public function isArray()
|
Chris@13
|
46 {
|
Chris@17
|
47 return \array_key_exists('isArray', $this->opts) && $this->opts['isArray'];
|
Chris@13
|
48 }
|
Chris@13
|
49
|
Chris@13
|
50 /**
|
Chris@13
|
51 * Get param default value.
|
Chris@13
|
52 *
|
Chris@13
|
53 * @return mixed
|
Chris@13
|
54 */
|
Chris@13
|
55 public function getDefaultValue()
|
Chris@13
|
56 {
|
Chris@13
|
57 if ($this->isDefaultValueAvailable()) {
|
Chris@13
|
58 return $this->opts['defaultValue'];
|
Chris@13
|
59 }
|
Chris@13
|
60 }
|
Chris@13
|
61
|
Chris@13
|
62 /**
|
Chris@13
|
63 * Get param name.
|
Chris@13
|
64 *
|
Chris@13
|
65 * @return string
|
Chris@13
|
66 */
|
Chris@13
|
67 public function getName()
|
Chris@13
|
68 {
|
Chris@13
|
69 return $this->parameter;
|
Chris@13
|
70 }
|
Chris@13
|
71
|
Chris@13
|
72 /**
|
Chris@13
|
73 * Is the param optional?
|
Chris@13
|
74 *
|
Chris@13
|
75 * @return bool
|
Chris@13
|
76 */
|
Chris@13
|
77 public function isOptional()
|
Chris@13
|
78 {
|
Chris@17
|
79 return \array_key_exists('isOptional', $this->opts) && $this->opts['isOptional'];
|
Chris@13
|
80 }
|
Chris@13
|
81
|
Chris@13
|
82 /**
|
Chris@13
|
83 * Does the param have a default value?
|
Chris@13
|
84 *
|
Chris@13
|
85 * @return bool
|
Chris@13
|
86 */
|
Chris@13
|
87 public function isDefaultValueAvailable()
|
Chris@13
|
88 {
|
Chris@17
|
89 return \array_key_exists('defaultValue', $this->opts);
|
Chris@13
|
90 }
|
Chris@13
|
91
|
Chris@13
|
92 /**
|
Chris@13
|
93 * Is the param passed by reference?
|
Chris@13
|
94 *
|
Chris@13
|
95 * (I don't think this is true for anything we need to fake a param for)
|
Chris@13
|
96 *
|
Chris@13
|
97 * @return bool
|
Chris@13
|
98 */
|
Chris@13
|
99 public function isPassedByReference()
|
Chris@13
|
100 {
|
Chris@17
|
101 return \array_key_exists('isPassedByReference', $this->opts) && $this->opts['isPassedByReference'];
|
Chris@13
|
102 }
|
Chris@13
|
103 }
|