This repository was archived by the owner on Jun 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathRequestParameterGetters.php
More file actions
74 lines (64 loc) · 1.84 KB
/
RequestParameterGetters.php
File metadata and controls
74 lines (64 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?hh // strict
/*
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
namespace Facebook\HackRouter;
use namespace HH\Lib\C;
trait RequestParameterGetters {
require extends RequestParametersBase;
final public function getString(string $name): string {
return $this->getSimpleTyped(StringRequestParameter::class, $name);
}
final public function getOptionalString(string $name): ?string {
return $this->getSimpleTypedOptional(StringRequestParameter::class, $name);
}
final public function getInt(string $name): int {
return $this->getSimpleTyped(IntRequestParameter::class, $name);
}
final public function getOptionalInt(string $name): ?int {
return $this->getSimpleTypedOptional(IntRequestParameter::class, $name);
}
final public function getEnum<TValue>(
\HH\enumname<TValue> $class,
string $name,
): TValue {
$value = $this->getEnumImpl(
$this->getRequiredSpec(EnumRequestParameter::class, $name),
$class,
$name,
);
return $class::assert($value);
}
final public function getOptionalEnum<TValue>(
\HH\enumname<TValue> $class,
string $name,
): ?TValue {
return $this->getEnumImpl(
$this->getOptionalSpec(EnumRequestParameter::class, $name),
$class,
$name,
);
}
final private function getEnumImpl<TValue>(
EnumRequestParameter<TValue> $spec,
\HH\enumname<TValue> $class,
string $name,
): ?TValue {
invariant(
$spec->getEnumName() === $class,
'Expected %s to be a %s, actually a %s',
$name,
$class,
$spec->getEnumName(),
);
if (!C\contains_key($this->values, $name)) {
return null;
}
return $spec->assert($this->values[$name]);
}
}