1 | <?php |
||
16 | class Endpoint { |
||
17 | /** |
||
18 | * Endpoint's route. |
||
19 | * |
||
20 | * @var string |
||
21 | */ |
||
22 | protected $route; |
||
23 | |||
24 | /** |
||
25 | * Endpoint's HTTP verb(s). |
||
26 | * |
||
27 | * @var string |
||
28 | */ |
||
29 | protected $method; |
||
30 | |||
31 | /** |
||
32 | * Endpoint's callback. |
||
33 | * |
||
34 | * @var callable |
||
35 | */ |
||
36 | protected $callback; |
||
37 | |||
38 | /** |
||
39 | * Endpoint's permission guard. |
||
40 | * |
||
41 | * @var GuardContract |
||
42 | */ |
||
43 | protected $guard; |
||
44 | |||
45 | /** |
||
46 | * Endpoint's arguments filter. |
||
47 | * |
||
48 | * @var FilterContract |
||
49 | */ |
||
50 | protected $filter; |
||
51 | |||
52 | /** |
||
53 | * Endpoint's route prefix. |
||
54 | * |
||
55 | * @var string |
||
56 | */ |
||
57 | protected $prefix; |
||
58 | |||
59 | /** |
||
60 | * Instantiate a new endpoint with a provided route, method, and callback. |
||
61 | * |
||
62 | * @param string $route |
||
63 | * @param string $method |
||
64 | * @param callable $callback |
||
65 | * |
||
66 | * @throws MalformedRouteException |
||
67 | */ |
||
68 | 45 | public function __construct( $route, $method, $callback ) { |
|
77 | |||
78 | /** |
||
79 | * Generates the endpoint's route. |
||
80 | * |
||
81 | * Combines the prefix with the route to generate the full route string. |
||
82 | * |
||
83 | * @return string |
||
84 | */ |
||
85 | 39 | public function get_route() { |
|
88 | |||
89 | /** |
||
90 | * Generates the endpoint's WP-API options array. |
||
91 | * |
||
92 | * @return array |
||
93 | */ |
||
94 | 39 | public function get_options() { |
|
110 | |||
111 | /** |
||
112 | * Sets the endpoint's permission guard. |
||
113 | * |
||
114 | * @param GuardContract $guard |
||
115 | * |
||
116 | * @return $this |
||
117 | */ |
||
118 | 6 | public function set_guard( GuardContract $guard ) { |
|
123 | |||
124 | /** |
||
125 | * Sets the endpoint's arguments filter. |
||
126 | * |
||
127 | * @param FilterContract $filter |
||
128 | * |
||
129 | * @return $this |
||
130 | */ |
||
131 | 6 | public function set_filter( FilterContract $filter ) { |
|
136 | |||
137 | /** |
||
138 | * Sets the endpoint's prefix. |
||
139 | * |
||
140 | * @param string $prefix |
||
141 | * |
||
142 | * @return $this |
||
143 | * @throws MalformedRouteException |
||
144 | */ |
||
145 | 6 | public function set_prefix( $prefix ) { |
|
154 | } |
||
155 |