-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New Abstract class for defining custom endpoint types
- Loading branch information
1 parent
24ee3f8
commit 27f9efb
Showing
1 changed file
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
/** | ||
* Abstract class for defining custom endpoint types in GatherPress. | ||
* | ||
* This file contains the `Endpoint_Type` abstract class, which serves as a base | ||
* class for custom endpoint types (e.g., redirects, templates) in GatherPress. | ||
* Subclasses are expected to define specific behavior for different types of endpoints. | ||
* | ||
* @package GatherPress\Core\Endpoints | ||
* @since 1.0.0 | ||
*/ | ||
|
||
namespace GatherPress\Core\Endpoints; | ||
|
||
// Exit if accessed directly. | ||
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore | ||
|
||
/** | ||
* Abstract class for defining custom endpoint behavior. | ||
* | ||
* The `Endpoint_Type` class is an abstract base class that provides the foundational | ||
* structure for custom endpoint types in GatherPress. It defines the core properties | ||
* of an endpoint, such as the `slug` and the `callback`, and requires subclasses | ||
* to implement their own specific behavior. | ||
* | ||
* This class is designed to be extended by specific endpoint types, such as: | ||
* - `Endpoint_Redirect`: Handles URL redirection for endpoints. | ||
* - `Endpoint_Template`: Handles loading custom templates for endpoints. | ||
* | ||
* @since 1.0.0 | ||
* @package GatherPress\Core | ||
* @subpackage Endpoints | ||
*/ | ||
abstract class Endpoint_Type { | ||
|
||
/** | ||
* The publicly visible name (slug) of the endpoint. | ||
* | ||
* This property stores the slug used in the URL to identify the endpoint. It is | ||
* what differentiates one type of endpoint from another in the URL structure (e.g., | ||
* `event/my-sample-event/googlecalendar` or `event/my-sample-event/ical`). | ||
* | ||
* @since 1.0.0 | ||
* | ||
* @var string | ||
*/ | ||
public $slug; | ||
|
||
/** | ||
* Callback function to handle the endpoint behavior. | ||
* | ||
* This property holds a callable (callback) that is executed when the endpoint is | ||
* matched. The specific behavior of the endpoint (e.g., redirecting or rendering a | ||
* template) is handled by this callback, which is passed when the endpoint is created. | ||
* | ||
* @since 1.0.0 | ||
* | ||
* @var callable | ||
*/ | ||
protected $callback; | ||
|
||
/** | ||
* Class constructor. | ||
* | ||
* Initializes the `Endpoint_Type` object by setting the publicly visible slug for | ||
* the endpoint and the callback function that defines the endpoint's behavior. | ||
* Subclasses will use this constructor to set up specific types of endpoints. | ||
* | ||
* @since 1.0.0 | ||
* | ||
* @param string $slug The slug used to identify the endpoint in the URL. | ||
* @param callable $callback The callback function that handles the endpoint logic. | ||
*/ | ||
public function __construct( | ||
string $slug, | ||
callable $callback | ||
) { | ||
$this->slug = $slug; | ||
$this->callback = $callback; | ||
} | ||
|
||
/** | ||
* Activate Endpoint_Type by hooking into relevant parts. | ||
* | ||
* @since 1.0.0 | ||
* | ||
* @return void | ||
*/ | ||
abstract public function activate(): void; | ||
} |