PluginProbe
AliNext – WooCommerce Dropshipping Plugin for AliExpress / trunk
AliNext – WooCommerce Dropshipping Plugin for AliExpress vtrunk
ali2woo-lite / includes / classes / factory / BackgroundProcessFactory.php

BackgroundProcessFactory.php in AliNext – WooCommerce Dropshipping Plugin for AliExpress trunk, at includes/classes/factory/BackgroundProcessFactory.php

75 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Description of ProcessFactory
4 *
5 * @author Ali2Woo Team
6 *
7 */
8 // phpcs:ignoreFile WordPress.Security.EscapeOutput.OutputNotEscaped
9 namespace AliNext_Lite;;
10
11 use Exception;
12 use DI\Container;
13 use Throwable;
14
15 class BackgroundProcessFactory
16 {
17 public function __construct(
18 protected Container $Container
19 ){}
20
21 /**
22 * @param string $actionCode
23 * @return ImportJobInterface
24 * @throws Exception
25 */
26 public function createProcessByCode(string $actionCode): BaseJobInterface
27 {
28 if ($actionCode == ApplyPricingRulesProcess::ACTION_CODE) {
29 return new ApplyPricingRulesProcess();
30 }
31
32 if ($actionCode == ImportProcess::ACTION_CODE) {
33 return new ImportProcess();
34 }
35
36 if ($actionCode == AddProductToImportListProcess::ACTION_CODE) {
37 return $this->Container->get(AddProductToImportListProcess::class);
38 }
39
40 if ($actionCode == AffiliateCheckProcess::ACTION_CODE) {
41 return $this->Container->get(AffiliateCheckProcess::class);
42 }
43
44 if ($actionCode == MigrateAlicdnUrlProcess::ACTION_CODE) {
45 return $this->Container->get(MigrateAlicdnUrlProcess::class);
46 }
47
48
49
50 throw new Exception('Unknown process given: ' . $actionCode);
51 }
52
53 public function getAll(): array
54 {
55 $codes = [
56 ApplyPricingRulesProcess::ACTION_CODE,
57 ImportProcess::ACTION_CODE,
58 AddProductToImportListProcess::ACTION_CODE,
59 AffiliateCheckProcess::ACTION_CODE,
60
61 ];
62
63 $jobs = [];
64
65 foreach ($codes as $code) {
66 try {
67 $jobs[] = $this->createProcessByCode($code);
68 } catch (Throwable $e) {
69 a2wl_info_log("[BackgroundProcessFactory] Failed to resolve '{$code}': " . $e->getMessage());
70 }
71 }
72
73 return $jobs;
74 }
75 }