-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.hh
109 lines (92 loc) · 3.02 KB
/
bootstrap.hh
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?hh
/**
* @copyright 2010-2015, The Titon Project
* @license http://opensource.org/licenses/bsd-license.php
* @link http://titon.io
*/
/**
* --------------------------------------------------------------
* Type Aliases
* --------------------------------------------------------------
*
* Defines type aliases that are used by the route package.
*/
namespace Titon\Route {
use Titon\Route\Group as RouteGroup;
type Action = shape('class' => string, 'action' => string);
type ArgumentList = array<mixed>;
type FilterCallback = (function(Router, Route): void);
type FilterMap = Map<string, FilterCallback>;
type GroupCallback = (function(Router, RouteGroup): void);
type GroupList = Vector<RouteGroup>;
type ParamMap = Map<string, mixed>;
type QueryMap = Map<string, mixed>;
type ResourceMap = Map<string, string>;
type RouteCallback = (function(...): mixed);
type RouteMap = Map<string, Route>;
type SegmentMap = Map<string, mixed>;
type Token = shape('token' => string, 'optional' => bool);
type TokenList = Vector<Token>;
}
namespace Titon\Route\Mixin {
use Titon\Route\Route;
type ConditionCallback = (function(Route): bool);
type ConditionList = Vector<ConditionCallback>;
type FilterList = Vector<string>;
type MethodList = Vector<string>;
type PatternMap = Map<string, string>;
}
/**
* --------------------------------------------------------------
* Annotations
* --------------------------------------------------------------
*
* Registers all annotations declared in the route packages.
*/
namespace {
use Titon\Annotation\Registry;
if (class_exists('Titon\Annotation\Annotation')) {
Registry::map('Route', 'Titon\Route\Annotation\Route');
}
}
/**
* --------------------------------------------------------------
* Helper Functions
* --------------------------------------------------------------
*
* Defines global helper functions for common use cases.
*/
namespace {
use Titon\Route\ParamMap;
use Titon\Route\QueryMap;
use Titon\Route\UrlBuilder;
use Titon\Context\Depository;
/**
* @see Titon\Route\UrlBuilder::getAbsoluteUrl()
*/
function current_url(): string {
return builder_context()->getAbsoluteUrl();
}
/**
* @see Titon\Route\UrlBuilder::build()
*/
function url(string $key, ParamMap $params = Map {}, QueryMap $query = Map {}): string {
return builder_context()->build($key, $params, $query);
}
/**
* @see Titon\Route\UrlBuilder::getSegment()
*/
function url_segment(string $segment): mixed {
return builder_context()->getSegment($segment);
}
/**
* Make and return a `UrlBuilder` instance from the depository.
*
* @return \Titon\Route\UrlBuilder
*/
function builder_context(): UrlBuilder {
$builder = Depository::getInstance()->make('Titon\Route\UrlBuilder');
invariant($builder instanceof UrlBuilder, 'Must be a UrlBuilder.');
return $builder;
}
}