Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoladj77 committed Nov 6, 2024
1 parent 681290e commit 8eecae2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
5 changes: 3 additions & 2 deletions modules/admin/classes/menu/pages/setup-wizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace HelloPlus\Modules\Admin\Classes\Menu\Pages;

use HelloPlus\Modules\Admin\Components\Api_Controller;
use HelloPlus\Modules\Admin\Module;

if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
Expand All @@ -29,7 +29,8 @@ public static function has_site_wizard_been_completed(): bool {
/**
* @var \HelloPlus\Modules\Admin\Classes\Rest\Onboarding_Settings $onboarding_rest
*/
$onboarding_rest = Api_Controller::get_endpoint( 'onboarding-settings' );
$onboarding_rest = Module::instance()->get_component( 'Api_Controller' )->get_endpoint( 'onboarding-settings' );

$kits = $onboarding_rest->get_kits();

$kit = array_filter( $kits, function ( $k ) use ( $kit_name ) {
Expand Down
15 changes: 8 additions & 7 deletions modules/admin/components/api-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,21 @@

class Api_Controller {

protected static $endpoints = [];
protected $endpoints = [];

protected static $ajax_classes = [];
protected $ajax_classes = [];

public function __construct() {
self::$endpoints['onboarding-settings'] = new Onboarding_Settings();
$this->endpoints['onboarding-settings'] = new Onboarding_Settings();

self::$ajax_classes['setup-wizard'] = new Setup_Wizard();
$this->ajax_classes['setup-wizard'] = new Setup_Wizard();
}

public static function get_endpoint( string $endpoint ) {
if ( ! isset( self::$endpoints[ $endpoint ] ) ) {
public function get_endpoint( string $endpoint ) {
if ( ! isset( $this->endpoints[ $endpoint ] ) ) {
throw new \Exception( esc_html__( 'Endpoint not found', 'hello-plus' ) );
}
return self::$endpoints[ $endpoint ];

return $this->endpoints[ $endpoint ];
}
}

0 comments on commit 8eecae2

Please sign in to comment.