Completed
Branch new-addon-api (b7bde0)
by
unknown
18:29 queued 08:41
created
core/services/addon/AddonManager.php 2 patches
Indentation   +93 added lines, -93 removed lines patch added patch discarded remove patch
@@ -23,109 +23,109 @@
 block discarded – undo
23 23
  */
24 24
 class AddonManager
25 25
 {
26
-    /**
27
-     * @var AddonCollection
28
-     */
29
-    private $addons;
26
+	/**
27
+	 * @var AddonCollection
28
+	 */
29
+	private $addons;
30 30
 
31
-    /**
32
-     * @var IncompatibleAddonHandler
33
-     */
34
-    private $incompatible_addon_handler;
31
+	/**
32
+	 * @var IncompatibleAddonHandler
33
+	 */
34
+	private $incompatible_addon_handler;
35 35
 
36
-    /**
37
-     * @var Psr4Autoloader
38
-     */
39
-    private $psr4_loader;
36
+	/**
37
+	 * @var Psr4Autoloader
38
+	 */
39
+	private $psr4_loader;
40 40
 
41
-    /**
42
-     * @var RegisterV1Addon
43
-     */
44
-    private $register_v1_addon;
41
+	/**
42
+	 * @var RegisterV1Addon
43
+	 */
44
+	private $register_v1_addon;
45 45
 
46
-    /**
47
-     * @var ThirdPartyPluginHandler
48
-     */
49
-    private $third_party_plugin_handler;
46
+	/**
47
+	 * @var ThirdPartyPluginHandler
48
+	 */
49
+	private $third_party_plugin_handler;
50 50
 
51 51
 
52
-    /**
53
-     * AddonManager constructor.
54
-     *
55
-     * @param AddonCollection          $addons
56
-     * @param Psr4Autoloader           $psr4_loader
57
-     * @param RegisterV1Addon          $register_v1_addon
58
-     * @param IncompatibleAddonHandler $incompatible_addon_handler
59
-     * @param ThirdPartyPluginHandler  $third_party_plugin_handler
60
-     */
61
-    public function __construct(
62
-        AddonCollection $addons,
63
-        Psr4Autoloader $psr4_loader,
64
-        RegisterV1Addon $register_v1_addon,
65
-        IncompatibleAddonHandler $incompatible_addon_handler,
66
-        ThirdPartyPluginHandler $third_party_plugin_handler
67
-    ) {
68
-        $this->addons                     = $addons;
69
-        $this->psr4_loader                = $psr4_loader;
70
-        $this->register_v1_addon          = $register_v1_addon;
71
-        $this->incompatible_addon_handler = $incompatible_addon_handler;
72
-        $this->third_party_plugin_handler = $third_party_plugin_handler;
73
-    }
52
+	/**
53
+	 * AddonManager constructor.
54
+	 *
55
+	 * @param AddonCollection          $addons
56
+	 * @param Psr4Autoloader           $psr4_loader
57
+	 * @param RegisterV1Addon          $register_v1_addon
58
+	 * @param IncompatibleAddonHandler $incompatible_addon_handler
59
+	 * @param ThirdPartyPluginHandler  $third_party_plugin_handler
60
+	 */
61
+	public function __construct(
62
+		AddonCollection $addons,
63
+		Psr4Autoloader $psr4_loader,
64
+		RegisterV1Addon $register_v1_addon,
65
+		IncompatibleAddonHandler $incompatible_addon_handler,
66
+		ThirdPartyPluginHandler $third_party_plugin_handler
67
+	) {
68
+		$this->addons                     = $addons;
69
+		$this->psr4_loader                = $psr4_loader;
70
+		$this->register_v1_addon          = $register_v1_addon;
71
+		$this->incompatible_addon_handler = $incompatible_addon_handler;
72
+		$this->third_party_plugin_handler = $third_party_plugin_handler;
73
+	}
74 74
 
75 75
 
76
-    /**
77
-     * @throws Exception
78
-     */
79
-    public function initialize()
80
-    {
81
-        // set autoloaders for all of the classes implementing the legacy EEI_Plugin_API
82
-        // which provide helpers for EE plugin authors to more easily register certain components with EE.
83
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
84
-    }
76
+	/**
77
+	 * @throws Exception
78
+	 */
79
+	public function initialize()
80
+	{
81
+		// set autoloaders for all of the classes implementing the legacy EEI_Plugin_API
82
+		// which provide helpers for EE plugin authors to more easily register certain components with EE.
83
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
84
+	}
85 85
 
86 86
 
87
-    /**
88
-     * @throws Exception
89
-     */
90
-    public function loadAddons()
91
-    {
92
-        try {
93
-            $this->incompatible_addon_handler->deactivateIncompatibleAddons();
94
-            // legacy add-on API
95
-            do_action('AHEE__EE_System__load_espresso_addons');
96
-            // new add-on API that uses versioning
97
-            do_action(
98
-                'AHEE__EventEspresso_core_services_addon_AddonManager__initialize__addons',
99
-                $this->addons,
100
-                espresso_version()
101
-            );
102
-            // addons are responsible for loading their AddonApiVersion into the AddonCollection
103
-            foreach ($this->addons as $addon) {
104
-                if ($addon instanceof AddonApiVersion) {
105
-                    $this->registerAddon($addon);
106
-                }
107
-            }
108
-            $this->third_party_plugin_handler->loadPlugins();
109
-            do_action('AHEE__EE_System__load_espresso_addons__complete');
110
-        } catch (Exception $exception) {
111
-            new ExceptionStackTraceDisplay($exception);
112
-        }
113
-    }
87
+	/**
88
+	 * @throws Exception
89
+	 */
90
+	public function loadAddons()
91
+	{
92
+		try {
93
+			$this->incompatible_addon_handler->deactivateIncompatibleAddons();
94
+			// legacy add-on API
95
+			do_action('AHEE__EE_System__load_espresso_addons');
96
+			// new add-on API that uses versioning
97
+			do_action(
98
+				'AHEE__EventEspresso_core_services_addon_AddonManager__initialize__addons',
99
+				$this->addons,
100
+				espresso_version()
101
+			);
102
+			// addons are responsible for loading their AddonApiVersion into the AddonCollection
103
+			foreach ($this->addons as $addon) {
104
+				if ($addon instanceof AddonApiVersion) {
105
+					$this->registerAddon($addon);
106
+				}
107
+			}
108
+			$this->third_party_plugin_handler->loadPlugins();
109
+			do_action('AHEE__EE_System__load_espresso_addons__complete');
110
+		} catch (Exception $exception) {
111
+			new ExceptionStackTraceDisplay($exception);
112
+		}
113
+	}
114 114
 
115 115
 
116
-    /**
117
-     * @param AddonApiVersion $addon
118
-     * @throws EE_Error
119
-     */
120
-    private function registerAddon(AddonApiVersion $addon)
121
-    {
122
-        // first register addon namespace so that FQCNs resolve correctly
123
-        $this->psr4_loader->addNamespace($addon->getNamespace(), dirname($addon->mainFile()) . '/src/');
124
-        // then allow add-on to perform any other setup that relied on PSR4 autoloading
125
-        $addon->initialize();
126
-        // now register each addon based on it's API version
127
-        if ($addon instanceof AddonApiV1) {
128
-            $this->register_v1_addon->register($addon);
129
-        }
130
-    }
116
+	/**
117
+	 * @param AddonApiVersion $addon
118
+	 * @throws EE_Error
119
+	 */
120
+	private function registerAddon(AddonApiVersion $addon)
121
+	{
122
+		// first register addon namespace so that FQCNs resolve correctly
123
+		$this->psr4_loader->addNamespace($addon->getNamespace(), dirname($addon->mainFile()) . '/src/');
124
+		// then allow add-on to perform any other setup that relied on PSR4 autoloading
125
+		$addon->initialize();
126
+		// now register each addon based on it's API version
127
+		if ($addon instanceof AddonApiV1) {
128
+			$this->register_v1_addon->register($addon);
129
+		}
130
+	}
131 131
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
     {
81 81
         // set autoloaders for all of the classes implementing the legacy EEI_Plugin_API
82 82
         // which provide helpers for EE plugin authors to more easily register certain components with EE.
83
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
83
+        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'plugin_api');
84 84
     }
85 85
 
86 86
 
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
     private function registerAddon(AddonApiVersion $addon)
