Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
13.33% |
2 / 15 |
|
33.33% |
1 / 3 |
CRAP | |
0.00% |
0 / 1 |
| Route | |
13.33% |
2 / 15 |
|
33.33% |
1 / 3 |
21.27 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| register_rest_route | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
2 | |||
| verify_permissions | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Automattic\Jetpack_Boost\REST_API; |
| 4 | |
| 5 | class Route { |
| 6 | |
| 7 | /** |
| 8 | * @var \Automattic\Jetpack_Boost\REST_API\Contracts\Endpoint |
| 9 | */ |
| 10 | protected $endpoint; |
| 11 | |
| 12 | protected $permissions; |
| 13 | |
| 14 | public function __construct( $endpoint ) { |
| 15 | $this->endpoint = new $endpoint(); |
| 16 | $this->permissions = $this->endpoint->permissions(); |
| 17 | } |
| 18 | |
| 19 | public function register_rest_route() { |
| 20 | register_rest_route( |
| 21 | JETPACK_BOOST_REST_NAMESPACE, |
| 22 | JETPACK_BOOST_REST_PREFIX . '/' . $this->endpoint->name(), |
| 23 | array( |
| 24 | 'methods' => $this->endpoint->request_methods(), |
| 25 | 'callback' => array( $this->endpoint, 'response' ), |
| 26 | 'permission_callback' => array( $this, 'verify_permissions' ), |
| 27 | ) |
| 28 | ); |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * This method is going to run and try to verify that |
| 33 | * all the permission callbacks are successful. |
| 34 | * |
| 35 | * If any of them fail - return false immediately. |
| 36 | * |
| 37 | * @param \WP_REST_Request $request |
| 38 | * |
| 39 | * @return bool |
| 40 | */ |
| 41 | public function verify_permissions( $request ) { |
| 42 | foreach ( $this->permissions as $permission ) { |
| 43 | if ( true !== $permission->verify( $request ) ) { |
| 44 | return false; |
| 45 | } |
| 46 | } |
| 47 | return true; |
| 48 | } |
| 49 | } |