Skip to content
This repository was archived by the owner on Jul 19, 2024. It is now read-only.

Commit b694221

Browse files
committed
ADD: Lumen support
1 parent 194e079 commit b694221

File tree

5 files changed

+165
-97
lines changed

5 files changed

+165
-97
lines changed

src/PubSubBaseServiceProvider.php

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<?php
2+
3+
namespace Superbalist\LaravelPubSub;
4+
5+
use Google\Cloud\PubSub\PubSubClient as GoogleCloudPubSubClient;
6+
use GuzzleHttp\Client;
7+
use Illuminate\Support\ServiceProvider;
8+
use Predis\Client as RedisClient;
9+
use Superbalist\PubSub\PubSubAdapterInterface;
10+
11+
class PubSubBaseServiceProvider extends ServiceProvider
12+
{
13+
/**
14+
* Perform post-registration booting of services.
15+
*/
16+
public function boot()
17+
{
18+
$this->publishes([
19+
__DIR__ . '/../config/pubsub.php' => config_path('pubsub.php'),
20+
]);
21+
}
22+
23+
/**
24+
* Register bindings in the container.
25+
*/
26+
public function register()
27+
{
28+
$this->mergeConfigFrom(__DIR__ . '/../config/pubsub.php', 'pubsub');
29+
30+
$this->app->singleton('pubsub.factory', function ($app) {
31+
return new PubSubConnectionFactory($app);
32+
});
33+
34+
$this->app->bind('pubsub.connection', PubSubAdapterInterface::class);
35+
36+
$this->app->bind(PubSubAdapterInterface::class, function ($app) {
37+
$manager = $app['pubsub']; /* @var PubSubManager $manager */
38+
return $manager->connection();
39+
});
40+
41+
$this->registerAdapterDependencies();
42+
43+
$this->commands(SubscriberMakeCommand::class);
44+
}
45+
46+
/**
47+
* Register adapter dependencies in the container.
48+
*/
49+
protected function registerAdapterDependencies()
50+
{
51+
$this->app->bind('pubsub.redis.redis_client', function ($app, $parameters) {
52+
return new RedisClient($parameters['config']);
53+
});
54+
55+
$this->app->bind('pubsub.gcloud.pub_sub_client', function ($app, $parameters) {
56+
return new GoogleCloudPubSubClient($parameters['config']);
57+
});
58+
59+
$this->app->bind('pubsub.kafka.topic_conf', function () {
60+
return new \RdKafka\TopicConf();
61+
});
62+
63+
$this->app->bind('pubsub.kafka.producer', function () {
64+
return new \RdKafka\Producer();
65+
});
66+
67+
$this->app->bind('pubsub.kafka.conf', function () {
68+
return new \RdKafka\Conf();
69+
});
70+
71+
$this->app->bind('pubsub.kafka.consumer', function ($app, $parameters) {
72+
return new \RdKafka\KafkaConsumer($parameters['conf']);
73+
});
74+
75+
$this->app->bind('pubsub.http.client', function () {
76+
return new Client();
77+
});
78+
}
79+
80+
/**
81+
* Get the services provided by the provider.
82+
*
83+
* @return array
84+
*/
85+
public function provides()
86+
{
87+
return [
88+
'pubsub',
89+
'pubsub.factory',
90+
'pubsub.connection',
91+
'pubsub.redis.redis_client',
92+
'pubsub.gcloud.pub_sub_client',
93+
'pubsub.kafka.topic_conf',
94+
'pubsub.kafka.producer',
95+
'pubsub.kafka.consumer',
96+
'pubsub.http.client',
97+
];
98+
}
99+
}

src/PubSubLaravelServiceProvider.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace Superbalist\LaravelPubSub;
4+
5+
class PubSubLaravelServiceProvider extends PubSubBaseServiceProvider
6+
{
7+
8+
/**
9+
* Register bindings in the container.
10+
*/
11+
public function register()
12+
{
13+
Parent::register();
14+
15+
$this->app->singleton('pubsub', function ($app) {
16+
return new PubSubManager($app, $app['pubsub.factory']);
17+
});
18+
}
19+
}

src/PubSubLumenManager.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace Superbalist\LaravelPubSub;
4+
5+
use Laravel\Lumen\Application;
6+
7+
class PubSubLumenManager extends PubSubManager
8+
{
9+
10+
/**
11+
* @param Application $app
12+
* @param PubSubConnectionFactory $factory
13+
*/
14+
public function __construct(Application $app, PubSubConnectionFactory $factory)
15+
{
16+
$this->app = $app;
17+
$this->factory = $factory;
18+
}
19+
}

