Skip to content

Commit

Permalink
Silex2 (#7)
Browse files Browse the repository at this point in the history
silex2
  • Loading branch information
jygaulier authored Apr 12, 2018
1 parent a4911cc commit 4218c73
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 40 deletions.
15 changes: 11 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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": {
Expand Down
62 changes: 26 additions & 36 deletions src/WorkerProvider/WorkerServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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';
Expand All @@ -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.
}
}

0 comments on commit 4218c73

Please sign in to comment.