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 pathUriPattern.php
More file actions
82 lines (68 loc) · 2.11 KB
/
Copy pathUriPattern.php
File metadata and controls
82 lines (68 loc) · 2.11 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
75
76
77
78
79
80
81
82
<?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\Vec;
// Non-final so you can extend it with additional convenience
// methods.
class UriPattern implements HasFastRouteFragment {
private vec<UriPatternPart> $parts = vec[];
final public function appendPart(UriPatternPart $part): this {
$this->parts[] = $part;
return $this;
}
final public function getFastRouteFragment(): string {
$fragments = Vec\map($this->parts, $part ==> $part->getFastRouteFragment());
return \implode('', $fragments);
}
final public function getParts(): vec<UriPatternPart> {
return $this->parts;
}
final public function getParameters(): vec<UriParameter> {
return Vec\map(
Vec\filter($this->parts, $part ==> $part is UriParameter),
$part ==> {
invariant(
$part is UriParameter,
"Tell the typechecker what's going on",
);
return $part;
},
);
}
///// Convenience Methods /////
final public function literal(string $part): this {
return $this->appendPart(new UriPatternLiteral($part));
}
final public function slash(): this {
return $this->literal('/');
}
final public function string(string $name): this {
return $this->appendPart(new StringRequestParameter(
StringRequestParameterSlashes::WITHOUT_SLASHES,
$name,
));
}
final public function stringWithSlashes(string $name): this {
return $this->appendPart(new StringRequestParameter(
StringRequestParameterSlashes::ALLOW_SLASHES,
$name,
));
}
final public function int(string $name): this {
return $this->appendPart(new IntRequestParameter($name));
}
final public function enum<T>(
/* HH_FIXME[2053] \HH\BuiltinEnum is an implementation detail */
classname<\HH\BuiltinEnum<T>> $enum_class,
string $name,
): this {
return $this->appendPart(new EnumRequestParameter($enum_class, $name));
}
}