From b694221219537494e35ef61b3c8fa28d0d84bac2 Mon Sep 17 00:00:00 2001 From: ITBM <22393016+itbm@users.noreply.github.com> Date: Tue, 28 Nov 2017 12:03:36 +0000 Subject: [PATCH 1/2] ADD: Lumen support --- src/PubSubBaseServiceProvider.php | 99 ++++++++++++++++++++++++++++ src/PubSubLaravelServiceProvider.php | 19 ++++++ src/PubSubLumenManager.php | 19 ++++++ src/PubSubLumenServiceProvider.php | 26 ++++++++ src/PubSubServiceProvider.php | 99 +--------------------------- 5 files changed, 165 insertions(+), 97 deletions(-) create mode 100644 src/PubSubBaseServiceProvider.php create mode 100644 src/PubSubLaravelServiceProvider.php create mode 100644 src/PubSubLumenManager.php create mode 100644 src/PubSubLumenServiceProvider.php diff --git a/src/PubSubBaseServiceProvider.php b/src/PubSubBaseServiceProvider.php new file mode 100644 index 0000000..474d796 --- /dev/null +++ b/src/PubSubBaseServiceProvider.php @@ -0,0 +1,99 @@ +publishes([ + __DIR__ . '/../config/pubsub.php' => config_path('pubsub.php'), + ]); + } + + /** + * Register bindings in the container. + */ + public function register() + { + $this->mergeConfigFrom(__DIR__ . '/../config/pubsub.php', 'pubsub'); + + $this->app->singleton('pubsub.factory', function ($app) { + return new PubSubConnectionFactory($app); + }); + + $this->app->bind('pubsub.connection', PubSubAdapterInterface::class); + + $this->app->bind(PubSubAdapterInterface::class, function ($app) { + $manager = $app['pubsub']; /* @var PubSubManager $manager */ + return $manager->connection(); + }); + + $this->registerAdapterDependencies(); + + $this->commands(SubscriberMakeCommand::class); + } + + /** + * Register adapter dependencies in the container. + */ + protected function registerAdapterDependencies() + { + $this->app->bind('pubsub.redis.redis_client', function ($app, $parameters) { + return new RedisClient($parameters['config']); + }); + + $this->app->bind('pubsub.gcloud.pub_sub_client', function ($app, $parameters) { + return new GoogleCloudPubSubClient($parameters['config']); + }); + + $this->app->bind('pubsub.kafka.topic_conf', function () { + return new \RdKafka\TopicConf(); + }); + + $this->app->bind('pubsub.kafka.producer', function () { + return new \RdKafka\Producer(); + }); + + $this->app->bind('pubsub.kafka.conf', function () { + return new \RdKafka\Conf(); + }); + + $this->app->bind('pubsub.kafka.consumer', function ($app, $parameters) { + return new \RdKafka\KafkaConsumer($parameters['conf']); + }); + + $this->app->bind('pubsub.http.client', function () { + return new Client(); + }); + } + + /** + * Get the services provided by the provider. + * + * @return array + */ + public function provides() + { + return [ + 'pubsub', + 'pubsub.factory', + 'pubsub.connection', + 'pubsub.redis.redis_client', + 'pubsub.gcloud.pub_sub_client', + 'pubsub.kafka.topic_conf', + 'pubsub.kafka.producer', + 'pubsub.kafka.consumer', + 'pubsub.http.client', + ]; + } +} diff --git a/src/PubSubLaravelServiceProvider.php b/src/PubSubLaravelServiceProvider.php new file mode 100644 index 0000000..7b30136 --- /dev/null +++ b/src/PubSubLaravelServiceProvider.php @@ -0,0 +1,19 @@ +app->singleton('pubsub', function ($app) { + return new PubSubManager($app, $app['pubsub.factory']); + }); + } +} diff --git a/src/PubSubLumenManager.php b/src/PubSubLumenManager.php new file mode 100644 index 0000000..075c478 --- /dev/null +++ b/src/PubSubLumenManager.php @@ -0,0 +1,19 @@ +app = $app; + $this->factory = $factory; + } +} diff --git a/src/PubSubLumenServiceProvider.php b/src/PubSubLumenServiceProvider.php new file mode 100644 index 0000000..39eb2de --- /dev/null +++ b/src/PubSubLumenServiceProvider.php @@ -0,0 +1,26 @@ +app->configure('pubsub'); + } + + /** + * Register bindings in the container. + */ + public function register() + { + Parent::register(); + + $this->app->singleton('pubsub', function ($app) { + return new PubSubLumenManager($app, $app['pubsub.factory']); + }); + } +} diff --git a/src/PubSubServiceProvider.php b/src/PubSubServiceProvider.php index 2058b9b..6ae1d58 100644 --- a/src/PubSubServiceProvider.php +++ b/src/PubSubServiceProvider.php @@ -2,102 +2,7 @@ namespace Superbalist\LaravelPubSub; -use Google\Cloud\PubSub\PubSubClient as GoogleCloudPubSubClient; -use GuzzleHttp\Client; -use Illuminate\Support\ServiceProvider; -use Predis\Client as RedisClient; -use Superbalist\PubSub\PubSubAdapterInterface; - -class PubSubServiceProvider extends ServiceProvider +class PubSubServiceProvider extends PubSubLaravelServiceProvider { - /** - * Perform post-registration booting of services. - */ - public function boot() - { - $this->publishes([ - __DIR__ . '/../config/pubsub.php' => config_path('pubsub.php'), - ]); - } - - /** - * Register bindings in the container. - */ - public function register() - { - $this->mergeConfigFrom(__DIR__ . '/../config/pubsub.php', 'pubsub'); - - $this->app->singleton('pubsub.factory', function ($app) { - return new PubSubConnectionFactory($app); - }); - - $this->app->singleton('pubsub', function ($app) { - return new PubSubManager($app, $app['pubsub.factory']); - }); - - $this->app->bind('pubsub.connection', PubSubAdapterInterface::class); - - $this->app->bind(PubSubAdapterInterface::class, function ($app) { - $manager = $app['pubsub']; /* @var PubSubManager $manager */ - return $manager->connection(); - }); - - $this->registerAdapterDependencies(); - - $this->commands(SubscriberMakeCommand::class); - } - - /** - * Register adapter dependencies in the container. - */ - protected function registerAdapterDependencies() - { - $this->app->bind('pubsub.redis.redis_client', function ($app, $parameters) { - return new RedisClient($parameters['config']); - }); - - $this->app->bind('pubsub.gcloud.pub_sub_client', function ($app, $parameters) { - return new GoogleCloudPubSubClient($parameters['config']); - }); - - $this->app->bind('pubsub.kafka.topic_conf', function () { - return new \RdKafka\TopicConf(); - }); - - $this->app->bind('pubsub.kafka.producer', function () { - return new \RdKafka\Producer(); - }); - - $this->app->bind('pubsub.kafka.conf', function () { - return new \RdKafka\Conf(); - }); - - $this->app->bind('pubsub.kafka.consumer', function ($app, $parameters) { - return new \RdKafka\KafkaConsumer($parameters['conf']); - }); - - $this->app->bind('pubsub.http.client', function () { - return new Client(); - }); - } - - /** - * Get the services provided by the provider. - * - * @return array - */ - public function provides() - { - return [ - 'pubsub', - 'pubsub.factory', - 'pubsub.connection', - 'pubsub.redis.redis_client', - 'pubsub.gcloud.pub_sub_client', - 'pubsub.kafka.topic_conf', - 'pubsub.kafka.producer', - 'pubsub.kafka.consumer', - 'pubsub.http.client', - ]; - } + // kept for backwards compatibility } From 5611de822124db4238ea51a730236c106d6635c7 Mon Sep 17 00:00:00 2001 From: ITBM <22393016+itbm@users.noreply.github.com> Date: Thu, 30 Nov 2017 09:07:43 +0000 Subject: [PATCH 2/2] CHG: Update readme & changelog --- README.md | 49 ++++++++++++++++++++++++++++++++++++++++--------- changelog.md | 4 ++++ 2 files changed, 44 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 9029d20..1815ca9 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # laravel-pubsub -A Pub-Sub abstraction for Laravel. +A Pub-Sub abstraction for Laravel and Lumen. [![Author](http://img.shields.io/badge/author-@superbalist-blue.svg?style=flat-square)](https://twitter.com/superbalist) [![Build Status](https://img.shields.io/travis/Superbalist/laravel-pubsub/master.svg?style=flat-square)](https://travis-ci.org/Superbalist/laravel-pubsub) @@ -9,7 +9,7 @@ A Pub-Sub abstraction for Laravel. [![Packagist Version](https://img.shields.io/packagist/v/superbalist/laravel-pubsub.svg?style=flat-square)](https://packagist.org/packages/superbalist/laravel-pubsub) [![Total Downloads](https://img.shields.io/packagist/dt/superbalist/laravel-pubsub.svg?style=flat-square)](https://packagist.org/packages/superbalist/laravel-pubsub) -This package is a wrapper bridging [php-pubsub](https://github.com/Superbalist/php-pubsub) into Laravel. +This package is a wrapper bridging [php-pubsub](https://github.com/Superbalist/php-pubsub) into Laravel and Lumen. For **Laravel 4** support, use the package https://github.com/Superbalist/laravel4-pubsub @@ -17,6 +17,8 @@ Please note that **Laravel 5.3** is only supported up until version 2.0.2. 2.0.3+ supports **Laravel 5.4 and up** moving forward. +3.0.1+ supports **Lumen 5.5 and up** moving forward. + The following adapters are supported: * Local * /dev/null @@ -25,7 +27,7 @@ The following adapters are supported: * Google Cloud * HTTP -## Installation +## Laravel Installation ```bash composer require superbalist/laravel-pubsub @@ -35,7 +37,7 @@ Register the service provider in app.php ```php 'providers' => [ // ... - Superbalist\LaravelPubSub\PubSubServiceProvider::class, + Superbalist\LaravelPubSub\PubSubLaravelServiceProvider::class, ] ``` @@ -47,6 +49,40 @@ Register the facade in app.php ] ``` +To customize the configuration file, publish the package configuration using Artisan. +```bash +php artisan vendor:publish --provider="Superbalist\LaravelPubSub\PubSubLaravelServiceProvider" +``` + +You can then edit the generated config at `app/config/pubsub.php`. + +## Lumen Installation + +```bash +composer require superbalist/laravel-pubsub +``` + +Register the service provider in app.php +```php +$app->register(Superbalist\LaravelPubSub\PubSubLumenServiceProvider::class); +``` + +Register the facade in app.php +```php +if (!class_exists('PubSub')) { + class_alias('Superbalist\LaravelPubSub\PubSubFacade', 'PubSub'); +} +``` + +To customize the configuration file, copy the package configuration. +```bash +cp vendor/superbalist/laravel-pubsub/config/pubsub.php config/pubsub.php +``` + +You can then edit the generated config at `config/pubsub.php`. + +## Configuration + The package has a default configuration which uses the following environment variables. ``` PUBSUB_CONNECTION=redis @@ -64,12 +100,7 @@ HTTP_PUBSUB_URI=null HTTP_PUBSUB_SUBSCRIBE_CONNECTION=redis ``` -To customize the configuration file, publish the package configuration using Artisan. -```bash -php artisan vendor:publish --provider="Superbalist\LaravelPubSub\PubSubServiceProvider" -``` -You can then edit the generated config at `app/config/pubsub.php`. ## Kafka Adapter Installation diff --git a/changelog.md b/changelog.md index 7d84fdd..2564b74 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,9 @@ # Changelog +## 3.0.1 - 2017-12-01 + +* Added Lumen support + ## 3.0.0 - 2017-07-25 * Bump up to superbalist/php-pubsub-google-cloud ^5.0 which allows for background daemon support