♻️ Make the REST namespace a const value

We need to access the namespace from an external class; using a const makes this easy. The alternative would be passing a service-instance via DI, just to access the namespace
This commit is contained in:
Philipp Stracker 2025-02-25 17:22:59 +01:00
parent 65204a5003
commit 79e4f9cdd4
No known key found for this signature in database
15 changed files with 26 additions and 28 deletions

View file

@ -87,7 +87,7 @@ class AuthenticationRestEndpoint extends RestEndpoint {
* }
*/
register_rest_route(
$this->namespace,
static::NAMESPACE,
'/' . $this->rest_base . '/direct',
array(
'methods' => WP_REST_Server::EDITABLE,
@ -125,7 +125,7 @@ class AuthenticationRestEndpoint extends RestEndpoint {
* }
*/
register_rest_route(
$this->namespace,
static::NAMESPACE,
'/' . $this->rest_base . '/oauth',
array(
'methods' => WP_REST_Server::EDITABLE,
@ -155,7 +155,7 @@ class AuthenticationRestEndpoint extends RestEndpoint {
* POST /wp-json/wc/v3/wc_paypal/authenticate/disconnect
*/
register_rest_route(
$this->namespace,
static::NAMESPACE,
'/' . $this->rest_base . '/disconnect',
array(
'methods' => WP_REST_Server::EDITABLE,

View file

@ -118,7 +118,7 @@ class CommonRestEndpoint extends RestEndpoint {
* GET /wp-json/wc/v3/wc_paypal/common
*/
register_rest_route(
$this->namespace,
static::NAMESPACE,
'/' . $this->rest_base,
array(
'methods' => WP_REST_Server::READABLE,
@ -134,7 +134,7 @@ class CommonRestEndpoint extends RestEndpoint {
* }
*/
register_rest_route(
$this->namespace,
static::NAMESPACE,
'/' . $this->rest_base,
array(
'methods' => WP_REST_Server::EDITABLE,
@ -147,7 +147,7 @@ class CommonRestEndpoint extends RestEndpoint {
* GET /wp-json/wc/v3/wc_paypal/common/merchant
*/
register_rest_route(
$this->namespace,
static::NAMESPACE,
"/$this->rest_base/merchant",
array(
'methods' => WP_REST_Server::READABLE,

View file

@ -62,7 +62,7 @@ class CompleteOnClickEndpoint extends RestEndpoint {
*/
public function register_routes(): void {
register_rest_route(
$this->namespace,
static::NAMESPACE,
'/' . $this->rest_base,
array(
'methods' => WP_REST_Server::EDITABLE,

View file

@ -64,7 +64,7 @@ class FeaturesRestEndpoint extends RestEndpoint {
public function register_routes(): void {
// GET /features - Get features list.
register_rest_route(
$this->namespace,
static::NAMESPACE,
'/' . $this->rest_base,
array(
array(

View file

@ -60,7 +60,7 @@ class LoginLinkRestEndpoint extends RestEndpoint {
* }
*/
register_rest_route(
$this->namespace,
static::NAMESPACE,
'/' . $this->rest_base,
array(
'methods' => WP_REST_Server::EDITABLE,

View file

@ -101,7 +101,7 @@ class OnboardingRestEndpoint extends RestEndpoint {
* GET /wp-json/wc/v3/wc_paypal/onboarding
*/
register_rest_route(
$this->namespace,
static::NAMESPACE,
'/' . $this->rest_base,
array(
'methods' => WP_REST_Server::READABLE,
@ -117,7 +117,7 @@ class OnboardingRestEndpoint extends RestEndpoint {
* }
*/
register_rest_route(
$this->namespace,
static::NAMESPACE,
'/' . $this->rest_base,
array(
'methods' => WP_REST_Server::EDITABLE,

View file

@ -63,7 +63,7 @@ class PayLaterMessagingEndpoint extends RestEndpoint {
* GET wc/v3/wc_paypal/pay_later_messaging
*/
register_rest_route(
$this->namespace,
static::NAMESPACE,
'/' . $this->rest_base,
array(
'methods' => WP_REST_Server::READABLE,
@ -76,7 +76,7 @@ class PayLaterMessagingEndpoint extends RestEndpoint {
* POST wc/v3/wc_paypal/pay_later_messaging
*/
register_rest_route(
$this->namespace,
static::NAMESPACE,
'/' . $this->rest_base,
array(
'methods' => WP_REST_Server::EDITABLE,

View file

@ -111,7 +111,7 @@ class PaymentRestEndpoint extends RestEndpoint {
* GET wc/v3/wc_paypal/payment
*/
register_rest_route(
$this->namespace,
static::NAMESPACE,
'/' . $this->rest_base,
array(
'methods' => WP_REST_Server::READABLE,
@ -131,7 +131,7 @@ class PaymentRestEndpoint extends RestEndpoint {
* }
*/
register_rest_route(
$this->namespace,
static::NAMESPACE,
'/' . $this->rest_base,
array(
'methods' => WP_REST_Server::EDITABLE,

View file

@ -87,7 +87,7 @@ class RefreshFeatureStatusEndpoint extends RestEndpoint {
* POST /wp-json/wc/v3/wc_paypal/refresh-features
*/
register_rest_route(
$this->namespace,
static::NAMESPACE,
'/' . $this->rest_base,
array(
'methods' => WP_REST_Server::EDITABLE,

View file

@ -54,7 +54,7 @@ class ResetDismissedTodosEndpoint extends RestEndpoint {
* POST wc/v3/wc_paypal/reset-dismissed-todos
*/
register_rest_route(
$this->namespace,
static::NAMESPACE,
'/' . $this->rest_base,
array(
'methods' => WP_REST_Server::EDITABLE,

View file

@ -18,10 +18,8 @@ use WP_REST_Response;
abstract class RestEndpoint extends WC_REST_Controller {
/**
* Endpoint namespace.
*
* @var string
*/
protected $namespace = 'wc/v3/wc_paypal';
protected const NAMESPACE = 'wc/v3/wc_paypal';
/**
* Verify access.

View file

@ -109,7 +109,7 @@ class SettingsRestEndpoint extends RestEndpoint {
* POST wc/v3/wc_paypal/settings
*/
register_rest_route(
$this->namespace,
static::NAMESPACE,
'/' . $this->rest_base,
array(
array(

View file

@ -107,7 +107,7 @@ class StylingRestEndpoint extends RestEndpoint {
* GET wc/v3/wc_paypal/styling
*/
register_rest_route(
$this->namespace,
static::NAMESPACE,
'/' . $this->rest_base,
array(
'methods' => WP_REST_Server::READABLE,
@ -123,7 +123,7 @@ class StylingRestEndpoint extends RestEndpoint {
* }
*/
register_rest_route(
$this->namespace,
static::NAMESPACE,
'/' . $this->rest_base,
array(
'methods' => WP_REST_Server::EDITABLE,

View file

@ -88,7 +88,7 @@ class TodosRestEndpoint extends RestEndpoint {
public function register_routes(): void {
// GET/POST /todos - Get todos list and update dismissed todos.
register_rest_route(
$this->namespace,
static::NAMESPACE,
'/' . $this->rest_base,
array(
array(
@ -106,7 +106,7 @@ class TodosRestEndpoint extends RestEndpoint {
// POST /todos/reset - Reset dismissed todos.
register_rest_route(
$this->namespace,
static::NAMESPACE,
'/' . $this->rest_base . '/reset',
array(
'methods' => WP_REST_Server::EDITABLE,
@ -117,7 +117,7 @@ class TodosRestEndpoint extends RestEndpoint {
// POST /todos/complete - Mark todo as completed on click.
register_rest_route(
$this->namespace,
static::NAMESPACE,
'/' . $this->rest_base . '/complete',
array(
'methods' => WP_REST_Server::EDITABLE,

View file

@ -79,7 +79,7 @@ class WebhookSettingsEndpoint extends RestEndpoint {
* POST /wp-json/wc/v3/wc_paypal/webhooks
*/
register_rest_route(
$this->namespace,
static::NAMESPACE,
'/' . $this->rest_base,
array(
array(
@ -100,7 +100,7 @@ class WebhookSettingsEndpoint extends RestEndpoint {
* POST /wp-json/wc/v3/wc_paypal/webhooks/simulate
*/
register_rest_route(
$this->namespace,
static::NAMESPACE,
'/' . $this->rest_base . '/simulate',
array(
array(