From 4218c7360bfed05ec5e21b335869a89a0dd21ea5 Mon Sep 17 00:00:00 2001 From: jygaulier Date: Thu, 12 Apr 2018 16:56:16 +0200 Subject: [PATCH] Silex2 (#7) silex2 --- composer.json | 15 +++-- src/WorkerProvider/WorkerServiceProvider.php | 62 ++++++++------------ 2 files changed, 37 insertions(+), 40 deletions(-) diff --git a/composer.json b/composer.json index 919886a..96d56d7 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,13 @@ { "name": "alchemy/worker-bundle", "description": "Symfony bundle for alchemy/worker-component", + "repositories": [ + { + "packagist.org": false, + "type": "vcs", + "url": "https://github.com/alchemy-fr/queue-bundle" + } + ], "authors": [ { "name": "Thibaud Fabre", @@ -21,14 +28,14 @@ }, "license": "MIT", "require-dev": { - "silex/silex": "^1.3.0", + "silex/silex": "~2.0", "symfony/symfony": "^2.8", - "phpunit/phpunit": "^5.4" + "phpunit/phpunit": "~6.0" }, "require": { "alchemy/worker-component": "^0.1.0", - "alchemy/queue-bundle": "^0.1.5", - "php": ">=5.5" + "alchemy/queue-bundle": "~4.1", + "php": "~7.0" }, "extra": { "branch-alias": { diff --git a/src/WorkerProvider/WorkerServiceProvider.php b/src/WorkerProvider/WorkerServiceProvider.php index 2a2760e..483f2d3 100644 --- a/src/WorkerProvider/WorkerServiceProvider.php +++ b/src/WorkerProvider/WorkerServiceProvider.php @@ -11,8 +11,10 @@ use Alchemy\WorkerBundle\Commands\InvokeWorkerCommand; use Alchemy\WorkerBundle\Commands\ShowQueueConfigurationCommand; use Psr\Log\LoggerAwareInterface; +use Pimple\Container; +use Pimple\ServiceProviderInterface; use Silex\Application; -use Silex\ServiceProviderInterface; + class WorkerServiceProvider implements ServiceProviderInterface { @@ -23,66 +25,66 @@ class WorkerServiceProvider implements ServiceProviderInterface * This method should only be used to configure services and parameters. * It should not get services. */ - public function register(Application $app) + public function register(Container $app) { $this->registerDefaultParameters($app); - $loggerSetter = function (LoggerAwareInterface $loggerAware) use ($app) { + $loggerSetter = $app->factory(function (LoggerAwareInterface $loggerAware) use ($app) { if (isset($app[$app['alchemy_worker.logger_service_name']])) { $loggerAware->setLogger($app[$app['alchemy_worker.logger_service_name']]); } return $loggerAware; - }; + }); - $app['alchemy_worker.process_pool'] = $app->share(function (Application $app) use ($loggerSetter) { + $app['alchemy_worker.process_pool'] = function (Application $app) use ($loggerSetter) { return $loggerSetter(new ProcessPool($app['alchemy_worker.process_pool_size'])); - }); + }; - $app['alchemy_worker.worker_invoker'] = $app->share(function (Application $app) use ($loggerSetter) { + $app['alchemy_worker.worker_invoker'] = function (Application $app) use ($loggerSetter) { return $loggerSetter(new WorkerInvoker($app['alchemy_worker.process_pool'])); - }); + }; - $app['alchemy_worker.queue_registry'] = $app->share(function () use ($loggerSetter) { + $app['alchemy_worker.queue_registry'] = function () use ($loggerSetter) { return $loggerSetter(new MessageQueueRegistry()); - }); + }; - $app['alchemy_worker.message_dispatcher'] = $app->share(function (Application $app) use ($loggerSetter) { + $app['alchemy_worker.message_dispatcher'] = function (Application $app) use ($loggerSetter) { return $loggerSetter(new MessageDispatcher( $app['alchemy_worker.worker_invoker'], $app['alchemy_worker.queue_registry'], $app['alchemy_worker.queue_name'] )); - }); + }; - $app['alchemy_worker.type_based_worker_resolver'] = $app->share(function () { + $app['alchemy_worker.type_based_worker_resolver'] = function () { return new TypeBasedWorkerResolver(); - }); + }; - $app['alchemy_worker.worker_resolver'] = $app->share(function (Application $app) { + $app['alchemy_worker.worker_resolver'] = function (Application $app) { return $app['alchemy_worker.type_based_worker_resolver']; - }); + }; - $app['alchemy_worker.commands.run_dispatcher_command'] = $app->share(function (Application $app) { + $app['alchemy_worker.commands.run_dispatcher_command'] = function (Application $app) { return new DispatchingConsumerCommand( $app['alchemy_worker.message_dispatcher'], $app['alchemy_worker.worker_invoker'] ); - }); + }; - $app['alchemy_worker.commands.run_worker_command'] = $app->share(function (Application $app) { + $app['alchemy_worker.commands.run_worker_command'] = function (Application $app) { return new InvokeWorkerCommand($app['alchemy_worker.worker_resolver']); - }); + }; - $app['alchemy_worker.commands.show_configuration'] = $app->share(function (Application $app) { + $app['alchemy_worker.commands.show_configuration'] = function (Application $app) { return new ShowQueueConfigurationCommand($app['alchemy_worker.queue_registry']); - }); + }; } /** - * @param Application $app + * @param Container $app */ - protected function registerDefaultParameters(Application $app) + protected function registerDefaultParameters(Container $app) { if (!isset($app['alchemy_worker.logger_service_name'])) { $app['alchemy_worker.logger_service_name'] = 'logger'; @@ -96,16 +98,4 @@ protected function registerDefaultParameters(Application $app) $app['alchemy_worker.process_pool_size'] = 8; } } - - /** - * Bootstraps the application. - * - * This method is called after all services are registered - * and should be used for "dynamic" configuration (whenever - * a service must be requested). - */ - public function boot(Application $app) - { - // TODO: Implement boot() method. - } }