File tree Expand file tree Collapse file tree 1 file changed +77
-0
lines changed
Expand file tree Collapse file tree 1 file changed +77
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ class RouteInformation
6+ {
7+
8+ public function __construct (
9+ private string $ route ,
10+ private string $ method ,
11+ private $ callback ,
12+ ) {
13+ }
14+
15+ public function get_method (): string
16+ {
17+ return $ this ->method ;
18+ }
19+
20+ public function is_post (): bool
21+ {
22+ return $ this ->method === 'POST ' ;
23+ }
24+
25+ public function is_put (): bool
26+ {
27+ return $ this ->method === 'PUT ' ;
28+ }
29+
30+ public function is_delete (): bool
31+ {
32+ return $ this ->method === 'DELETE ' ;
33+ }
34+
35+ public function is_put (): bool
36+ {
37+ return $ this ->method === 'PUT ' ;
38+ }
39+
40+ public function is_singular (): bool
41+ {
42+ // Always true
43+ if (str_ends_with ($ this ->route , '(?P<id>[\d]+) ' )) {
44+ return true ;
45+ }
46+
47+ // Never true
48+ if ( ! str_contains ($ this ->route , '?P<id> ' )) {
49+ return false ;
50+ }
51+
52+ return false ;
53+ }
54+
55+ public function is_list (): bool
56+ {
57+ return ! $ this ->is_singular ();
58+ }
59+
60+ public function is_wp_rest_controller ()
61+ {
62+ $ allowed = [
63+ WP_REST_Posts_Controller::class,
64+ WP_REST_Users_Controller::class,
65+ WP_REST_Taxonomies_Controller::class,
66+ ];
67+
68+ foreach ($ allowed as $ controller ) {
69+ if ($ this ->callback [0 ] instanceof $ controller ) {
70+ return true ;
71+ }
72+ }
73+
74+ return false ;
75+ }
76+
77+ }
You can’t perform that action at this time.
0 commit comments