1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 19:14:04 +00:00

[2.1.0] Central queue connections (#181)

* Central queues

* Better dependency injection

* tenancy=false => central=true; move config to env setup

* Apply fixes from StyleCI
This commit is contained in:
Samuel Štancl 2019-10-17 21:00:52 +02:00 committed by GitHub
parent d5b01219fd
commit cfcb2574c2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 13 deletions

View file

@ -4,7 +4,8 @@ declare(strict_types=1);
namespace Stancl\Tenancy\TenancyBootstrappers;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Config\Repository;
use Illuminate\Queue\QueueManager;
use Illuminate\Support\Testing\Fakes\QueueFake;
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
use Stancl\Tenancy\Tenant;
@ -14,19 +15,18 @@ class QueueTenancyBootstrapper implements TenancyBootstrapper
/** @var bool Has tenancy been started. */
public $started = false;
/** @var Application */
protected $app;
/** @var Repository */
protected $config;
public function __construct(Application $app)
public function __construct(Repository $config, QueueManager $queue)
{
$this->app = $app;
$this->config = $config;
$bootstrapper = &$this;
$queue = $this->app['queue'];
if (! $queue instanceof QueueFake) {
$queue->createPayloadUsing(function () use (&$bootstrapper) {
return $bootstrapper->getPayload();
$queue->createPayloadUsing(function ($connection) use (&$bootstrapper) {
return $bootstrapper->getPayload($connection);
});
}
}
@ -41,12 +41,16 @@ class QueueTenancyBootstrapper implements TenancyBootstrapper
$this->started = false;
}
public function getPayload()
public function getPayload(string $connection)
{
if (! $this->started) {
return [];
}
if ($this->config["queue.connections.$connection.central"]) {
return [];
}
$id = tenant('id');
return [