src/PubSubLumenServiceProvider.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace Superbalist\LaravelPubSub;
4+
5+
class PubSubLumenServiceProvider extends PubSubBaseServiceProvider
6+
{
7+
/**
8+
* Perform post-registration booting of services.
9+
*/
10+
public function boot()
11+
{
12+
$this->app->configure('pubsub');
13+
}
14+
15+
/**
16+
* Register bindings in the container.
17+
*/
18+
public function register()
19+
{
20+
Parent::register();
21+
22+
$this->app->singleton('pubsub', function ($app) {
23+
return new PubSubLumenManager($app, $app['pubsub.factory']);
24+
});
25+
}
26+
}

src/PubSubServiceProvider.php

Lines changed: 2 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -2,102 +2,7 @@
22

33
namespace Superbalist\LaravelPubSub;
44

5-
use Google\Cloud\PubSub\PubSubClient as GoogleCloudPubSubClient;
6-
use GuzzleHttp\Client;
7-
use Illuminate\Support\ServiceProvider;
8-
use Predis\Client as RedisClient;
9-
use Superbalist\PubSub\PubSubAdapterInterface;
10-
11-
class PubSubServiceProvider extends ServiceProvider
5+
class PubSubServiceProvider extends PubSubLaravelServiceProvider
126
{
13-
/**
14-
* Perform post-registration booting of services.
15-
*/
16-
public function boot()
17-
{
18-
$this->publishes([
19-
__DIR__ . '/../config/pubsub.php' => config_path('pubsub.php'),
20-
]);
21-
}
22-
23-
/**
24-
* Register bindings in the container.
25-
*/
26-
public function register()
27-
{
28-
$this->mergeConfigFrom(__DIR__ . '/../config/pubsub.php', 'pubsub');
29-
30-
$this->app->singleton('pubsub.factory', function ($app) {
31-
return new PubSubConnectionFactory($app);
32-
});
33-
34-
$this->app->singleton('pubsub', function ($app) {
35-
return new PubSubManager($app, $app['pubsub.factory']);
36-
});
37-
38-
$this->app->bind('pubsub.connection', PubSubAdapterInterface::class);
39-
40-
$this->app->bind(PubSubAdapterInterface::class, function ($app) {
41-
$manager = $app['pubsub']; /* @var PubSubManager $manager */
42-
return $manager->connection();
43-
});
44-
45-
$this->registerAdapterDependencies();
46-
47-
$this->commands(SubscriberMakeCommand::class);
48-
}
49-
50-
/**
51-
* Register adapter dependencies in the container.
52-
*/
53-
protected function registerAdapterDependencies()
54-
{
55-
$this->app->bind('pubsub.redis.redis_client', function ($app, $parameters) {
56-
return new RedisClient($parameters['config']);
57-
});
58-
59-
$this->app->bind('pubsub.gcloud.pub_sub_client', function ($app, $parameters) {
60-
return new GoogleCloudPubSubClient($parameters['config']);
61-
});
62-
63-
$this->app->bind('pubsub.kafka.topic_conf', function () {
64-
return new \RdKafka\TopicConf();
65-
});
66-
67-
$this->app->bind('pubsub.kafka.producer', function () {
68-
return new \RdKafka\Producer();
69-
});
70-
71-
$this->app->bind('pubsub.kafka.conf', function () {
72-
return new \RdKafka\Conf();
73-
});
74-
75-
$this->app->bind('pubsub.kafka.consumer', function ($app, $parameters) {
76-
return new \RdKafka\KafkaConsumer($parameters['conf']);
77-
});
78-
79-
$this->app->bind('pubsub.http.client', function () {
80-
return new Client();
81-
});
82-
}
83-
84-
/**
85-
* Get the services provided by the provider.
86-
*
87-
* @return array
88-
*/
89-
public function provides()
90-
{
91-
return [
92-
'pubsub',
93-
'pubsub.factory',
94-
'pubsub.connection',
95-
'pubsub.redis.redis_client',
96-
'pubsub.gcloud.pub_sub_client',
97-
'pubsub.kafka.topic_conf',
98-
'pubsub.kafka.producer',
99-
'pubsub.kafka.consumer',
100-
'pubsub.http.client',
101-
];
102-
}
7+
// kept for backwards compatibility
1038
}

0 commit comments

Comments
 (0)