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

Refactor early identification (#47)

* Make universal route logic part of tbe early ID trait

* Add requstHasTenant to prevent access MW, add todo@samuel

* Delete PathIdentificationManager, move the used methods appropriately

* Correct and refactor code related to the deleted PathIdentificationManager class

* Add docblock

* Fix code style (php-cs-fixer)

* refactor globalStackMiddleware()

* remove todos [ci skip]

* refactor routeMiddleware()

* revert bool assertions

* revert more changes

---------

Co-authored-by: PHP CS Fixer <phpcsfixer@example.com>
Co-authored-by: Samuel Štancl <samuel@archte.ch>
This commit is contained in:
lukinovec 2024-04-22 11:30:58 +02:00 committed by GitHub
parent b70cd0e531
commit 4e51cdbacb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 95 additions and 256 deletions

View file

@ -193,12 +193,11 @@ class TenancyServiceProvider extends ServiceProvider
* return RouteFacade::get('/livewire/livewire.js', $handle)->middleware(['universal']);
* });
*/
if (InitializeTenancyByRequestData::inGlobalStack()) {
TenancyUrlGenerator::$prefixRouteNames = false;
}
if (InitializeTenancyByPath::inGlobalStack()) {
if (tenancy()->globalStackHasMiddleware(config('tenancy.identification.path_identification_middleware'))) {
TenancyUrlGenerator::$prefixRouteNames = true;
/** @var CloneRoutesAsTenant $cloneRoutes */

View file

@ -87,7 +87,17 @@ return [
Middleware\InitializeTenancyByDomainOrSubdomain::class,
],
// todo@lukas docblock
/**
* Identification middleware tenancy recognizes as path identification middleware.
*
* This is used during determining whether whether a path identification is used
* during operations specific to path identification, e.g. forgetting the tenant parameter in ForgetTenantParameter.
*
* If you're using a custom path identification middleware, add it here.
*
* @see \Stancl\Tenancy\Actions\CloneRoutesAsTenant
* @see \Stancl\Tenancy\Listeners\ForgetTenantParameter
*/
'path_identification_middleware' => [
Middleware\InitializeTenancyByPath::class,
],

View file

@ -3,14 +3,14 @@
declare(strict_types=1);
use Illuminate\Support\Facades\Route;
use Stancl\Tenancy\PathIdentificationManager;
use Stancl\Tenancy\Controllers\TenantAssetController;
use Stancl\Tenancy\Resolvers\PathTenantResolver;
Route::get('/tenancy/assets/{path?}', TenantAssetController::class)
->where('path', '(.*)')
->name('stancl.tenancy.asset');
Route::prefix('/{' . PathIdentificationManager::getTenantParameterName() . '}/')->get('/tenancy/assets/{path?}', TenantAssetController::class)
Route::prefix('/{' . PathTenantResolver::tenantParameterName() . '}/')->get('/tenancy/assets/{path?}', TenantAssetController::class)
->where('path', '(.*)')
->middleware('tenant')
->name(PathIdentificationManager::getTenantRouteNamePrefix() . 'stancl.tenancy.asset');
->name(PathTenantResolver::tenantRouteNamePrefix() . 'stancl.tenancy.asset');