Subversion-Projekte lars-tiefland.laravel_shop

Revision

Zur aktuellen Revision | Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
/*
4
 * This file is part of Psy Shell.
5
 *
6
 * (c) 2012-2022 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
     * @todo remove \ReturnTypeWillChange attribute after dropping support for PHP 7.0 (when we can use nullable types)
36
     */
37
    #[\ReturnTypeWillChange]
38
    public function getClass()
39
    {
40
        return;
41
    }
42
 
43
    /**
44
     * Is the param an array?
45
     *
46
     * @return bool
47
     */
48
    public function isArray(): bool
49
    {
50
        return \array_key_exists('isArray', $this->opts) && $this->opts['isArray'];
51
    }
52
 
53
    /**
54
     * Get param default value.
55
     *
56
     * @todo remove \ReturnTypeWillChange attribute after dropping support for PHP 7.x (when we can use mixed type)
57
     *
58
     * @return mixed
59
     */
60
    #[\ReturnTypeWillChange]
61
    public function getDefaultValue()
62
    {
63
        if ($this->isDefaultValueAvailable()) {
64
            return $this->opts['defaultValue'];
65
        }
66
 
67
        return null;
68
    }
69
 
70
    /**
71
     * Get param name.
72
     *
73
     * @return string
74
     */
75
    public function getName(): string
76
    {
77
        return $this->parameter;
78
    }
79
 
80
    /**
81
     * Is the param optional?
82
     *
83
     * @return bool
84
     */
85
    public function isOptional(): bool
86
    {
87
        return \array_key_exists('isOptional', $this->opts) && $this->opts['isOptional'];
88
    }
89
 
90
    /**
91
     * Does the param have a default value?
92
     *
93
     * @return bool
94
     */
95
    public function isDefaultValueAvailable(): bool
96
    {
97
        return \array_key_exists('defaultValue', $this->opts);
98
    }
99
 
100
    /**
101
     * Is the param passed by reference?
102
     *
103
     * (I don't think this is true for anything we need to fake a param for)
104
     *
105
     * @return bool
106
     */
107
    public function isPassedByReference(): bool
108
    {
109
        return \array_key_exists('isPassedByReference', $this->opts) && $this->opts['isPassedByReference'];
110
    }
111
}