system • Started as a standalone version • Later I added a cloud hosted version • The aim to have both use the same basic code base with cloud being modified for multi-tenant • Have the ability to test without having to worry about the multi-tenantancy part
(string $subdomain): void; public function switchById(string $id): void; } interface TenantProvider { public function getTenant(): Tenant; } interface TenantRepositoryInterface { /** * @return \Generator|Tenant[] */ public function getAllActive(): \Generator; }
a Scheduler message 2. Create a messenger stamp to show it’s been created for a tenant 3. Create a messenger middleware to create a message for each tenant 4. Create a messenger middleware to switch to the correct tenant
use Symfony\Component\Messenger\MessageBusInterface ; use Symfony\Component\Messenger\Middleware\MiddlewareInterface ; use Symfony\Component\Messenger\Middleware\StackInterface ; class ScheduleMiddleware implements MiddlewareInterface { public function __construct( private MessageBusInterface $messageBus, private TenantRepositoryInterface $tenantRepository , ) { } public function handle(Envelope $envelope, StackInterface $stack): Envelope { if (!$envelope->getMessage() instanceof ScheduleMessageInterface ) { return $stack->next()->handle($envelope, $stack); } // Check if the message has already been duplicated if (null !== $envelope->last(SchedulerStamp ::class)) { return $stack->next()->handle($envelope, $stack); } // ...