Skip to content

Commit 38c6c2a

Browse files
author
hsehszroc
committed
ADDED: exception if namespace doesn't match.
ADDED: onboarding property to get it's instance.
1 parent e3ff235 commit 38c6c2a

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

Config.php

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
use stdClass;
3131
use WP_Error;
32+
use Exception;
3233
use TheWebSolver\Core\Admin\Onboarding\Wizard;
3334
use TheWebSolver\Core\Admin\Onboarding\Form;
3435

@@ -85,11 +86,22 @@ final class Config {
8586
public $form;
8687

8788
/**
88-
* Initializes onboarding wizard.
89+
* Onboarding instance.
90+
*
91+
* @var \TheWebSolver\Core\Admin\Onboarding\Wizard
8992
*
90-
* @return object The external child-class onboarding instance if valid, `Onboarding_Wizard` if not.
93+
* @since 1.1
94+
*/
95+
public $onboarding;
96+
97+
/**
98+
* Initializes onboarding wizard.
9199
*
100+
* @throws Exception If `Config.php` and `Includes/Wizard.php`
101+
* file namespace didn't match.
92102
* @since 1.0
103+
* @since 1.1 Throws Exception and WP dies.
104+
* @since 1.1 Sets onboarding property instead of returning it.
93105
*/
94106
public function onboarding() {
95107
// Prepare and instantiate external child-class, if valid.
@@ -115,13 +127,21 @@ public function onboarding() {
115127
} else {
116128
// New shiny wizard creation from internal child-class.
117129
include_once __DIR__ . '/Includes/Wizard.php';
118-
$onboarding = new Onboarding_Wizard();
119-
$onboarding->set_config( $this );
130+
try {
131+
if ( class_exists( __NAMESPACE__ . '\\Onboarding_Wizard' ) ) {
132+
$onboarding = new Onboarding_Wizard();
133+
$onboarding->set_config( $this );
134+
} else {
135+
throw new Exception( '<p>Namespace of <b>Config</b> and <b>Wizard</b> class does not match.</p><hr>Set same namespace used on <b>Config.php</b> file in <b>Includes/Wizard.php file</b> to instantiate <code><b><em>Onboarding_Wizard</em></b></code> class.' );
136+
}
137+
} catch ( Exception $e ) {
138+
wp_die( wp_kses_post( $e->getMessage() ), 'Namespace Mismatch' );
139+
}
120140
}
121141

122142
$onboarding->init();
123143

124-
return $onboarding;
144+
$this->onboarding = $onboarding;
125145
}
126146

127147
/**

0 commit comments

Comments
 (0)