22
33namespace Enqueue \LaravelQueue ;
44
5+ use Enqueue \LaravelQueue \Command \ConsumeMessagesCommand ;
6+ use Enqueue \LaravelQueue \Command \ProduceMessageCommand ;
7+ use Enqueue \LaravelQueue \Command \QueuesCommand ;
8+ use Enqueue \LaravelQueue \Command \SetupBrokerCommand ;
9+ use Enqueue \LaravelQueue \Command \TopicsCommand ;
10+ use Enqueue \SimpleClient \SimpleClient ;
511use Illuminate \Queue \QueueManager ;
612use Illuminate \Support \ServiceProvider ;
713
@@ -12,18 +18,53 @@ class EnqueueServiceProvider extends ServiceProvider
1218 */
1319 public function boot ()
1420 {
15- /** @var QueueManager $manager */
16- $ manager = $ this ->app ['queue ' ];
17-
18- $ manager ->addConnector ('interop ' , function () {
19- return new Connector ();
20- });
21+ $ this ->bootInteropQueueDriver ();
2122 }
2223
2324 /**
2425 * {@inheritdoc}
2526 */
2627 public function register ()
2728 {
29+ $ this ->registerClient ();
30+ }
31+
32+ private function registerClient ()
33+ {
34+ if (false == $ this ->app ['config ' ]->has ('enqueue.client ' )) {
35+ return ;
36+ }
37+
38+ if (false == class_exists (SimpleClient::class)) {
39+ throw new \LogicException ('The enqueue/simple-client package is not installed ' );
40+ }
41+
42+ $ this ->app ->singleton (SimpleClient::class, function () {
43+ /** @var \Illuminate\Config\Repository $config */
44+ $ config = $ this ->app ['config ' ];
45+
46+ var_dump ($ config ->get ('enqueue.client ' ));
47+ return new SimpleClient ($ config ->get ('enqueue.client ' ));
48+ });
49+
50+ if ($ this ->app ->runningInConsole ()) {
51+ $ this ->commands ([
52+ SetupBrokerCommand::class,
53+ ProduceMessageCommand::class,
54+ QueuesCommand::class,
55+ TopicsCommand::class,
56+ ConsumeMessagesCommand::class,
57+ ]);
58+ }
59+ }
60+
61+ private function bootInteropQueueDriver ()
62+ {
63+ /** @var QueueManager $manager */
64+ $ manager = $ this ->app ['queue ' ];
65+
66+ $ manager ->addConnector ('interop ' , function () {
67+ return new Connector ();
68+ });
2869 }
2970}
0 commit comments