1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 19:34:04 +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

@ -4,7 +4,6 @@ declare(strict_types=1);
namespace Stancl\Tenancy;
use Laravel\Telescope\Telescope;
use Stancl\Tenancy\Commands\Run;
use Stancl\Tenancy\Commands\Seed;
use Illuminate\Cache\CacheManager;
@ -50,43 +49,7 @@ class TenancyServiceProvider extends ServiceProvider
]);
$this->app->register(TenantRouteServiceProvider::class);
if (\class_exists(Telescope::class)) {
$this->setTelescopeTags();
}
$this->registerTenantRedirectMacro();
}
public function setTelescopeTags()
{
Telescope::tag(function (\Laravel\Telescope\IncomingEntry $entry) {
$tags = $this->app->make(TenantManager::class)->integration('telescope', $entry);
if (\in_array('tenancy', optional(request()->route())->middleware() ?? [])) {
$tags = \array_merge($tags, [
'tenant:' . tenant('uuid'),
'domain:' . tenant('domain'),
]);
}
return $tags;
});
}
public function registerTenantRedirectMacro()
{
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;
});
}
/**
* Register services.
*