PluginProbe
ووسلام – همگام سازی ووکامرس و باسلام / 1.10.18
ووسلام – همگام سازی ووکامرس و باسلام v1.10.18
1.10.18 1.10.17 1.10.15 1.10.14 1.10.13 1.10.12 1.10.10 1.10.9 1.10.8 1.10.7 1.10.6 1.10.5 1.10.4 1.10.3 1.10.2 1.10.1 1.10.0 1.9.2 1.9.1 1.9.0 1.8.8 1.8.5 1.8.6 1.8.7 1.8.4 All 51 releases
sync-basalam / includes / Jobs / JobRegistry.php

JobRegistry.php in ووسلام – همگام سازی ووکامرس و باسلام 1.10.18, at includes/Jobs/JobRegistry.php

69 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace SyncBasalam\Jobs;
4
5 use SyncBasalam\Jobs\Types\BulkUpdateProductsJob;
6 use SyncBasalam\Jobs\Types\UpdateAllProductsJob;
7 use SyncBasalam\Jobs\Types\UpdateSingleProductJob;
8 use SyncBasalam\Jobs\Types\CreateSingleProductJob;
9 use SyncBasalam\Jobs\Types\CreateAllProductsJob;
10 use SyncBasalam\Jobs\Types\AutoConnectProductsJob;
11 use SyncBasalam\Jobs\Types\FetchOrdersJob;
12
13 defined('ABSPATH') || exit;
14
15 class JobRegistry
16 {
17 private $jobTypes = [];
18
19 public function __construct(array $jobTypes = [])
20 {
21 if (empty($jobTypes)) {
22 $this->registerDefaultJobs();
23 return;
24 }
25
26 foreach ($jobTypes as $jobType) {
27 if ($jobType instanceof JobType) {
28 $this->register($jobType);
29 }
30 }
31 }
32
33 private function registerDefaultJobs(): void
34 {
35 $container = syncBasalamContainer();
36 $this->register($container->get(BulkUpdateProductsJob::class));
37 $this->register($container->get(UpdateAllProductsJob::class));
38 $this->register($container->get(UpdateSingleProductJob::class));
39 $this->register($container->get(CreateSingleProductJob::class));
40 $this->register($container->get(CreateAllProductsJob::class));
41 $this->register($container->get(AutoConnectProductsJob::class));
42 $this->register($container->get(FetchOrdersJob::class));
43 }
44
45 public function register(JobType $jobType): void
46 {
47 $this->jobTypes[$jobType->getType()] = $jobType;
48 }
49
50 public function get(string $type): ?JobType
51 {
52 return $this->jobTypes[$type] ?? null;
53 }
54
55 public function getAll(): array
56 {
57 return $this->jobTypes;
58 }
59
60 public function getSortedByPriority(): array
61 {
62 $jobTypes = $this->jobTypes;
63 uasort($jobTypes, function (JobType $a, JobType $b) {
64 return $a->getPriority() <=> $b->getPriority();
65 });
66 return $jobTypes;
67 }
68 }
69