Pink-Crab /
Perique-Route
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | /** |
||
| 6 | * THe Abstract base for all routes and groups. |
||
| 7 | * |
||
| 8 | * @package PinkCrab\Route\Route |
||
| 9 | * @author Glynn Quelch [email protected] |
||
| 10 | * @since 0.0.1 |
||
| 11 | */ |
||
| 12 | |||
| 13 | namespace PinkCrab\Route\Route; |
||
| 14 | |||
| 15 | use WP_REST_Request; |
||
| 16 | use PinkCrab\WP_Rest_Schema\Argument\Argument; |
||
| 17 | |||
| 18 | abstract class Abstract_Route { |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @var string |
||
| 22 | */ |
||
| 23 | protected string $namespace = ''; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @var Argument[] |
||
| 27 | */ |
||
| 28 | protected array $arguments = array(); |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @var array<int, callable(WP_REST_Request $request):bool> |
||
|
0 ignored issues
–
show
Documentation
Bug
introduced
by
Loading history...
|
|||
| 32 | */ |
||
| 33 | protected array $authentication = array(); |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Get the value of namespace |
||
| 37 | * |
||
| 38 | * @return string |
||
| 39 | */ |
||
| 40 | public function get_namespace(): string { |
||
| 41 | return $this->namespace; |
||
| 42 | } |
||
| 43 | |||
| 44 | /** |
||
| 45 | * Get the value of arguments |
||
| 46 | * |
||
| 47 | * @return Argument[] |
||
| 48 | */ |
||
| 49 | public function get_arguments(): array { |
||
| 50 | return $this->arguments; |
||
| 51 | } |
||
| 52 | |||
| 53 | /** |
||
| 54 | * Adds a single argument to the arguments list. |
||
| 55 | * |
||
| 56 | * @param Argument $argument |
||
| 57 | * @return static |
||
| 58 | */ |
||
| 59 | public function argument( Argument $argument ) { |
||
| 60 | $this->arguments[ $argument->get_key() ] = $argument; |
||
| 61 | return $this; |
||
| 62 | } |
||
| 63 | |||
| 64 | /** |
||
| 65 | * If an argument exists. |
||
| 66 | * |
||
| 67 | * @param string $key |
||
| 68 | * @return bool |
||
| 69 | */ |
||
| 70 | public function has_argument( string $key ): bool { |
||
| 71 | return \array_key_exists( $key, $this->arguments ); |
||
| 72 | } |
||
| 73 | |||
| 74 | /** |
||
| 75 | * Add a single callback authentication stack |
||
| 76 | * |
||
| 77 | * @param callable(\WP_REST_Request): bool $auth_callback |
||
| 78 | * @return static |
||
| 79 | */ |
||
| 80 | public function authentication( callable $auth_callback ) { |
||
| 81 | $this->authentication[] = $auth_callback; |
||
| 82 | return $this; |
||
| 83 | } |
||
| 84 | |||
| 85 | /** |
||
| 86 | * Get the value of authentication |
||
| 87 | * |
||
| 88 | * @return callable[] |
||
| 89 | */ |
||
| 90 | public function get_authentication(): array { |
||
| 91 | return $this->authentication; |
||
| 92 | } |
||
| 93 | } |
||
| 94 |