comparison vendor/psy/psysh/src/Psy/Reflection/ReflectionLanguageConstructParameter.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children 7a779792577d
comparison
equal deleted inserted replaced
-1:000000000000 0:4c8ae668cc8c
1 <?php
2
3 /*
4 * This file is part of Psy Shell.
5 *
6 * (c) 2012-2017 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 ReflectionParameter but for language construct parameters.
16 *
17 * It stubs out all the important bits and returns whatever was passed in $opts.
18 */
19 class ReflectionLanguageConstructParameter extends \ReflectionParameter
20 {
21 private $function;
22 private $parameter;
23 private $opts;
24
25 public function __construct($function, $parameter, array $opts)
26 {
27 $this->function = $function;
28 $this->parameter = $parameter;
29 $this->opts = $opts;
30 }
31
32 /**
33 * No class here.
34 */
35 public function getClass()
36 {
37 return;
38 }
39
40 /**
41 * Is the param an array?
42 *
43 * @return bool
44 */
45 public function isArray()
46 {
47 return array_key_exists('isArray', $this->opts) && $this->opts['isArray'];
48 }
49
50 /**
51 * Get param default value.
52 *
53 * @return mixed
54 */
55 public function getDefaultValue()
56 {
57 if ($this->isDefaultValueAvailable()) {
58 return $this->opts['defaultValue'];
59 }
60 }
61
62 /**
63 * Get param name.
64 *
65 * @return string
66 */
67 public function getName()
68 {
69 return $this->parameter;
70 }
71
72 /**
73 * Is the param optional?
74 *
75 * @return bool
76 */
77 public function isOptional()
78 {
79 return array_key_exists('isOptional', $this->opts) && $this->opts['isOptional'];
80 }
81
82 /**
83 * Does the param have a default value?
84 *
85 * @return bool
86 */
87 public function isDefaultValueAvailable()
88 {
89 return array_key_exists('defaultValue', $this->opts);
90 }
91
92 /**
93 * Is the param passed by reference?
94 *
95 * (I don't think this is true for anything we need to fake a param for)
96 *
97 * @return bool
98 */
99 public function isPassedByReference()
100 {
101 return array_key_exists('isPassedByReference', $this->opts) && $this->opts['isPassedByReference'];
102 }
103 }