Skip to content

Commit

Permalink
Switch to class instantiation
Browse files Browse the repository at this point in the history
  • Loading branch information
obenland committed Jan 8, 2025
1 parent ff1d645 commit 4a063a4
Show file tree
Hide file tree
Showing 12 changed files with 20 additions and 92 deletions.
24 changes: 12 additions & 12 deletions activitypub.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,21 @@
* Initialize REST routes.
*/
function rest_init() {
Rest\Actors::init();
Rest\Outbox::init();
Rest\Inbox::init();
Rest\Followers::init();
Rest\Following::init();
Rest\Webfinger::init();
Rest\Comment::init();
Rest\Server::init();
Rest\Collection::init();
Rest\Interaction::init();
Rest\Post::init();
( new Rest\Actors() )->register_routes();
( new Rest\Outbox() )->register_routes();
( new Rest\Inbox() )->register_routes();
( new Rest\Followers() )->register_routes();
( new Rest\Following() )->register_routes();
( new Rest\Webfinger() )->register_routes();
( new Rest\Comment() )->register_routes();
( new Rest\Server() )->register_routes();
( new Rest\Collection() )->register_routes();
( new Rest\Interaction() )->register_routes();
( new Rest\Post() )->register_routes();

// Load NodeInfo endpoints only if blog is public.
if ( is_blog_public() ) {
Rest\NodeInfo::init();
( new Rest\NodeInfo() )->register_routes();
}
}
\add_action( 'rest_api_init', __NAMESPACE__ . '\rest_init' );
Expand Down
8 changes: 0 additions & 8 deletions includes/rest/class-actors.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,6 @@ class Actors extends \WP_REST_Controller {
*/
protected $rest_base = '(?:users|actors)/(?P<user_id>[\w\-\.]+)';

/**
* Initialize the class, registering WordPress hooks.
*/
public static function init() {
$controller = new self();
$controller->register_routes();
}

/**
* Register routes.
*/
Expand Down
8 changes: 0 additions & 8 deletions includes/rest/class-collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,6 @@ class Collection extends \WP_REST_Controller {
*/
protected $namespace = ACTIVITYPUB_REST_NAMESPACE;

/**
* Initialize the class, registering WordPress hooks.
*/
public static function init() {
$controller = new self();
$controller->register_routes();
}

/**
* Register routes.
*/
Expand Down
8 changes: 0 additions & 8 deletions includes/rest/class-comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,6 @@ class Comment extends \WP_REST_Controller {
*/
protected $namespace = ACTIVITYPUB_REST_NAMESPACE;

/**
* Initialize the class, registering WordPress hooks.
*/
public static function init() {
$controller = new self();
$controller->register_routes();
}

/**
* Register routes.
*/
Expand Down
8 changes: 0 additions & 8 deletions includes/rest/class-followers.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,6 @@ class Followers extends \WP_REST_Controller {
*/
protected $rest_base = '(?:users|actors)/(?P<user_id>[\w\-\.]+)/followers';

/**
* Initialize the class, registering WordPress hooks.
*/
public static function init() {
$controller = new self();
$controller->register_routes();
}

/**
* Register routes.
*/
Expand Down
5 changes: 1 addition & 4 deletions includes/rest/class-following.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ class Following extends \WP_REST_Controller {
/**
* Initialize the class, registering WordPress hooks.
*/
public static function init() {
$controller = new self();
$controller->register_routes();

public function __construct() {
\add_filter( 'activitypub_rest_following', array( self::class, 'default_following' ), 10, 2 );
}

Expand Down
11 changes: 0 additions & 11 deletions includes/rest/class-inbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,6 @@ class Inbox extends \WP_REST_Controller {
*/
protected $rest_base = '(?:users|actors)/(?P<user_id>[\w\-\.]+)/inbox';

/**
* Initialize the class, registering WordPress hooks.
*/
public static function init() {
$controller = new self();
$controller->register_routes();

$server = new Server();
$server->add_hooks();
}

/**
* Register routes.
*/
Expand Down
11 changes: 5 additions & 6 deletions includes/rest/class-interaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,19 @@ class Interaction extends \WP_REST_Controller {
protected $namespace = ACTIVITYPUB_REST_NAMESPACE;

/**
* Initialize the class, registering WordPress hooks.
* The base of this controller's route.
*
* @var string
*/
public static function init() {
$controller = new self();
$controller->register_routes();
}
protected $rest_base = 'interactions';

/**
* Register routes.
*/
public function register_routes() {
\register_rest_route(
$this->namespace,
'/interactions',
'/' . $this->rest_base,
array(
array(
'methods' => \WP_REST_Server::READABLE,
Expand Down
8 changes: 0 additions & 8 deletions includes/rest/class-nodeinfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,6 @@ class Nodeinfo extends \WP_REST_Controller {
*/
protected $namespace = ACTIVITYPUB_REST_NAMESPACE;

/**
* Initialize the class, registering WordPress hooks.
*/
public static function init() {
$controller = new self();
$controller->register_routes();
}

/**
* Register routes.
*/
Expand Down
8 changes: 0 additions & 8 deletions includes/rest/class-outbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,6 @@ class Outbox extends \WP_REST_Controller {
*/
protected $rest_base = '(?:users|actors)/(?P<user_id>[\w\-\.]+)/outbox';

/**
* Initialize the class, registering WordPress hooks.
*/
public static function init() {
$controller = new self();
$controller->register_routes();
}

/**
* Register routes.
*/
Expand Down
6 changes: 2 additions & 4 deletions includes/rest/class-server.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ class Server extends \WP_REST_Controller {
/**
* Initialize the class, registering WordPress hooks.
*/
public static function init() {
$controller = new self();
$controller->register_routes();
$controller->add_hooks();
public function __construct() {
$this->add_hooks();
}

/**
Expand Down
7 changes: 0 additions & 7 deletions includes/rest/class-webfinger.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@ class Webfinger extends \WP_REST_Controller {
*/
protected $namespace = ACTIVITYPUB_REST_NAMESPACE;

/**
* Initialize the class, registering WordPress hooks.
*/
public static function init() {
( new self() )->register_routes();
}

/**
* Register routes.
*/
Expand Down

0 comments on commit 4a063a4

Please sign in to comment.