-
-
Notifications
You must be signed in to change notification settings - Fork 3
Add singleton-based plugin loading mechanism #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 8 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
06b58b1
Add singleton-based plugin loading mechanism
pfefferle 06c27b5
Deprecate wellknown_nodeinfo_data filter
pfefferle d3e4519
Release 3.1.0
pfefferle 5882e60
Address Copilot review feedback
pfefferle bfd0ed5
Remove manual textdomain loading
pfefferle 3c7475c
Call integrations directly instead of hooking on init
pfefferle 2086fb0
Add tests for Nodeinfo main class
pfefferle 0a57ee3
Fix failing tests
pfefferle aae2d65
Address Copilot review feedback
pfefferle 35e31eb
Add documentation and tests for lifecycle methods
pfefferle deb6c7f
Use rewrite_rules_array filter for better performance
pfefferle b52bf7f
Update includes/class-nodeinfo.php
pfefferle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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,172 @@ | ||
| <?php | ||
| /** | ||
| * Nodeinfo Class | ||
| * | ||
| * @package Nodeinfo | ||
| */ | ||
|
|
||
| namespace Nodeinfo; | ||
|
|
||
| use Nodeinfo\Controller\Nodeinfo as Controller_Nodeinfo; | ||
| use Nodeinfo\Controller\Nodeinfo2 as Controller_Nodeinfo2; | ||
| use Nodeinfo\Integration\Nodeinfo10; | ||
| use Nodeinfo\Integration\Nodeinfo11; | ||
| use Nodeinfo\Integration\Nodeinfo20; | ||
| use Nodeinfo\Integration\Nodeinfo21; | ||
| use Nodeinfo\Integration\Nodeinfo22; | ||
|
|
||
| /** | ||
| * Nodeinfo Class | ||
| * | ||
| * @package Nodeinfo | ||
| */ | ||
| class Nodeinfo { | ||
| /** | ||
| * Instance of the class. | ||
| * | ||
| * @var Nodeinfo | ||
| */ | ||
| private static $instance; | ||
|
|
||
| /** | ||
| * Whether the class has been initialized. | ||
| * | ||
| * @var boolean | ||
| */ | ||
| private $initialized = false; | ||
|
|
||
| /** | ||
| * Get the instance of the class. | ||
| * | ||
| * @return Nodeinfo | ||
| */ | ||
| public static function get_instance() { | ||
| if ( null === self::$instance ) { | ||
| self::$instance = new self(); | ||
| } | ||
|
|
||
| return self::$instance; | ||
| } | ||
|
|
||
| /** | ||
| * Do not allow multiple instances of the class. | ||
| */ | ||
| private function __construct() { | ||
| // Do nothing. | ||
| } | ||
|
|
||
| /** | ||
| * Initialize the plugin. | ||
| */ | ||
| public function init() { | ||
| if ( $this->initialized ) { | ||
| return; | ||
| } | ||
|
|
||
| $this->register_integrations(); | ||
| $this->register_hooks(); | ||
| $this->register_admin_hooks(); | ||
|
|
||
|
pfefferle marked this conversation as resolved.
Outdated
|
||
| $this->initialized = true; | ||
| } | ||
|
|
||
| /** | ||
| * Register NodeInfo version integrations. | ||
| * | ||
| * These only register filters, so they can be called directly. | ||
| */ | ||
| public function register_integrations() { | ||
| Nodeinfo10::init(); | ||
| Nodeinfo11::init(); | ||
| Nodeinfo20::init(); | ||
| Nodeinfo21::init(); | ||
| Nodeinfo22::init(); | ||
| } | ||
|
|
||
| /** | ||
| * Register hooks. | ||
| */ | ||
| public function register_hooks() { | ||
| // Register REST routes. | ||
| \add_action( 'rest_api_init', array( $this, 'register_routes' ) ); | ||
|
|
||
| // Add WebFinger and Host-Meta discovery. | ||
| \add_filter( 'webfinger_user_data', array( Controller_Nodeinfo::class, 'jrd' ), 10, 3 ); | ||
| \add_filter( 'webfinger_post_data', array( Controller_Nodeinfo::class, 'jrd' ), 10, 3 ); | ||
| \add_filter( 'host_meta', array( Controller_Nodeinfo::class, 'jrd' ) ); | ||
|
|
||
| // Add rewrite rules for well-known endpoints. | ||
| \add_action( 'init', array( $this, 'add_rewrite_rules' ), 1 ); | ||
|
|
||
| // Register deprecated filter handlers. | ||
| \add_filter( 'nodeinfo_discovery', array( $this, 'deprecated_wellknown_nodeinfo_data' ), 99 ); | ||
| } | ||
|
|
||
| /** | ||
| * Handles the deprecated wellknown_nodeinfo_data filter. | ||
| * | ||
| * @param array $discovery The discovery document. | ||
| * @return array The filtered discovery document. | ||
| */ | ||
| public function deprecated_wellknown_nodeinfo_data( $discovery ) { | ||
| /** | ||
| * Filters the NodeInfo discovery document. | ||
| * | ||
| * @deprecated 3.0.0 Use nodeinfo_discovery instead. | ||
| * | ||
| * @param array $discovery The discovery document. | ||
| */ | ||
| return \apply_filters_deprecated( | ||
| 'wellknown_nodeinfo_data', | ||
| array( $discovery ), | ||
| '3.0.0', | ||
| 'nodeinfo_discovery' | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Register admin hooks. | ||
| */ | ||
| public function register_admin_hooks() { | ||
| // Initialize Site Health checks. | ||
| \add_action( 'admin_init', array( Health_Check::class, 'init' ) ); | ||
| } | ||
|
|
||
| /** | ||
| * Register REST API routes. | ||
| */ | ||
| public function register_routes() { | ||
| $nodeinfo_controller = new Controller_Nodeinfo(); | ||
| $nodeinfo_controller->register_routes(); | ||
|
|
||
| $nodeinfo2_controller = new Controller_Nodeinfo2(); | ||
| $nodeinfo2_controller->register_routes(); | ||
| } | ||
|
|
||
| /** | ||
| * Add rewrite rules for well-known endpoints. | ||
| */ | ||
| public function add_rewrite_rules() { | ||
| \add_rewrite_rule( '^.well-known/nodeinfo', 'index.php?rest_route=/nodeinfo/discovery', 'top' ); | ||
| \add_rewrite_rule( '^.well-known/x-nodeinfo2', 'index.php?rest_route=/nodeinfo2/1.0', 'top' ); | ||
| } | ||
|
|
||
| /** | ||
| * Flush rewrite rules. | ||
|
pfefferle marked this conversation as resolved.
Outdated
|
||
| * | ||
| * Should be called on plugin activation. | ||
| */ | ||
| public static function activate() { | ||
| self::get_instance()->add_rewrite_rules(); | ||
|
pfefferle marked this conversation as resolved.
Outdated
|
||
| \flush_rewrite_rules(); | ||
| } | ||
|
|
||
| /** | ||
| * Deactivate the plugin. | ||
|
pfefferle marked this conversation as resolved.
Outdated
|
||
| * | ||
| * Should be called on plugin deactivation. | ||
| */ | ||
| public static function deactivate() { | ||
| \flush_rewrite_rules(); | ||
| } | ||
| } | ||
|
pfefferle marked this conversation as resolved.
|
||
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.