Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 1... Línea 1...
1
<?php
1
<?php
Línea 2... Línea 2...
2
 
2
 
Línea 3... Línea 3...
3
namespace Aws\EndpointV2\Ruleset;
3
namespace Aws\EndpointV2\Ruleset;
-
 
4
 
Línea 4... Línea 5...
4
 
5
use Aws\Exception\UnresolvedEndpointException;
5
use Aws\Exception\UnresolvedEndpointException;
6
use function \Aws\is_associative;
6
 
7
 
7
/**
8
/**
Línea 28... Línea 29...
28
    private $documentation;
29
    private $documentation;
Línea 29... Línea 30...
29
 
30
 
30
    /** @var boolean */
31
    /** @var boolean */
Línea -... Línea 32...
-
 
32
    private $deprecated;
-
 
33
 
-
 
34
    /** @var array<string, string> */
-
 
35
    private static $typeMap = [
-
 
36
        'String' => 'is_string',
-
 
37
        'Boolean' => 'is_bool',
-
 
38
        'StringArray' => 'isStringArray'
31
    private $deprecated;
39
    ];
32
 
40
 
33
    public function __construct($name, array $definition)
41
    public function __construct($name, array $definition)
34
    {
42
    {
35
        $type = ucfirst($definition['type']);
43
        $type = ucfirst($definition['type']);
36
        if ($this->isValidType($type)) {
44
        if ($this->isValidType($type)) {
37
            $this->type = $type;
45
            $this->type = $type;
38
        } else {
46
        } else {
39
            throw new UnresolvedEndpointException(
47
            throw new UnresolvedEndpointException(
40
                'Unknown parameter type ' . "`{$type}`" .
48
                'Unknown parameter type ' . "`{$type}`" .
41
                '. Parameters must be of type `String` or `Boolean`.'
49
                '. Parameters must be of type `String`, `Boolean` or `StringArray.'
-
 
50
            );
42
            );
51
        }
43
        }
52
 
44
        $this->name = $name;
53
        $this->name = $name;
45
        $this->builtIn = isset($definition['builtIn']) ? $definition['builtIn'] : null;
54
        $this->builtIn = $definition['builtIn'] ?? null;
46
        $this->default = isset($definition['default']) ? $definition['default'] : null;
-
 
47
        $this->required =  isset($definition['required']) ?
55
        $this->default = $definition['default'] ?? null;
48
            $definition['required'] : false;
-
 
49
        $this->documentation =  isset($definition['documentation']) ?
56
        $this->required = $definition['required'] ?? false;
50
            $definition['documentation'] : null;
-
 
51
        $this->deprecated =  isset($definition['deprecated']) ?
57
        $this->documentation = $definition['documentation'] ?? null;
Línea 52... Línea 58...
52
            $definition['deprecated'] : false;
58
        $this->deprecated = $definition['deprecated'] ?? false;
53
    }
59
    }
54
 
60
 
Línea 114... Línea 120...
114
     * @return void
120
     * @return void
115
     * @throws InvalidArgumentException
121
     * @throws InvalidArgumentException
116
     */
122
     */
117
    public function validateInputParam($inputParam)
123
    public function validateInputParam($inputParam)
118
    {
124
    {
119
        $typeMap = [
-
 
120
            'String' => 'is_string',
-
 
121
            'Boolean' => 'is_bool'
-
 
122
        ];
-
 
123
 
-
 
124
        if ($typeMap[$this->type]($inputParam) === false) {
125
        if (!$this->isValidInput($inputParam)) {
125
            throw new UnresolvedEndpointException(
126
            throw new UnresolvedEndpointException(
126
                "Input parameter `{$this->name}` is the wrong type. Must be a {$this->type}."
127
                "Input parameter `{$this->name}` is the wrong type. Must be a {$this->type}."
127
            );
128
            );
128
        }
129
        }
Línea 129... Línea 130...
129
 
130
 
130
        if ($this->deprecated) {
131
        if ($this->deprecated) {
131
            $deprecated = $this->deprecated;
132
            $deprecated = $this->deprecated;
132
            $deprecationString = "{$this->name} has been deprecated ";
133
            $deprecationString = "{$this->name} has been deprecated ";
133
            $msg = isset($deprecated['message']) ? $deprecated['message'] : null;
134
            $msg = $deprecated['message'] ?? null;
Línea 134... Línea 135...
134
            $since = isset($deprecated['since']) ? $deprecated['since'] : null;
135
            $since = $deprecated['since'] ?? null;
135
 
136
 
-
 
137
            if (!is_null($since)){
-
 
138
                $deprecationString .= 'since ' . $since . '. ';
136
            if (!is_null($since)) $deprecationString = $deprecationString
139
            }
-
 
140
            if (!is_null($msg)) {
Línea 137... Línea 141...
137
                . 'since '. $since . '. ';
141
                $deprecationString .= $msg;
138
            if (!is_null($msg)) $deprecationString = $deprecationString . $msg;
142
            }
139
 
143
 
Línea 140... Línea 144...
140
            trigger_error($deprecationString, E_USER_WARNING);
144
            trigger_error($deprecationString, E_USER_WARNING);
141
        }
145
        }
142
    }
146
    }
-
 
147
 
-
 
148
    private function isValidType($type)
-
 
149
    {
-
 
150
        return isset(self::$typeMap[$type]);
-
 
151
    }
-
 
152
 
-
 
153
    private function isValidInput($inputParam): bool
-
 
154
    {
-
 
155
        $method = self::$typeMap[$this->type];
-
 
156
        if (is_callable($method)) {
-
 
157
            return $method($inputParam);
-
 
158
        } elseif (method_exists($this, $method)) {
-
 
159
            return $this->$method($inputParam);
-
 
160
        }
-
 
161
 
-
 
162
        return false;
-
 
163
    }
-
 
164
 
-
 
165
    private function isStringArray(array $array): bool
-
 
166
    {
-
 
167
        if (is_associative($array)) {
-
 
168
            return false;
-
 
169
        }
-
 
170
 
-
 
171
        foreach($array as $value) {
-
 
172
            if (!is_string($value)) {
-
 
173
                return false;
143
 
174
            }
144
    private function isValidType($type)
175
        }