121 121
     {
122 122
         // first register addon namespace so that FQCNs resolve correctly
123
-        $this->psr4_loader->addNamespace($addon->getNamespace(), dirname($addon->mainFile()) . '/src/');
123
+        $this->psr4_loader->addNamespace($addon->getNamespace(), dirname($addon->mainFile()).'/src/');
124 124
         // then allow add-on to perform any other setup that relied on PSR4 autoloading
125 125
         $addon->initialize();
126 126
         // now register each addon based on it's API version
Please login to merge, or discard this patch.
core/services/addon/api/IncompatibleAddonHandler.php 2 patches
Indentation   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -6,68 +6,68 @@
 block discarded – undo
6 6
 
7 7
 class IncompatibleAddonHandler
8 8
 {
9
-    /**
10
-     * @return void
11
-     */
12
-    public function deactivateIncompatibleAddons()
13
-    {
14
-        $this->deactivateIncompatibleAddon(
15
-            'Wait Lists',
16
-            'EE_WAIT_LISTS_VERSION',
17
-            '1.0.0.beta.074',
18
-            'load_espresso_wait_lists',
19
-            'EE_WAIT_LISTS_PLUGIN_FILE'
20
-        );
21
-        $this->deactivateIncompatibleAddon(
22
-            'Automated Upcoming Event Notifications',
23
-            'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_VERSION',
24
-            '1.0.0.beta.091',
25
-            'load_espresso_automated_upcoming_event_notification',
26
-            'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_PLUGIN_FILE'
27
-        );
28
-    }
9
+	/**
10
+	 * @return void
11
+	 */
12
+	public function deactivateIncompatibleAddons()
13
+	{
14
+		$this->deactivateIncompatibleAddon(
15
+			'Wait Lists',
16
+			'EE_WAIT_LISTS_VERSION',
17
+			'1.0.0.beta.074',
18
+			'load_espresso_wait_lists',
19
+			'EE_WAIT_LISTS_PLUGIN_FILE'
20
+		);
21
+		$this->deactivateIncompatibleAddon(
22
+			'Automated Upcoming Event Notifications',
23
+			'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_VERSION',
24
+			'1.0.0.beta.091',
25
+			'load_espresso_automated_upcoming_event_notification',
26
+			'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_PLUGIN_FILE'
27
+		);
28
+	}
29 29
 
30 30
 
31
-    /**
32
-     * @param string $addon_name
33
-     * @param string $version_constant
34
-     * @param string $min_version_required
35
-     * @param string $load_callback
36
-     * @param string $plugin_file_constant
37
-     * @return void
38
-     */
39
-    private function deactivateIncompatibleAddon(
40
-        string $addon_name,
41
-        string $version_constant,
42
-        string $min_version_required,
43
-        string $load_callback,
44
-        string $plugin_file_constant
45
-    ) {
46
-        if (! defined($version_constant)) {
47
-            return;
48
-        }
49
-        $addon_version = constant($version_constant);
50
-        if ($addon_version && version_compare($addon_version, $min_version_required, '<')) {
51
-            remove_action('AHEE__EE_System__load_espresso_addons', $load_callback);
52
-            if (! function_exists('deactivate_plugins')) {
53
-                require_once ABSPATH . 'wp-admin/includes/plugin.php';
54
-            }
55
-            deactivate_plugins(plugin_basename(constant($plugin_file_constant)));
56
-            unset($_GET['activate'], $_REQUEST['activate'], $_GET['activate-multi'], $_REQUEST['activate-multi']);
57
-            EE_Error::add_error(
58
-                sprintf(
59
-                    esc_html__(
60
-                        'We\'re sorry, but the Event Espresso %1$s addon was deactivated because version %2$s or higher is required with this version of Event Espresso core.',
61
-                        'event_espresso'
62
-                    ),
63
-                    $addon_name,
64
-                    $min_version_required
65
-                ),
66
-                __FILE__,
67
-                __FUNCTION__ . "({$addon_name})",
68
-                __LINE__
69
-            );
70
-            EE_Error::get_notices(false, true);
71
-        }
72
-    }
31
+	/**
32
+	 * @param string $addon_name
33
+	 * @param string $version_constant
34
+	 * @param string $min_version_required
35
+	 * @param string $load_callback
36
+	 * @param string $plugin_file_constant
37
+	 * @return void
38
+	 */
39
+	private function deactivateIncompatibleAddon(
40
+		string $addon_name,
41
+		string $version_constant,
42
+		string $min_version_required,
43
+		string $load_callback,
44
+		string $plugin_file_constant
45
+	) {
46
+		if (! defined($version_constant)) {
47
+			return;
48
+		}
49
+		$addon_version = constant($version_constant);
50
+		if ($addon_version && version_compare($addon_version, $min_version_required, '<')) {
51
+			remove_action('AHEE__EE_System__load_espresso_addons', $load_callback);
52
+			if (! function_exists('deactivate_plugins')) {
53
+				require_once ABSPATH . 'wp-admin/includes/plugin.php';
54
+			}
55
+			deactivate_plugins(plugin_basename(constant($plugin_file_constant)));
56
+			unset($_GET['activate'], $_REQUEST['activate'], $_GET['activate-multi'], $_REQUEST['activate-multi']);
57
+			EE_Error::add_error(
58
+				sprintf(
59
+					esc_html__(
60
+						'We\'re sorry, but the Event Espresso %1$s addon was deactivated because version %2$s or higher is required with this version of Event Espresso core.',
61
+						'event_espresso'
62
+					),
63
+					$addon_name,
64
+					$min_version_required
65
+				),
66
+				__FILE__,
67
+				__FUNCTION__ . "({$addon_name})",
68
+				__LINE__
69
+			);
70
+			EE_Error::get_notices(false, true);
71
+		}
72
+	}
73 73
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -43,14 +43,14 @@  discard block
 block discarded – undo
43 43
         string $load_callback,
44 44
         string $plugin_file_constant
45 45
     ) {
46
-        if (! defined($version_constant)) {
46
+        if ( ! defined($version_constant)) {
47 47
             return;
48 48
         }
49 49
         $addon_version = constant($version_constant);
50 50
         if ($addon_version && version_compare($addon_version, $min_version_required, '<')) {
51 51
             remove_action('AHEE__EE_System__load_espresso_addons', $load_callback);
52
-            if (! function_exists('deactivate_plugins')) {
53
-                require_once ABSPATH . 'wp-admin/includes/plugin.php';
52
+            if ( ! function_exists('deactivate_plugins')) {
53
+                require_once ABSPATH.'wp-admin/includes/plugin.php';
54 54
             }
55 55
             deactivate_plugins(plugin_basename(constant($plugin_file_constant)));
56 56
             unset($_GET['activate'], $_REQUEST['activate'], $_GET['activate-multi'], $_REQUEST['activate-multi']);
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
                     $min_version_required
65 65
                 ),
66 66
                 __FILE__,
67
-                __FUNCTION__ . "({$addon_name})",
67
+                __FUNCTION__."({$addon_name})",
68 68
                 __LINE__
69 69
             );
70 70
             EE_Error::get_notices(false, true);
Please login to merge, or discard this patch.
core/services/addon/api/AddonApiVersion.php 2 patches
Indentation   +282 added lines, -282 removed lines patch added patch discarded remove patch
@@ -19,286 +19,286 @@
 block discarded – undo
19 19
  */
20 20
 abstract class AddonApiVersion
21 21
 {
22
-    const V1 = 1;
23
-
24
-    /**
25
-     * @var int one of the API_VERSION_* constants from above
26
-     */
27
-    private $api_version;
28
-
29
-    /**
30
-     * @var DomainInterface
31
-     */
32
-    private $domain;
33
-
34
-    /**
35
-     * @var Version minimum version of EE core that the add-on will work with
36
-     */
37
-    private $min_core_version;
38
-
39
-    /**
40
-     * @var Version minimum version of WP core that the add-on will work with
41
-     */
42
-    private $min_wp_version;
43
-
44
-    /**
45
-     * @var string  PascalCase identifier for the add-on.
46
-     *              IMPORTANT! there must be a class of the same name in the root of the add-ons /src/domain/ folder
47
-     */
48
-    private $name;
49
-
50
-    /**
51
-     * @var string
52
-     */
53
-    private $addon_namespace;
54
-
55
-    /**
56
-     * @var FilePath
57
-     */
58
-    private $main_file;
59
-
60
-    /**
61
-     * @var string
62
-     */
63
-    private $slug;
64
-
65
-    /**
66
-     * @var Version the current add-on version
67
-     */
68
-    private $version;
69
-
70
-
71
-    /**
72
-     * Bootstrap constructor.
73
-     *
74
-     * @param string $slug
75
-     * @param string $name
76
-     * @param string $namespace
77
-     * @param string $version
78
-     * @param string $min_core_version
79
-     * @param string $main_file
80
-     * @param int    $api_version
81
-     */
82
-    protected function __construct(
83
-        string $slug,
84
-        string $name,
85
-        string $namespace,
86
-        string $version,
87
-        string $min_core_version,
88
-        string $main_file,
89
-        int $api_version
90
-    ) {
91
-        $this->setSlug($slug);
92
-        $this->setName($name);
93
-        $this->setNamespace($namespace);
94
-        $this->setMinCoreVersion($min_core_version);
95
-        $this->setMainFile($main_file);
96
-        $this->setVersion($version);
97
-        $this->setApiVersion($api_version);
98
-    }
99
-
100
-
101
-    /**
102
-     * @return void
103
-     */
104
-    public function initialize(): void
105
-    {
106
-        $this->domain = DomainFactory::create(
107
-            "{$this->addon_namespace}\\domain\\Domain",
108
-            $this->main_file,
109
-            $this->version
110
-        );
111
-    }
112
-
113
-
114
-    /**
115
-     * @return int[]
116
-     */
117
-    private function validApiVersions(): array
118
-    {
119
-        return [
120
-            AddonApiVersion::V1,
121
-        ];
122
-    }
123
-
124
-
125
-    /**
126
-     * @param int $api_version
127
-     */
128
-    private function setApiVersion(int $api_version): void
129
-    {
130
-        if (! in_array($api_version, $this->validApiVersions())) {
131
-            throw new DomainException(
132
-                esc_html__(
133
-                    'Invalid Add-on API Version! Please use one of the EventEspresso\core\domain\entities\addon\Bootstrap class constants',
134
-                    'event_espresso'
135
-                )
136
-            );
137
-        }
138
-        $this->api_version = $api_version;
139
-    }
140
-
141
-
142
-    /**
143
-     * @param string $main_file
144
-     */
145
-    public function setMainFile(string $main_file): void
146
-    {
147
-        $this->main_file = new FilePath($main_file);
148
-    }
149
-
150
-
151
-    /**
152
-     * @param string $min_core_version
153
-     */
154
-    private function setMinCoreVersion(string $min_core_version): void
155
-    {
156
-        $this->min_core_version = Version::fromString($min_core_version);
157
-    }
158
-
159
-
160
-    /**
161
-     * @param string $name
162
-     */
163
-    public function setName(string $name): void
164
-    {
165
-        $this->name = $name;
166
-    }
167
-
168
-
169
-    /**
170
-     * @param string $namespace
171
-     */
172
-    private function setNamespace(string $namespace): void
173
-    {
174
-        $this->addon_namespace = $namespace;
175
-    }
176
-
177
-
178
-    /**
179
-     * @param string $slug
180
-     */
181
-    private function setSlug(string $slug): void
182
-    {
183
-        $valid_slug = sanitize_key($slug);
184
-        if ($slug !== $valid_slug) {
185
-            throw new DomainException(
186
-                esc_html__(
187
-                    'Invalid Add-on "slug"! Please ensure that slug only uses lowercase characters and dashes.',
188
-                    'event_espresso'
189
-                )
190
-            );
191
-        }
192
-        $this->slug = $valid_slug;
193
-    }
194
-
195
-
196
-    /**
197
-     * @param string $version
198
-     */
199
-    public function setVersion(string $version): void
200
-    {
201
-        $this->version = Version::fromString($version);
202
-    }
203
-
204
-
205
-    /**
206
-     * @return int
207
-     */
208
-    public function apiVersion(): int
209
-    {
210
-        return $this->api_version;
211
-    }
212
-
213
-
214
-    /**
215
-     * @return DomainInterface
216
-     */
217
-    public function domain(): DomainInterface
218
-    {
219
-        return $this->domain;
220
-    }
221
-
222
-
223
-    /**
224
-     * @return Version|null
225
-     */
226
-    public function minCoreVersion(): ?Version
227
-    {
228
-        return $this->min_core_version;
229
-    }
230
-
231
-
232
-    /**
233
-     * @return Version|null
234
-     */
235
-    public function minWpVersion(): ?Version
236
-    {
237
-        return $this->min_wp_version;
238
-    }
239
-
240
-
241
-    /**
242
-     * @param string $min_wp_version
243
-     */
244
-    public function setMinWpVersion(string $min_wp_version = EE_MIN_WP_VER_REQUIRED): void
245
-    {
246
-        $this->min_wp_version = Version::fromString($min_wp_version);
247
-    }
248
-
249
-
250
-    /**
251
-     * @return string
252
-     */
253
-    public function name(): string
254
-    {
255
-        return $this->name;
256
-    }
257
-
258
-
259
-    /**
260
-     * FQCN for the domain's EE_Addon class
261
-     *
262
-     * @return string
263
-     */
264
-    public function fqcn(): string
265
-    {
266
-        return "{$this->addon_namespace}\\domain\\{$this->name}";
267
-    }
268
-
269
-
270
-    /**
271
-     * @return string
272
-     */
273
-    public function getNamespace(): string
274
-    {
275
-        return $this->addon_namespace;
276
-    }
277
-
278
-
279
-    /**
280
-     * @return FilePath
281
-     */
282
-    public function mainFile(): FilePath
283
-    {
284
-        return $this->main_file;
285
-    }
286
-
287
-
288
-    /**
289
-     * @return string
290
-     */
291
-    public function slug(): string
292
-    {
293
-        return $this->slug;
294
-    }
295
-
296
-
297
-    /**
298
-     * @return Version
299
-     */
300
-    public function version(): Version
301
-    {
302
-        return $this->version;
303
-    }
22
+	const V1 = 1;
23
+
24
+	/**
25
+	 * @var int one of the API_VERSION_* constants from above
26
+	 */
27
+	private $api_version;
28
+
29
+	/**
30
+	 * @var DomainInterface
31
+	 */
32
+	private $domain;
33
+
34
+	/**
35
+	 * @var Version minimum version of EE core that the add-on will work with
36
+	 */
37
+	private $min_core_version;
38
+
39
+	/**
40
+	 * @var Version minimum version of WP core that the add-on will work with
41
+	 */
42
+	private $min_wp_version;
43
+
44
+	/**
45
+	 * @var string  PascalCase identifier for the add-on.
46
+	 *              IMPORTANT! there must be a class of the same name in the root of the add-ons /src/domain/ folder
47
+	 */
48
+	private $name;
49
+
50
+	/**
51
+	 * @var string
52
+	 */
53
+	private $addon_namespace;
54
+
55
+	/**
56
+	 * @var FilePath
57
+	 */
58
+	private $main_file;
59
+
60
+	/**
61
+	 * @var string
62
+	 */
63
+	private $slug;
64
+
65
+	/**
66
+	 * @var Version the current add-on version
67
+	 */
68
+	private $version;
69
+
70
+
71
+	/**
72
+	 * Bootstrap constructor.
73
+	 *
74
+	 * @param string $slug
75
+	 * @param string $name
76
+	 * @param string $namespace
77
+	 * @param string $version
78
+	 * @param string $min_core_version
79
+	 * @param string $main_file
80
+	 * @param int    $api_version
81
+	 */
82
+	protected function __construct(
83
+		string $slug,
84
+		string $name,
85
+		string $namespace,
86
+		string $version,
87
+		string $min_core_version,
88
+		string $main_file,
89
+		int $api_version
90
+	) {
91
+		$this->setSlug($slug);
92
+		$this->setName($name);
93
+		$this->setNamespace($namespace);
94
+		$this->setMinCoreVersion($min_core_version);
95
+		$this->setMainFile($main_file);
96
+		$this->setVersion($version);
97
+		$this->setApiVersion($api_version);
98
+	}
99
+
100
+
101
+	/**
102
+	 * @return void
103
+	 */
104
+	public function initialize(): void
105
+	{
106
+		$this->domain = DomainFactory::create(
107
+			"{$this->addon_namespace}\\domain\\Domain",
108
+			$this->main_file,
109
+			$this->version
110
+		);
111
+	}
112
+
113
+
114
+	/**
115
+	 * @return int[]
116
+	 */
117
+	private function validApiVersions(): array
118
+	{
119
+		return [
120
+			AddonApiVersion::V1,
121
+		];
122
+	}
123
+
124
+
125
+	/**
126
+	 * @param int $api_version
127
+	 */
128
+	private function setApiVersion(int $api_version): void
129
+	{
130
+		if (! in_array($api_version, $this->validApiVersions())) {
131
+			throw new DomainException(
132
+				esc_html__(
133
+					'Invalid Add-on API Version! Please use one of the EventEspresso\core\domain\entities\addon\Bootstrap class constants',
134
+					'event_espresso'
135
+				)
136
+			);
137
+		}
138
+		$this->api_version = $api_version;
139
+	}
140
+
141
+
142
+	/**
143
+	 * @param string $main_file
144
+	 */
145
+	public function setMainFile(string $main_file): void
146
+	{
147
+		$this->main_file = new FilePath($main_file);
148
+	}
149
+
150
+
151
+	/**
152
+	 * @param string $min_core_version
153
+	 */
154
+	private function setMinCoreVersion(string $min_core_version): void
155
+	{
156
+		$this->min_core_version = Version::fromString($min_core_version);
157
+	}
158
+
159
+
160
+	/**
161
+	 * @param string $name
162
+	 */
163
+	public function setName(string $name): void
164
+	{
165
+		$this->name = $name;
166
+	}
167
+
168
+
169
+	/**
170
+	 * @param string $namespace
171
+	 */
172
+	private function setNamespace(string $namespace): void
173
+	{
174
+		$this->addon_namespace = $namespace;
175
+	}
176
+
177
+
178
+	/**
179
+	 * @param string $slug
180
+	 */
181
+	private function setSlug(string $slug): void
182
+	{
183
+		$valid_slug = sanitize_key($slug);
184
+		if ($slug !== $valid_slug) {
185
+			throw new DomainException(
186
+				esc_html__(
187
+					'Invalid Add-on "slug"! Please ensure that slug only uses lowercase characters and dashes.',
188
+					'event_espresso'
189
+				)
190
+			);
191
+		}
192
+		$this->slug = $valid_slug;
193
+	}
194
+
195
+
196
+	/**
197
+	 * @param string $version
198
+	 */
199
+	public function setVersion(string $version): void
200
+	{
201
+		$this->version = Version::fromString($version);
202
+	}
203
+
204
+
205
+	/**
206
+	 * @return int
207
+	 */
208
+	public function apiVersion(): int
209
+	{
210
+		return $this->api_version;
211
+	}
212
+
213
+
214
+	/**
215
+	 * @return DomainInterface
216
+	 */
217
+	public function domain(): DomainInterface
218
+	{
219
+		return $this->domain;
220
+	}
221
+
222
+
223
+	/**
224
+	 * @return Version|null
225
+	 */
226
+	public function minCoreVersion(): ?Version
227
+	{
228
+		return $this->min_core_version;
229
+	}
230
+
231
+
232
+	/**
233
+	 * @return Version|null
234
+	 */
235
+	public function minWpVersion(): ?Version
236
+	{
237
+		return $this->min_wp_version;
238
+	}
239
+
240
+
241
+	/**
242
+	 * @param string $min_wp_version
243
+	 */
244
+	public function setMinWpVersion(string $min_wp_version = EE_MIN_WP_VER_REQUIRED): void
245
+	{
246
+		$this->min_wp_version = Version::fromString($min_wp_version);
247
+	}
248
+
249
+
250
+	/**
251
+	 * @return string
252
+	 */
253
+	public function name(): string
254
+	{
255
+		return $this->name;
256
+	}
257
+
258
+
259
+	/**
260
+	 * FQCN for the domain's EE_Addon class
261
+	 *
262
+	 * @return string
263
+	 */
264
+	public function fqcn(): string
265
+	{
266
+		return "{$this->addon_namespace}\\domain\\{$this->name}";
267
+	}
268
+
269
+
270
+	/**
271
+	 * @return string
272
+	 */
273
+	public function getNamespace(): string
274
+	{
275
+		return $this->addon_namespace;
276
+	}
277
+
278
+
279
+	/**
280
+	 * @return FilePath
281
+	 */
282
+	public function mainFile(): FilePath
283
+	{
284
+		return $this->main_file;
285
+	}
286
+
287
+
288
+	/**
289
+	 * @return string
290
+	 */
291
+	public function slug(): string
292
+	{
293
+		return $this->slug;
294
+	}
295
+
296
+
297
+	/**
298
+	 * @return Version
299
+	 */
300
+	public function version(): Version
301
+	{
302
+		return $this->version;
303
+	}
304 304
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -127,7 +127,7 @@
 block discarded – undo
127 127
      */
128 128
     private function setApiVersion(int $api_version): void
129 129
     {
130
-        if (! in_array($api_version, $this->validApiVersions())) {
130
+        if ( ! in_array($api_version, $this->validApiVersions())) {
131 131
             throw new DomainException(
132 132
                 esc_html__(
133 133
                     'Invalid Add-on API Version! Please use one of the EventEspresso\core\domain\entities\addon\Bootstrap class constants',
Please login to merge, or discard this patch.
core/services/addon/api/ThirdPartyPluginHandler.php 2 patches
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -7,42 +7,42 @@
 block discarded – undo
7 7
 class ThirdPartyPluginHandler
8 8
 {
9 9
 
10
-    /**
11
-     * @var RequestInterface $request
12
-     */
13
-    private $request;
14
-
15
-
16
-    /**
17
-     * ThirdPartyPluginHandler constructor.
18
-     *
19
-     * @param RequestInterface $request
20
-     */
21
-    public function __construct(RequestInterface $request)
22
-    {
23
-        $this->request = $request;
24
-    }
25
-
26
-
27
-    public function loadPlugins()
28
-    {
29
-        $this->wpApiBasicAuth();
30
-    }
31
-
32
-
33
-    private function wpApiBasicAuth()
34
-    {
35
-        // if the WP API basic auth plugin isn't already loaded, load it now.
36
-        // We want it for mobile apps. Just include the entire plugin
37
-        // also, don't load the basic auth when a plugin is getting activated, because
38
-        // it could be the basic auth plugin, and it doesn't check if its methods are already defined
39
-        // and causes a fatal error
40
-        if (($this->request->isWordPressApi() || $this->request->isApi())
41
-            && ! $this->request->isActivation()
42
-            && ! function_exists('json_basic_auth_handler')
43
-            && ! function_exists('json_basic_auth_error')
44
-        ) {
45
-            include_once EE_THIRD_PARTY . 'wp-api-basic-auth/basic-auth.php';
46
-        }
47
-    }
10
+	/**
11
+	 * @var RequestInterface $request
12
+	 */
13
+	private $request;
14
+
15
+
16
+	/**
17
+	 * ThirdPartyPluginHandler constructor.
18
+	 *
19
+	 * @param RequestInterface $request
20
+	 */
21
+	public function __construct(RequestInterface $request)
22
+	{
23
+		$this->request = $request;
24
+	}
25
+
26
+
27
+	public function loadPlugins()
28
+	{
29
+		$this->wpApiBasicAuth();
30
+	}
31
+
32
+
33
+	private function wpApiBasicAuth()
34
+	{
35
+		// if the WP API basic auth plugin isn't already loaded, load it now.
36
+		// We want it for mobile apps. Just include the entire plugin
37
+		// also, don't load the basic auth when a plugin is getting activated, because
38
+		// it could be the basic auth plugin, and it doesn't check if its methods are already defined
39
+		// and causes a fatal error
40
+		if (($this->request->isWordPressApi() || $this->request->isApi())
41
+			&& ! $this->request->isActivation()
42
+			&& ! function_exists('json_basic_auth_handler')
43
+			&& ! function_exists('json_basic_auth_error')
44
+		) {
45
+			include_once EE_THIRD_PARTY . 'wp-api-basic-auth/basic-auth.php';
46
+		}
47
+	}
48 48
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@
 block discarded – undo
42 42
             && ! function_exists('json_basic_auth_handler')
43 43
             && ! function_exists('json_basic_auth_error')
44 44
         ) {
45
-            include_once EE_THIRD_PARTY . 'wp-api-basic-auth/basic-auth.php';
45
+            include_once EE_THIRD_PARTY.'wp-api-basic-auth/basic-auth.php';
46 46
         }
47 47
     }
48 48
 }
Please login to merge, or discard this patch.
core/services/addon/api/v1/LegacyModelApi.php 1 patch
Indentation   +91 added lines, -91 removed lines patch added patch discarded remove patch
@@ -5,95 +5,95 @@
 block discarded – undo
5 5
 class LegacyModelApi
6 6
 {
7 7
 
8
-    /**
9
-     * @var string path to EE_* entity classes
10
-     */
11
-    private $entity_classes;
12
-
13
-    /**
14
-     * @var string path to EEM_* entity model classes
15
-     */
16
-    private $entity_models;
17
-
18
-    /**
19
-     * @var string path to EEE_* entity class extensions
20
-     */
21
-    private $entity_class_extensions;
22
-
23
-    /**
24
-     * @var string path to EEME_* entity model class extensions
25
-     */
26
-    private $entity_model_extensions;
27
-
28
-
29
-    /**
30
-     * @return string
31
-     */
32
-    public function entityClasses(): string
33
-    {
34
-        return $this->entity_classes;
35
-    }
36
-
37
-
38
-    /**
39
-     * @param string $entity_classes
40
-     */
41
-    public function addEntityClasses(string $entity_classes): void
42
-    {
43
-        $this->entity_classes = $entity_classes;
44
-    }
45
-
46
-
47
-    /**
48
-     * @return string
49
-     */
50
-    public function entityModels(): string
51
-    {
52
-        return $this->entity_models;
53
-    }
54
-
55
-
56
-    /**
57
-     * @param string $entity_models
58
-     */
59
-    public function addEntityModels(string $entity_models): void
60
-    {
61
-        $this->entity_models = $entity_models;
62
-    }
63
-
64
-
65
-    /**
66
-     * @return string
67
-     */
68
-    public function entityClassExtensions(): string
69
-    {
70
-        return $this->entity_class_extensions;
71
-    }
72
-
73
-
74
-    /**
75
-     * @param string $entity_class_extensions
76
-     */
77
-    public function addEntityClassExtensions(string $entity_class_extensions): void
78
-    {
79
-        $this->entity_class_extensions = $entity_class_extensions;
80
-    }
81
-
82
-
83
-    /**
84
-     * @return string
85
-     */
86
-    public function entityModelExtensions(): string
87
-    {
88
-        return $this->entity_model_extensions;
89
-    }
90
-
91
-
92
-    /**
93
-     * @param string $entity_model_extensions
94
-     */
95
-    public function addEntityModelExtensions(string $entity_model_extensions): void
96
-    {
97
-        $this->entity_model_extensions = $entity_model_extensions;
98
-    }
8
+	/**
9
+	 * @var string path to EE_* entity classes
10
+	 */
11
+	private $entity_classes;
12
+
13
+	/**
14
+	 * @var string path to EEM_* entity model classes
15
+	 */
16
+	private $entity_models;
17
+
18
+	/**
19
+	 * @var string path to EEE_* entity class extensions
20
+	 */
21
+	private $entity_class_extensions;
22
+
23
+	/**
24
+	 * @var string path to EEME_* entity model class extensions
25
+	 */
26
+	private $entity_model_extensions;
27
+
28
+
29
+	/**
30
+	 * @return string
31
+	 */
32
+	public function entityClasses(): string
33
+	{
34
+		return $this->entity_classes;
35
+	}
36
+
37
+
38
+	/**
39
+	 * @param string $entity_classes
40
+	 */
41
+	public function addEntityClasses(string $entity_classes): void
42
+	{
43
+		$this->entity_classes = $entity_classes;
44
+	}
45
+
46
+
47
+	/**
48
+	 * @return string
49
+	 */
50
+	public function entityModels(): string
51
+	{
52
+		return $this->entity_models;
53
+	}
54
+
55
+
56
+	/**
57
+	 * @param string $entity_models
58
+	 */
59
+	public function addEntityModels(string $entity_models): void
60
+	{
61
+		$this->entity_models = $entity_models;
62
+	}
63
+
64
+
65
+	/**
66
+	 * @return string
67
+	 */
68
+	public function entityClassExtensions(): string
69
+	{
70
+		return $this->entity_class_extensions;
71
+	}
72
+
73
+
74
+	/**
75
+	 * @param string $entity_class_extensions
76
+	 */
77
+	public function addEntityClassExtensions(string $entity_class_extensions): void
78
+	{
79
+		$this->entity_class_extensions = $entity_class_extensions;
80
+	}
81
+
82
+
83
+	/**
84
+	 * @return string
85
+	 */
86
+	public function entityModelExtensions(): string
87
+	{
88
+		return $this->entity_model_extensions;
89
+	}
90
+
91
+
92
+	/**
93
+	 * @param string $entity_model_extensions
94
+	 */
95
+	public function addEntityModelExtensions(string $entity_model_extensions): void
96
+	{
97
+		$this->entity_model_extensions = $entity_model_extensions;
98
+	}
99 99
 }
Please login to merge, or discard this patch.
core/services/addon/api/v1/RegisterAddon.php 1 patch
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -8,26 +8,26 @@
 block discarded – undo
8 8
 
9 9
 class RegisterAddon
10 10
 {
11
-    /**
12
-     * @param AddonApiV1 $addon
13
-     * @throws EE_Error
14
-     */
15
-    public function register(AddonApiV1 $addon)
16
-    {
17
-        EE_Register_Addon::register(
18
-            $addon->fqcn(),
19
-            [
20
-                'version'               => $addon->version(),
21
-                'plugin_slug'           => $addon->slug(),
22
-                'min_core_version'      => $addon->minCoreVersion(),
23
-                'min_wp_version'        => $addon->minWpVersion(),
24
-                'main_file_path'        => $addon->mainFile(),
25
-                'dms_paths'             => [$addon->dataMigrationScripts()],
26
-                'class_paths'           => [$addon->entityClasses()],
27
-                'model_paths'           => [$addon->entityModels()],
28
-                'class_extension_paths' => [$addon->entityClassExtensions()],
29
-                'model_extension_paths' => [$addon->entityModelExtensions()],
30
-            ]
31
-        );
32
-    }
11
+	/**
12
+	 * @param AddonApiV1 $addon
13
+	 * @throws EE_Error
14
+	 */
15
+	public function register(AddonApiV1 $addon)
16
+	{
17
+		EE_Register_Addon::register(
18
+			$addon->fqcn(),
19
+			[
20
+				'version'               => $addon->version(),
21
+				'plugin_slug'           => $addon->slug(),
22
+				'min_core_version'      => $addon->minCoreVersion(),
23
+				'min_wp_version'        => $addon->minWpVersion(),
24
+				'main_file_path'        => $addon->mainFile(),
25
+				'dms_paths'             => [$addon->dataMigrationScripts()],
26
+				'class_paths'           => [$addon->entityClasses()],
27
+				'model_paths'           => [$addon->entityModels()],
28
+				'class_extension_paths' => [$addon->entityClassExtensions()],
29
+				'model_extension_paths' => [$addon->entityModelExtensions()],
30
+			]
31
+		);
32
+	}
33 33
 }
Please login to merge, or discard this patch.
core/services/addon/api/v1/AddonApi.php 1 patch
Indentation   +131 added lines, -131 removed lines patch added patch discarded remove patch
@@ -7,135 +7,135 @@
 block discarded – undo
7 7
 class AddonApi extends AddonApiVersion
8 8
 {
9 9
 
10
-    /**
11
-     * @var DataMigrationApi
12
-     */
13
-    private $data_migration_api;
14
-
15
-    /**
16
-     * @var LegacyModelApi
17
-     */
18
-    private $legacy_model_api;
19
-
20
-
21
-    /**
22
-     * Bootstrap constructor.
23
-     *
24
-     * @param string $slug
25
-     * @param string $name
26
-     * @param string $namespace
27
-     * @param string $version
28
-     * @param string $min_core_version
29
-     * @param string $main_file
30
-     */
31
-    public function __construct(
32
-        string $slug,
33
-        string $name,
34
-        string $namespace,
35
-        string $version,
36
-        string $min_core_version,
37
-        string $main_file
38
-    ) {
39
-        parent::__construct(
40
-            $slug,
41
-            $name,
42
-            $namespace,
43
-            $version,
44
-            $min_core_version,
45
-            $main_file,
46
-            AddonApiVersion::V1
47
-        );
48
-        $this->legacy_model_api = new LegacyModelApi();
49
-        $this->data_migration_api = new DataMigrationApi();
50
-    }
51
-
52
-
53
-    /**
54
-     * @return string
55
-     */
56
-    public function dataMigrationScripts(): string
57
-    {
58
-        return $this->data_migration_api->dataMigrationScripts();
59
-    }
60
-
61
-
62
-    /**
63
-     * @param string $data_migration_scripts
64
-     */
65
-    public function addDataMigrationScripts(string $data_migration_scripts): void
66
-    {
67
-        $this->data_migration_api->addDataMigrationScripts($data_migration_scripts);
68
-    }
69
-
70
-
71
-    /**
72
-     * @return string
73
-     */
74
-    public function entityClasses(): string
75
-    {
76
-        return $this->legacy_model_api->entityClasses();
77
-    }
78
-
79
-
80
-    /**
81
-     * @param string $entity_classes
82
-     */
83
-    public function addEntityClasses(string $entity_classes): void
84
-    {
85
-        $this->legacy_model_api->addEntityClasses($entity_classes);
86
-    }
87
-
88
-
89
-    /**
90
-     * @return string
91
-     */
92
-    public function entityModels(): string
93
-    {
94
-        return $this->legacy_model_api->entityModels();
95
-    }
96
-
97
-
98
-    /**
99
-     * @param string $entity_models
100
-     */
101
-    public function addEntityModels(string $entity_models): void
102
-    {
103
-        $this->legacy_model_api->addEntityModels($entity_models);
104
-    }
105
-
106
-
107
-    /**
108
-     * @return string
109
-     */
110
-    public function entityClassExtensions(): string
111
-    {
112
-        return $this->legacy_model_api->entityClassExtensions();
113
-    }
114
-
115
-
116
-    /**
117
-     * @param string $entity_class_extensions
118
-     */
119
-    public function addEntityClassExtensions(string $entity_class_extensions): void
120
-    {
121
-        $this->legacy_model_api->addEntityClassExtensions($entity_class_extensions);
122
-    }
123
-
124
-
125
-    /**
126
-     * @return string
127
-     */
128
-    public function entityModelExtensions(): string
129
-    {
130
-        return $this->legacy_model_api->entityModelExtensions();
131
-    }
132
-
133
-
134
-    /**
135
-     * @param string $entity_model_extensions
136
-     */
137
-    public function addEntityModelExtensions(string $entity_model_extensions): void
138
-    {
139
-        $this->legacy_model_api->addEntityModelExtensions($entity_model_extensions);
140
-    }
10
+	/**
11
+	 * @var DataMigrationApi
12
+	 */
13
+	private $data_migration_api;
14
+
15
+	/**
16
+	 * @var LegacyModelApi
17
+	 */
18
+	private $legacy_model_api;
19
+
20
+
21
+	/**
22
+	 * Bootstrap constructor.
23
+	 *
24
+	 * @param string $slug
25
+	 * @param string $name
26
+	 * @param string $namespace
27
+	 * @param string $version
28
+	 * @param string $min_core_version
29
+	 * @param string $main_file
30
+	 */
31
+	public function __construct(
32
+		string $slug,
33
+		string $name,
34
+		string $namespace,
35
+		string $version,
36
+		string $min_core_version,
37
+		string $main_file
38
+	) {
39
+		parent::__construct(
40
+			$slug,
41
+			$name,
42
+			$namespace,
43
+			$version,
44
+			$min_core_version,
45
+			$main_file,
46
+			AddonApiVersion::V1
47
+		);
48
+		$this->legacy_model_api = new LegacyModelApi();
49
+		$this->data_migration_api = new DataMigrationApi();
50
+	}
51
+
52
+
53
+	/**
54
+	 * @return string
55
+	 */
56
+	public function dataMigrationScripts(): string
57
+	{
58
+		return $this->data_migration_api->dataMigrationScripts();
59
+	}
60
+
61
+
62
+	/**
63
+	 * @param string $data_migration_scripts
64
+	 */
65
+	public function addDataMigrationScripts(string $data_migration_scripts): void
66
+	{
67
+		$this->data_migration_api->addDataMigrationScripts($data_migration_scripts);
68
+	}
69
+
70
+
71
+	/**
72
+	 * @return string
73
+	 */
74
+	public function entityClasses(): string
75
+	{
76
+		return $this->legacy_model_api->entityClasses();
77
+	}
78
+
79
+
80
+	/**
81
+	 * @param string $entity_classes
82
+	 */
83
+	public function addEntityClasses(string $entity_classes): void
84
+	{
85
+		$this->legacy_model_api->addEntityClasses($entity_classes);
86
+	}
87
+
88
+
89
+	/**
90
+	 * @return string
91
+	 */
92
+	public function entityModels(): string
93
+	{
94
+		return $this->legacy_model_api->entityModels();
95
+	}
96
+
97
+
98
+	/**
99
+	 * @param string $entity_models
100
+	 */
101
+	public function addEntityModels(string $entity_models): void
102
+	{
103
+		$this->legacy_model_api->addEntityModels($entity_models);
104
+	}
105
+
106
+
107
+	/**
108
+	 * @return string
109
+	 */
110
+	public function entityClassExtensions(): string
111
+	{
112
+		return $this->legacy_model_api->entityClassExtensions();
113
+	}
114
+
115
+
116
+	/**
117
+	 * @param string $entity_class_extensions
118
+	 */
119
+	public function addEntityClassExtensions(string $entity_class_extensions): void
120
+	{
121
+		$this->legacy_model_api->addEntityClassExtensions($entity_class_extensions);
122
+	}
123
+
124
+
125
+	/**
126
+	 * @return string
127
+	 */
128
+	public function entityModelExtensions(): string
129
+	{
130
+		return $this->legacy_model_api->entityModelExtensions();
131
+	}
132
+
133
+
134
+	/**
135
+	 * @param string $entity_model_extensions
136
+	 */
137
+	public function addEntityModelExtensions(string $entity_model_extensions): void
138
+	{
139
+		$this->legacy_model_api->addEntityModelExtensions($entity_model_extensions);
140
+	}
141 141
 }
Please login to merge, or discard this patch.
core/services/addon/api/v1/DataMigrationApi.php 1 patch
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -5,26 +5,26 @@
 block discarded – undo
5 5
 class DataMigrationApi
6 6
 {
7 7
 
8
-    /**
9
-     * @var string path to DMS folder
10
-     */
11
-    private $data_migration_scripts;
8
+	/**
9
+	 * @var string path to DMS folder
10
+	 */
11
+	private $data_migration_scripts;
12 12
 
13 13
 
14
-    /**
15
-     * @return string
16
-     */
17
-    public function dataMigrationScripts(): string
18
-    {
19
-        return $this->data_migration_scripts;
20
-    }
14
+	/**
15
+	 * @return string
16
+	 */
17
+	public function dataMigrationScripts(): string
18
+	{
19
+		return $this->data_migration_scripts;
20
+	}
21 21
 
22 22
 
23
-    /**
24
-     * @param string $data_migration_scripts
25
-     */
26
-    public function addDataMigrationScripts(string $data_migration_scripts): void
27
-    {
28
-        $this->data_migration_scripts = $data_migration_scripts;
29
-    }
23
+	/**
24
+	 * @param string $data_migration_scripts
25
+	 */
26
+	public function addDataMigrationScripts(string $data_migration_scripts): void
27
+	{
28
+		$this->data_migration_scripts = $data_migration_scripts;
29
+	}
30 30
 }
Please login to merge, or discard this patch.
core/libraries/plugin_api/EE_Register_Model.lib.php 2 patches
Indentation   +175 added lines, -175 removed lines patch added patch discarded remove patch
@@ -11,193 +11,193 @@
 block discarded – undo
11 11
  */
12 12
 class EE_Register_Model implements EEI_Plugin_API
13 13
 {
14
-    /**
15
-     *
16
-     * @var array keys are the model_id used to register with, values are the array provided to register them, exactly
17
-     *      like EE_Register_Model::register()'s 2nd arg
18
-     */
19
-    protected static $_model_registry;
14
+	/**
15
+	 *
16
+	 * @var array keys are the model_id used to register with, values are the array provided to register them, exactly
17
+	 *      like EE_Register_Model::register()'s 2nd arg
18
+	 */
19
+	protected static $_model_registry;
20 20
 
21
-    /**
22
-     *
23
-     * @var array keys are model names, values are their class names. Stored on registration and used
24
-     * on a hook
25
-     */
26
-    protected static $_model_name_to_classname_map;
21
+	/**
22
+	 *
23
+	 * @var array keys are model names, values are their class names. Stored on registration and used
24
+	 * on a hook
25
+	 */
26
+	protected static $_model_name_to_classname_map;
27 27
 
28 28
 
29
-    /**
30
-     * @param string $model_id    unique id for it
31
-     * @param array  $config      {
32
-     * @type array   $model_paths array of folders containing DB models, where each file follows the models naming
33
-     *                            convention, which is: EEM_{model_name}.model.php which contains a single class called
34
-     *                            EEM_{model_name}. Eg. you could pass
35
-     *                            "public_html/wp-content/plugins/my_addon/db_models" (with or without trailing slash)
36
-     *                            and in that folder put each of your model files, like "EEM_Food.model.php" which
37
-     *                            contains the class "EEM_Food" and
38
-     *                            "EEM_Monkey.model.php" which contains the class "EEM_Monkey". These will be
39
-     *                            autoloaded and added to the EE registry so they can be used like ordinary models. The
40
-     *                            class contained in each file should extend EEM_Base.
41
-     * @type array   $class_paths array of folders containing DB classes, where each file follows the model class
42
-     *                            naming convention, which is EE_{model_name}.class.php. The class contained in each
43
-     *                            file should extend EE_Base_Class
44
-     *
45
-     * }
46
-     * @return bool
47
-     * @throws EE_Error
48
-     */
49
-    public static function register(string $model_id = '', array $config = []): bool
50
-    {
51
-        // required fields MUST be present, so let's make sure they are.
52
-        if (empty($model_id) || ! is_array($config) || empty($config['model_paths'])) {
53
-            throw new EE_Error(
54
-                __(
55
-                    'In order to register Models with EE_Register_Model::register(), you must include a "model_id" (a unique identifier for this set of models), and an array containing the following keys: "model_paths" (an array of full server paths to folders that contain models)',
56
-                    'event_espresso'
57
-                )
58
-            );
59
-        }
29
+	/**
30
+	 * @param string $model_id    unique id for it
31
+	 * @param array  $config      {
32
+	 * @type array   $model_paths array of folders containing DB models, where each file follows the models naming
33
+	 *                            convention, which is: EEM_{model_name}.model.php which contains a single class called
34
+	 *                            EEM_{model_name}. Eg. you could pass
35
+	 *                            "public_html/wp-content/plugins/my_addon/db_models" (with or without trailing slash)
36
+	 *                            and in that folder put each of your model files, like "EEM_Food.model.php" which
37
+	 *                            contains the class "EEM_Food" and
38
+	 *                            "EEM_Monkey.model.php" which contains the class "EEM_Monkey". These will be
39
+	 *                            autoloaded and added to the EE registry so they can be used like ordinary models. The
40
+	 *                            class contained in each file should extend EEM_Base.
41
+	 * @type array   $class_paths array of folders containing DB classes, where each file follows the model class
42
+	 *                            naming convention, which is EE_{model_name}.class.php. The class contained in each
43
+	 *                            file should extend EE_Base_Class
44
+	 *
45
+	 * }
46
+	 * @return bool
47
+	 * @throws EE_Error
48
+	 */
49
+	public static function register(string $model_id = '', array $config = []): bool
50
+	{
51
+		// required fields MUST be present, so let's make sure they are.
52
+		if (empty($model_id) || ! is_array($config) || empty($config['model_paths'])) {
53
+			throw new EE_Error(
54
+				__(
55
+					'In order to register Models with EE_Register_Model::register(), you must include a "model_id" (a unique identifier for this set of models), and an array containing the following keys: "model_paths" (an array of full server paths to folders that contain models)',
56
+					'event_espresso'
57
+				)
58
+			);
59
+		}
60 60
 
61
-        // make sure we don't register twice
62
-        if (isset(self::$_model_registry[ $model_id ])) {
63
-            return true;
64
-        }
61
+		// make sure we don't register twice
62
+		if (isset(self::$_model_registry[ $model_id ])) {
63
+			return true;
64
+		}
65 65
 
66
-        if (! did_action('AHEE__EE_System__load_espresso_addons')
67
-            || did_action('FHEE__EE_System__parse_model_names')
68
-            || did_action('FHEE__EE_System__parse_implemented_model_names')
69
-        ) {
70
-            EE_Error::doing_it_wrong(
71
-                __METHOD__,
72
-                sprintf(
73
-                    __(
74
-                        'An attempt was made to register "%s" as a group models has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__load_espresso_addons" hook to register models.',
75
-                        'event_espresso'
76
-                    ),
77
-                    $model_id
78
-                ),
79
-                '4.5'
80
-            );
81
-        }
82
-        self::$_model_registry[ $model_id ] = $config;
66
+		if (! did_action('AHEE__EE_System__load_espresso_addons')
67
+			|| did_action('FHEE__EE_System__parse_model_names')
68
+			|| did_action('FHEE__EE_System__parse_implemented_model_names')
69
+		) {
70
+			EE_Error::doing_it_wrong(
71
+				__METHOD__,
72
+				sprintf(
73
+					__(
74
+						'An attempt was made to register "%s" as a group models has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__load_espresso_addons" hook to register models.',
75
+						'event_espresso'
76
+					),
77
+					$model_id
78
+				),
79
+				'4.5'
80
+			);
81
+		}
82
+		self::$_model_registry[ $model_id ] = $config;
83 83
 
84
-        if ((isset($config['model_paths']) && ! isset($config['class_paths']))
85
-            || (! isset($config['model_paths']) && isset($config['class_paths']))
86
-        ) {
87
-            throw new EE_Error(
88
-                sprintf(
89
-                    __(
90
-                        'You must register both "model_paths" AND "class_paths", not just one or the other You provided %s',
91
-                        'event_espresso'
92
-                    ),
93
-                    implode(", ", array_keys($config))
94
-                )
95
-            );
96
-        }
97
-        if (isset($config['model_paths'])) {
98
-            // make sure they passed in an array
99
-            if (! is_array($config['model_paths'])) {
100
-                $config['model_paths'] = [$config['model_paths']];
101
-            }
102
-            // we want to add this as a model folder
103
-            // and autoload them all
104
-            $class_to_filepath_map = EEH_File::get_contents_of_folders($config['model_paths']);
105
-            EEH_Autoloader::register_autoloader($class_to_filepath_map);
106
-            $model_name_to_classname_map = [];
107
-            foreach (array_keys($class_to_filepath_map) as $classname) {
108
-                $model_name_to_classname_map[ str_replace("EEM_", "", $classname) ] = $classname;
109
-            }
110
-            self::$_model_name_to_classname_map[ $model_id ] = $model_name_to_classname_map;
111
-            add_filter('FHEE__EE_System__parse_model_names', ['EE_Register_Model', 'add_addon_models']);
112
-            add_filter(
113
-                'FHEE__EE_System__parse_implemented_model_names',
114
-                ['EE_Register_Model', 'add_addon_models']
115
-            );
116
-            add_filter('FHEE__EE_Registry__load_model__paths', ['EE_Register_Model', 'add_model_folders']);
117
-            unset($config['model_paths']);
118
-        }
119
-        if (isset($config['class_paths'])) {
120
-            // make sure they passed in an array
121
-            if (! is_array($config['class_paths'])) {
122
-                $config['class_paths'] = [$config['class_paths']];
123
-            }
124
-            $class_to_filepath_map = EEH_File::get_contents_of_folders($config['class_paths']);
125
-            EEH_Autoloader::register_autoloader($class_to_filepath_map);
126
-            add_filter('FHEE__EE_Registry__load_class__paths', ['EE_Register_Model', 'add_class_folders']);
127
-            unset($config['class_paths']);
128
-        }
129
-        foreach ($config as $unknown_key => $unknown_config) {
130
-            self::deregister($model_id);
131
-            throw new EE_Error(
132
-                sprintf(__("The key '%s' is not a known key for registering a model", "event_espresso"), $unknown_key)
133
-            );
134
-        }
135
-        return true;
136
-    }
84
+		if ((isset($config['model_paths']) && ! isset($config['class_paths']))
85
+			|| (! isset($config['model_paths']) && isset($config['class_paths']))
86
+		) {
87
+			throw new EE_Error(
88
+				sprintf(
89
+					__(
90
+						'You must register both "model_paths" AND "class_paths", not just one or the other You provided %s',
91
+						'event_espresso'
92
+					),
93
+					implode(", ", array_keys($config))
94
+				)
95
+			);
96
+		}
97
+		if (isset($config['model_paths'])) {
98
+			// make sure they passed in an array
99
+			if (! is_array($config['model_paths'])) {
100
+				$config['model_paths'] = [$config['model_paths']];
101
+			}
102
+			// we want to add this as a model folder
103
+			// and autoload them all
104
+			$class_to_filepath_map = EEH_File::get_contents_of_folders($config['model_paths']);
105
+			EEH_Autoloader::register_autoloader($class_to_filepath_map);
106
+			$model_name_to_classname_map = [];
107
+			foreach (array_keys($class_to_filepath_map) as $classname) {
108
+				$model_name_to_classname_map[ str_replace("EEM_", "", $classname) ] = $classname;
109
+			}
110
+			self::$_model_name_to_classname_map[ $model_id ] = $model_name_to_classname_map;
111
+			add_filter('FHEE__EE_System__parse_model_names', ['EE_Register_Model', 'add_addon_models']);
112
+			add_filter(
113
+				'FHEE__EE_System__parse_implemented_model_names',
114
+				['EE_Register_Model', 'add_addon_models']
115
+			);
116
+			add_filter('FHEE__EE_Registry__load_model__paths', ['EE_Register_Model', 'add_model_folders']);
117
+			unset($config['model_paths']);
118
+		}
119
+		if (isset($config['class_paths'])) {
120
+			// make sure they passed in an array
121
+			if (! is_array($config['class_paths'])) {
122
+				$config['class_paths'] = [$config['class_paths']];
123
+			}
124
+			$class_to_filepath_map = EEH_File::get_contents_of_folders($config['class_paths']);
125
+			EEH_Autoloader::register_autoloader($class_to_filepath_map);
126
+			add_filter('FHEE__EE_Registry__load_class__paths', ['EE_Register_Model', 'add_class_folders']);
127
+			unset($config['class_paths']);
128
+		}
129
+		foreach ($config as $unknown_key => $unknown_config) {
130
+			self::deregister($model_id);
131
+			throw new EE_Error(
132
+				sprintf(__("The key '%s' is not a known key for registering a model", "event_espresso"), $unknown_key)
133
+			);
134
+		}
135
+		return true;
136
+	}
137 137
 
138 138
 
139
-    /**
140
-     * Filters the core list of models
141
-     *
142
-     * @param array $core_models
143
-     * @return array keys are model names (eg 'Event') and values are their classes (eg 'EE_Event')
144
-     */
145
-    public static function add_addon_models($core_models = []): array
146
-    {
147
-        $models = [];
148
-        foreach (self::$_model_name_to_classname_map as $model_map) {
149
-            $models[] = $model_map;
150
-        }
151
-        return array_merge($core_models, ...$models);
152
-    }
139
+	/**
140
+	 * Filters the core list of models
141
+	 *
142
+	 * @param array $core_models
143
+	 * @return array keys are model names (eg 'Event') and values are their classes (eg 'EE_Event')
144
+	 */
145
+	public static function add_addon_models($core_models = []): array
146
+	{
147
+		$models = [];
148
+		foreach (self::$_model_name_to_classname_map as $model_map) {
149
+			$models[] = $model_map;
150
+		}
151
+		return array_merge($core_models, ...$models);
152
+	}
153 153
 
154 154
 
155
-    /**
156
-     * Filters the list of model folders
157
-     *
158
-     * @param array $folders
159
-     * @return array of folder paths
160
-     */
161
-    public static function add_model_folders(array $folders = []): array
162
-    {
163
-        $model_folders = [];
164
-        foreach (self::$_model_registry as $config) {
165
-            if (isset($config['model_paths'])) {
166
-                $model_folders[] = $config['model_paths'];
167
-            }
168
-        }
169
-        return array_merge($folders, ...$model_folders);
170
-    }
155
+	/**
156
+	 * Filters the list of model folders
157
+	 *
158
+	 * @param array $folders
159
+	 * @return array of folder paths
160
+	 */
161
+	public static function add_model_folders(array $folders = []): array
162
+	{
163
+		$model_folders = [];
164
+		foreach (self::$_model_registry as $config) {
165
+			if (isset($config['model_paths'])) {
166
+				$model_folders[] = $config['model_paths'];
167
+			}
168
+		}
169
+		return array_merge($folders, ...$model_folders);
170
+	}
171 171
 
172 172
 
173
-    /**
174
-     * Filters the array of model class paths
175
-     *
176
-     * @param array $folders
177
-     * @return array of folder paths
178
-     */
179
-    public static function add_class_folders(array $folders = []): array
180
-    {
181
-        $class_folders = [];
182
-        foreach (self::$_model_registry as $config) {
183
-            if (isset($config['class_paths'])) {
184
-                $class_folders[] = $config['class_paths'];
185
-            }
186
-        }
187
-        return array_merge($folders, ...$class_folders);
188
-    }
173
+	/**
174
+	 * Filters the array of model class paths
175
+	 *
176
+	 * @param array $folders
177
+	 * @return array of folder paths
178
+	 */
179
+	public static function add_class_folders(array $folders = []): array
180
+	{
181
+		$class_folders = [];
182
+		foreach (self::$_model_registry as $config) {
183
+			if (isset($config['class_paths'])) {
184
+				$class_folders[] = $config['class_paths'];
185
+			}
186
+		}
187
+		return array_merge($folders, ...$class_folders);
188
+	}
189 189
 
190 190
 
191
-    /**
192
-     * deregister
193
-     *
194
-     * @param string $model_id
195
-     */
196
-    public static function deregister(string $model_id = '')
197
-    {
198
-        if (isset(self::$_model_registry[ $model_id ])) {
199
-            unset(self::$_model_registry[ $model_id ]);
200
-            unset(self::$_model_name_to_classname_map[ $model_id ]);
201
-        }
202
-    }
191
+	/**
192
+	 * deregister
193
+	 *
194
+	 * @param string $model_id
195
+	 */
196
+	public static function deregister(string $model_id = '')
197
+	{
198
+		if (isset(self::$_model_registry[ $model_id ])) {
199
+			unset(self::$_model_registry[ $model_id ]);
200
+			unset(self::$_model_name_to_classname_map[ $model_id ]);
201
+		}
202
+	}
203 203
 }
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -59,11 +59,11 @@  discard block
 block discarded – undo
59 59
         }
60 60
 
61 61
         // make sure we don't register twice
62
-        if (isset(self::$_model_registry[ $model_id ])) {
62
+        if (isset(self::$_model_registry[$model_id])) {
63 63
             return true;
64 64
         }
65 65
 
66
-        if (! did_action('AHEE__EE_System__load_espresso_addons')
66
+        if ( ! did_action('AHEE__EE_System__load_espresso_addons')
67 67
             || did_action('FHEE__EE_System__parse_model_names')
68 68
             || did_action('FHEE__EE_System__parse_implemented_model_names')
69 69
         ) {
@@ -79,10 +79,10 @@  discard block
 block discarded – undo
79 79
                 '4.5'
80 80
             );
81 81
         }
82
-        self::$_model_registry[ $model_id ] = $config;
82
+        self::$_model_registry[$model_id] = $config;
83 83
 
84 84
         if ((isset($config['model_paths']) && ! isset($config['class_paths']))
85
-            || (! isset($config['model_paths']) && isset($config['class_paths']))
85
+            || ( ! isset($config['model_paths']) && isset($config['class_paths']))
86 86
         ) {
87 87
             throw new EE_Error(
88 88
                 sprintf(
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
         }
97 97
         if (isset($config['model_paths'])) {
98 98
             // make sure they passed in an array
99
-            if (! is_array($config['model_paths'])) {
99
+            if ( ! is_array($config['model_paths'])) {
100 100
                 $config['model_paths'] = [$config['model_paths']];
101 101
             }
102 102
             // we want to add this as a model folder
@@ -105,9 +105,9 @@  discard block
 block discarded – undo
105 105
             EEH_Autoloader::register_autoloader($class_to_filepath_map);
106 106
             $model_name_to_classname_map = [];
107 107
             foreach (array_keys($class_to_filepath_map) as $classname) {
108
-                $model_name_to_classname_map[ str_replace("EEM_", "", $classname) ] = $classname;
108
+                $model_name_to_classname_map[str_replace("EEM_", "", $classname)] = $classname;
109 109
             }
110
-            self::$_model_name_to_classname_map[ $model_id ] = $model_name_to_classname_map;
110
+            self::$_model_name_to_classname_map[$model_id] = $model_name_to_classname_map;
111 111
             add_filter('FHEE__EE_System__parse_model_names', ['EE_Register_Model', 'add_addon_models']);
112 112
             add_filter(
113 113
                 'FHEE__EE_System__parse_implemented_model_names',
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
         }
119 119
         if (isset($config['class_paths'])) {
120 120
             // make sure they passed in an array
121
-            if (! is_array($config['class_paths'])) {
121
+            if ( ! is_array($config['class_paths'])) {
122 122
                 $config['class_paths'] = [$config['class_paths']];
123 123
             }
124 124
             $class_to_filepath_map = EEH_File::get_contents_of_folders($config['class_paths']);
@@ -195,9 +195,9 @@  discard block
 block discarded – undo
195 195
      */
196 196
     public static function deregister(string $model_id = '')
197 197
     {
198
-        if (isset(self::$_model_registry[ $model_id ])) {
199
-            unset(self::$_model_registry[ $model_id ]);
200
-            unset(self::$_model_name_to_classname_map[ $model_id ]);
198
+        if (isset(self::$_model_registry[$model_id])) {
199
+            unset(self::$_model_registry[$model_id]);
200
+            unset(self::$_model_name_to_classname_map[$model_id]);
201 201
         }
202 202
     }
203 203
 }
Please login to merge, or discard this patch.