AmplitudeProvider.php
2 months ago
AssetsProvider.php
11 months ago
BlocksProvider.php
3 months ago
ClientProvider.php
2 months ago
ContainerProvider.php
11 months ago
DatabaseProvider.php
8 months ago
HostingRoutesProvider.php
2 months ago
IntegrationsProvider.php
5 months ago
JobsProvider.php
7 months ago
MenusProvider.php
11 months ago
NoticesProvider.php
4 months ago
ProviderInterface.php
11 months ago
RedirectsProvider.php
11 months ago
RoutesProvider.php
9 months ago
SurveysProvider.php
2 months ago
TrackingProvider.php
8 months ago
WebhooksProvider.php
8 months ago
WpdbProvider.php
11 months ago
JobsProvider.php
69 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Hostinger\Reach\Providers; |
| 4 | |
| 5 | use Hostinger\Reach\Api\Handlers\ReachApiHandler; |
| 6 | use Hostinger\Reach\Api\Webhooks\Handlers\CartAbandoned; |
| 7 | use Hostinger\Reach\Container; |
| 8 | use Hostinger\Reach\Integrations\ImportManager; |
| 9 | use Hostinger\Reach\Jobs\AbandonedCartsJob; |
| 10 | use Hostinger\Reach\Jobs\ActionScheduler; |
| 11 | use Hostinger\Reach\Jobs\ImportJob; |
| 12 | use Hostinger\Reach\Jobs\CleanupCartsJob; |
| 13 | use Hostinger\Reach\Repositories\CartRepository; |
| 14 | |
| 15 | if ( ! defined( 'ABSPATH' ) ) { |
| 16 | die; |
| 17 | } |
| 18 | |
| 19 | class JobsProvider implements ProviderInterface { |
| 20 | |
| 21 | public function register( Container $container ): void { |
| 22 | $action_scheduler = new ActionScheduler(); |
| 23 | $container->set( |
| 24 | ActionScheduler::class, |
| 25 | function () use ( $action_scheduler ) { |
| 26 | return $action_scheduler; |
| 27 | } |
| 28 | ); |
| 29 | |
| 30 | $jobs = array( |
| 31 | AbandonedCartsJob::class => array( |
| 32 | $container->get( ActionScheduler::class ), |
| 33 | $container->get( ReachApiHandler::class ), |
| 34 | $container->get( CartRepository::class ), |
| 35 | $container->get( CartAbandoned::class ), |
| 36 | ), |
| 37 | ImportJob::class => array( |
| 38 | $container->get( ActionScheduler::class ), |
| 39 | $container->get( ReachApiHandler::class ), |
| 40 | $container->get( ImportManager::class ), |
| 41 | ), |
| 42 | CleanupCartsJob::class => array( |
| 43 | $container->get( ActionScheduler::class ), |
| 44 | $container->get( ReachApiHandler::class ), |
| 45 | $container->get( CartRepository::class ), |
| 46 | ), |
| 47 | ); |
| 48 | |
| 49 | foreach ( $jobs as $class_name => $dependencies ) { |
| 50 | $job = new $class_name( ...$dependencies ); |
| 51 | $container->set( |
| 52 | $job::class, |
| 53 | function () use ( $job ) { |
| 54 | return $job; |
| 55 | } |
| 56 | ); |
| 57 | |
| 58 | $job = $container->get( $job::class ); |
| 59 | add_action( |
| 60 | 'init', |
| 61 | function () use ( $job ): void { |
| 62 | $job->init(); |
| 63 | } |
| 64 | ); |
| 65 | |
| 66 | } |
| 67 | } |
| 68 | } |
| 69 |