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

Add 'Features'

This commit is contained in:
Samuel Štancl 2019-09-08 11:11:44 +02:00
parent 8c69d7847e
commit 61739dc5fc
5 changed files with 82 additions and 40 deletions

View file

@ -0,0 +1,20 @@
<?php
use Stancl\Tenancy\TenantManager;
use Stancl\Tenancy\Contracts\Feature;
class TenantRedirect implements Feature
{
public function bootstrap(TenantManager $tenantManager): void
{
RedirectResponse::macro('tenant', function (string $domain) {
// replace first occurance of hostname fragment with $domain
$url = $this->getTargetUrl();
$hostname = parse_url($url, PHP_URL_HOST);
$position = strpos($url, $hostname);
$this->setTargetUrl(substr_replace($url, $domain, $position, strlen($hostname)));
return $this;
});
}
}