-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueue_Service_Provider.php
More file actions
74 lines (64 loc) · 1.72 KB
/
Copy pathQueue_Service_Provider.php
File metadata and controls
74 lines (64 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
/**
* Queue_Service_Provider class file.
*
* @package Mantle
*/
namespace Mantle\Queue;
use Mantle\Contracts\Queue\Queue_Manager as Queue_Manager_Contract;
use Mantle\Queue\Console\Cleanup_Jobs_Command;
use Mantle\Queue\Console\Run_Command;
use Mantle\Queue\Dispatcher;
use Mantle\Queue\Queue_Manager;
use Mantle\Queue\Worker;
use Mantle\Support\Service_Provider;
use function Mantle\Support\Helpers\tap;
/**
* Queue Service Provider
*/
class Queue_Service_Provider extends Service_Provider {
/**
* Register the service provider.
*/
public function register(): void {
$this->app->singleton_if(
'queue',
fn ( $app ) => tap(
// Register the Queue Manager with the supported providers when resolved.
new Queue_Manager( $app ),
$this->register_providers( ... ),
),
);
$this->app->singleton_if(
'queue.worker',
fn ( $app ) => new Worker( $app['queue'], $app['events'] ),
);
$this->app->singleton_if(
'queue.dispatcher',
fn ( $app ) => new Dispatcher( $app ),
);
// Register queue console commands.
$this->add_command( Cleanup_Jobs_Command::class );
$this->add_command( Run_Command::class );
// Register the queue service providers.
$this->app->register( Providers\WordPress\Service_Provider::class );
}
/**
* Boot the service provider.
*/
public function boot(): void {
$this->app->make( Queue_Manager_Contract::class );
}
/**
* Register Queue Providers
*
* Fire an event to allow other plugins to register queue providers.
*
* @param Queue_Manager_Contract $manager Queue Manager.
*/
protected function register_providers( Queue_Manager_Contract $manager ): void {
$this->app['events']->dispatch(
new Events\Providers_Registered( $manager ),
);
}
}