laravel-resque/src/ResqueServiceProvider.php

62 lines
1.5 KiB
PHP
Raw Normal View History

2016-07-28 21:52:05 +00:00
<?php
namespace Hlgrrnhrdt\Resque;
use Hlgrrnhrdt\Resque\Console\WorkCommand;
use Illuminate\Support\ServiceProvider;
/**
* ResqueServiceProvider
*
* @author Holger Reinhardt <hlgrrnhrdt@gmail.com>
*/
class ResqueServiceProvider extends ServiceProvider
{
2016-07-29 16:03:41 +00:00
/**
*
*/
public function boot()
{
2016-07-29 22:00:27 +00:00
$this->setRedisConfig();
2016-07-29 16:03:41 +00:00
}
2016-07-28 21:52:05 +00:00
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
2016-07-29 16:03:41 +00:00
$this->registerResque();
2016-07-28 21:52:05 +00:00
$this->registerWorkCommand();
}
2016-07-29 16:03:41 +00:00
protected function registerResque()
2016-07-28 21:52:05 +00:00
{
2016-07-29 22:00:27 +00:00
$this->app->singleton(Resque::class, function () {
$prefix = $this->app['config']['resque.prefix'];
2016-07-29 23:49:45 +00:00
return (new Resque())->setPrefix($prefix ?: 'resque');
2016-07-28 21:52:05 +00:00
});
}
protected function registerWorkCommand()
{
2016-07-29 12:05:07 +00:00
$this->app->singleton('command.resque.work', function () {
2016-07-29 22:00:27 +00:00
return new WorkCommand($this->app->make(Resque::class));
2016-07-28 21:52:05 +00:00
});
2016-07-29 12:02:56 +00:00
$this->commands('command.resque.work');
2016-07-28 21:52:05 +00:00
}
2016-07-29 22:00:27 +00:00
protected function setRedisConfig()
{
$config = $this->app['config']['resque.connection'];
$host = isset($config['host']) ? $config['host'] : 'localhost';
$port = isset($config['port']) ? $config['port'] : 6379;
$database = isset($config['database']) ? $config['database'] : 0;
$server = implode(':', [$host, $port]);
\Resque::setBackend($server, $database);
}
2016-07-28 21:52:05 +00:00
}