1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 21:54:03 +00:00
tenancy/src/TenancyBootstrappers/QueueTenancyBootstrapper.php
Samuel Štancl abd0b8f04e
[2.x] Queued post-creation automigration (#154)
* Queued post-creation automigration

* Add shouldQueueMigration()

* Automigration test, config key, QueueTenancyBootstrapper support for QueueFake

* Apply fixes from StyleCI

* Fix if statement
2019-10-04 21:34:17 +02:00

59 lines
1.2 KiB
PHP

<?php
declare(strict_types=1);
namespace Stancl\Tenancy\TenancyBootstrappers;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Support\Testing\Fakes\QueueFake;
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
use Stancl\Tenancy\Tenant;
class QueueTenancyBootstrapper implements TenancyBootstrapper
{
/** @var bool Has tenancy been started. */
public $started = false;
/** @var Application */
protected $app;
public function __construct(Application $app)
{
$this->app = $app;
$bootstrapper = &$this;
$queue = $this->app['queue'];
if (! $queue instanceof QueueFake) {
$queue->createPayloadUsing(function () use (&$bootstrapper) {
return $bootstrapper->getPayload();
});
}
}
public function start(Tenant $tenant)
{
$this->started = true;
}
public function end()
{
$this->started = false;
}
public function getPayload()
{
if (! $this->started) {
return [];
}
$id = tenant('id');
return [
'tenant_id' => $id,
'tags' => [
"tenant:$id",
],
];
}
}