mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 18:04:03 +00:00
[1.8.0] Add Telescope tags with tenant ids (#77)
This commit is contained in:
parent
8d8c177dac
commit
824ecfce48
3 changed files with 64 additions and 0 deletions
|
|
@ -16,6 +16,7 @@
|
|||
},
|
||||
"require-dev": {
|
||||
"vlucas/phpdotenv": "^3.3",
|
||||
"laravel/telescope": "^2.0",
|
||||
"laravel/framework": "5.8.*",
|
||||
"orchestra/testbench-browser-kit": "~3.8",
|
||||
"league/flysystem-aws-s3-v3": "~1.0",
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Stancl\Tenancy;
|
||||
|
||||
use Laravel\Telescope\Telescope;
|
||||
use Stancl\Tenancy\Commands\Run;
|
||||
use Stancl\Tenancy\Commands\Seed;
|
||||
use Illuminate\Cache\CacheManager;
|
||||
|
|
@ -49,10 +50,30 @@ class TenancyServiceProvider extends ServiceProvider
|
|||
|
||||
$this->app->register(TenantRouteServiceProvider::class);
|
||||
|
||||
if (\class_exists(Telescope::class)) {
|
||||
$this->setTelescopeTags();
|
||||
}
|
||||
|
||||
$this->registerTenantRedirectMacro();
|
||||
$this->makeQueuesTenantAware();
|
||||
}
|
||||
|
||||
public function setTelescopeTags()
|
||||
{
|
||||
Telescope::tag(function (\Laravel\Telescope\IncomingEntry $entry) {
|
||||
$tags = $this->app->make(TenantManager::class)->integration('telescope', $entry);
|
||||
|
||||
if (\in_array('tenancy', request()->route()->middleware())) {
|
||||
$tags = \array_merge($tags, [
|
||||
'tenant:' . tenant('uuid'),
|
||||
'domain:' . tenant('domain'),
|
||||
]);
|
||||
}
|
||||
|
||||
return $tags;
|
||||
});
|
||||
}
|
||||
|
||||
public function registerTenantRedirectMacro()
|
||||
{
|
||||
RedirectResponse::macro('tenant', function (string $domain) {
|
||||
|
|
|
|||
|
|
@ -18,6 +18,13 @@ trait TenantManagerEvents
|
|||
'ended' => [],
|
||||
];
|
||||
|
||||
/**
|
||||
* Integration listeners.
|
||||
*
|
||||
* @var callable[][]
|
||||
*/
|
||||
protected $integrationListeners = [];
|
||||
|
||||
/**
|
||||
* Register a listener that will be executed before tenancy is bootstrapped.
|
||||
*
|
||||
|
|
@ -82,4 +89,39 @@ trait TenantManagerEvents
|
|||
return $prevents->merge($listener($this) ?? []);
|
||||
}, collect([]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a callback for an integration event.
|
||||
*
|
||||
* @param string $name
|
||||
* @param callable $callback
|
||||
* @return void
|
||||
*/
|
||||
public function integrationEvent(string $name, callable $callback)
|
||||
{
|
||||
if (\array_key_exists($name, $this->integrationListeners)) {
|
||||
$this->integrationListeners[$name][] = $callback;
|
||||
} else {
|
||||
$this->integrationListeners[$name] = [$callback];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return callbacks for an integration event.
|
||||
*
|
||||
* @param string $name
|
||||
* @param mixed $arguments,...
|
||||
* @return callable[]
|
||||
*/
|
||||
public function integration(string $name, ...$arguments)
|
||||
{
|
||||
if ($arguments) {
|
||||
// If $arguments are supplied, execute all listeners with arguments.
|
||||
return \array_reduce($this->integrationListeners[$name] ?? [], function ($tags, $listener) use ($arguments) {
|
||||
return \array_merge($tags, $listener(...$arguments));
|
||||
}, []);
|
||||
}
|
||||
|
||||
return $this->integrationListeners[$name];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue