* Initial implementation (lukinovec)
* Make sure DatabaseCacheBootstrapper runs after DatabaseTenancyBootstrapper, misc wip changes
* Fix withTenantDatabases()
* Add failing test (GlobalCacheTest)
* Configure globalCache's DB stores to use central connection instead of default connection every time it's reinstantiated
* Make GlobalCache facade not cached. Even though it wasn't causing issues
in our existing tests, it likely was flaky, and making it not $cached
makes it now consistent with global_cache() - always getting a new
CacheManager from the globalCache container binding
* Add database connection assertions in GlobalCacheTest
* Run all cached resolver/global cache tests with DatabaseCacheBootstrapper
* Reset adjustCacheManagerUsing in revert() and TestCase
* Reset static $stores property
* Finalize GlobalCache-related changes
* tests: remove pointless cache TTLs
* Refactor DatabaseCacheBootstrapper
* Refactor tests
Co-authored-by: lukinovec <lukinovec@gmail.com>
* Test encrypted cookie identification
* Add Fortify bootstrapper custom query param passing test
* Correct Fortify route bootstrapper test (todo refactor, convoluted)
* Clarify Fortify bootstrapper test
* Fix encrypted cookie identification test
* Move encrypted cookie assertion to "cookie identification works"
* Cover configured tenant model columns in cached resolver tests
* Refactor testing resolver with default vs custom tenant model name config
* Delete resolved todo
* Make code more concise
* Keep initial formatting (minimize diff noise)
* Make dataset/helper method parameter clearer
* Clarify fortify test
* Clarify assertions, improve comments
* Delete excessive comments, make existing comments consistent and clearer
* Make cached resolver test file clearer, update outdated comments
* Use the tenant model column term consistently
* FIx inconsistencies
* Provide more info in comment
* make comment more clear
* static property reset
---------
Co-authored-by: Samuel Štancl <samuel@archte.ch>
* UrlGenerator: set defaults based on config; request data: move config to config file+resolver
* Claude code adjustments
* improve request data tests, simplify complex test in UrlGeneratorBootstrapperTest
* url generator test: test changing tenant parameter name
* request data identification: add tenant_model_column configuration
* defaultParameterNames -> passQueryParameter
* move comment
* minor refactor in PathIdentificationTest, expand CLAUDE.md to include early identification section
* Fix COLOR_FLAG
* improve test name
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* TenancyUrlGenerator: add a check for queryParameterName being null
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Fix code style (php-cs-fixer)
---------
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
* cleanup, resolve todos, add immediate todos
* Improve path_identification_middleware docblock
* rename leave() method in tests
* wip fix hardcoded values making assumptions about the parameters used in routing
* defaultParameterNames
* fix CreatesDatabaseUsers return values
* $tenant -> tenant()
* resolve more todos
* make comment block a complete block
* Correct useTenantRoutesInFortify(), delete unused import
* test fixes
* remove todos
* remove JobPipeline todo
* simplify comment example
* remove todo
* fix VERSION_PREFIX in queue.yml
---------
Co-authored-by: lukinovec <lukinovec@gmail.com>
* Declare sensitive parameters as sensitive
... just so that they don't show up in logs
* Remove unnecessary null-coalescing
* Simplify return
* Merge isset() calls
* Inline return
* Use nullsafe operator
* Simplify if-else branches
* Use direct empty string comparison instead of strlen()
* Add missing type
* Change interface as events expect a TenantWithDatabase not just a Tenant
* Narrow typehint
* Remove redundant type casts
* Fix style with php-cs-fixer
* Fix typos
* Revert unwanted if-else simplification
* fix phpstan errors
* narrow type
---------
Co-authored-by: Samuel Štancl <samuel@archte.ch>
This makes it possible to have Domain records in both `foo` and
`foo.{centralDomain}` format when using the combined domain/subdomain
identification middleware, or the origin header id mw which extends it.
This commit also refactors some related logic.
* 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>
* Only retrieve domains if the relationship and the domains table exist (DomianTenantResolver)
* Resolve todo, add other todos
* Use constructor promotion in DeleteDomains
* Fix imports + domain deletion test
* Confirm that turning on resolver caching doesn't break the tests
* Fix Tenant model imports
* Fix code style (php-cs-fixer)
* remove runtime schema check
* temp: enable resolver cache
* make 'autoincrement ids are supported' pass
* disable resolver cache
---------
Co-authored-by: PHP CS Fixer <phpcsfixer@example.com>
Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com>
Co-authored-by: Samuel Štancl <samuel@archte.ch>
* resolver refactor
* Fix code style (php-cs-fixer)
* make tenant column used in PathTenantResolver configurable, fix phpstan errors, minor improvements
* support binding route fields, write tests for customizable tenant columns
* Invalidate cache for all possible columns in path resolver
* implement proper cache separation logic for different columns used by PathTenantResolver
* improve return type
---------
Co-authored-by: PHP CS Fixer <phpcsfixer@example.com>
* Resolve delete tenant storage todo
* Delete outdated todo (resolved in #25)
* Delete resource syncing todo (resolved in #11)
* Make it clear that getArgsForTenant() is used during cache invalidation
* Delete redundant __call() and __callStatic() annotations
* Fix code style (php-cs-fixer)
* Revert %tenant_id% to-do removal
* Test all cached resolvers instead of just the domain one
* Make docblock more concise, delete renaming to-do (the name seems fine)
* Fix method in tests
* If route is the only resolver arg, use the tenant as the cache key instead of encoded route instance
* Resolve to-do
* make docblock more clear
* Add comments to getResolverArgument()
* Rename $id to $tenantKey
* Fix code style (php-cs-fixer)
* Add regression test for forgetting tenant parameters of cached tenants
* Forget route parameter when tenant gets resolved
* Add parameter type
* Simplify getCacheKey()
* Resolvers wip
* Resolvers wip
* Fix code style (php-cs-fixer)
* Bring back the route instance check to getCacheKey, fix test
* add todo
* add assertion
---------
Co-authored-by: PHP CS Fixer <phpcsfixer@example.com>
Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com>
Co-authored-by: Samuel Štancl <samuel@archte.ch>
* Add SingleDomainTenant
* Add logic for single domain tenants
* Test that the single domain approach works (wip)
* Fix code style (php-cs-fixer)
* Simplify SubdomainTest tests
* Add single domain tenant conditions to DomainTenantResolver
* Test single domain tenants in resolver test
* Fix test name typo
* Improve runUsingBothDomainApproaches()
* Delete extra tenancy()->end()
* Test early identification with both domain approaches
* Test that things work with both domain approaches in the rest of the tests
* Fix falsely passing test
* Fix PHPStan errors
* Change SingleDomainTenant to a contract, add SingleDomainTenant test model
* Fix TenantList domainsCLI()
* Improve setCurrentDomain() check
* Fix code style (php-cs-fixer)
* Add annotation
* Revert getCustomColumns() change
* Add comments
* Use the domain returned by the closure in runUsingBoth..()
* Delete `migrate` from test
* Improve test names
* Use variable instead of repeating the same string multiple times
* Update comment
* Add comment
* Clean up PreventAccess test
* Don't assign domain to a single-use variable
* Update comments
* Uncomment datasets
* Add todo
* Fix user impersonation test
* Don't specify tenant key when creating tenant in runUsingBoth..()
* Improve universal route test
* Improve `runUsingBothDomainApproaches()`
* Add tests specific to single domain tenants
* Get rid of the runUsingBothDomainApproaches method
* Add test file specific for the single domain tenant feature
* Rename test
* Make getCustomColumns() function static
* Positiopn datasets differently
* Fix early id test
* Add prevent MW to route MW in test
* Fix single domain tenant tests
* Delete SingleDomainTenantTest (CI testing)
* Add the test file back
* TUrn APP_DEBUG on temporarily
* Turn debug off
* Try creating tenant with non-unique domain (CI testing)
* dd duplicate tenant records
* Revert testing change
* Make SingleDomainTenant not extend base tenant (VirtualColumn issues)
* Fix early id test
* add todo
* Use dev-master stancl/virtualcolumn
* Make SingleDomainTenant extend the tenant base model
* remove todo
* Clean up EarlyIdentificationTest changes
* Finish test file cleanup
* Fix test
* improve test
---------
Co-authored-by: PHP CS Fixer <phpcsfixer@example.com>
Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com>
* Update url binding bootstrapper test
* Fix parent::temporarySignedRoute() call
* Add universal route tests for all identification types
* Improve determineContextFromRequest()
* Add setting `TenancyUrlGenerator::$prefixRouteNames` to true in TSP stub
* Delete seemingly redundant test (making one route universal won't make all routes universal in any case)
* Use collection syntax in ReregisterUniversalRoutes
* Improve comments
* Add domain identification MW annotation
* Update condition in GloballyUsable
* Set `tenancy.bootstrappers` instead of adding the bootstrappers using `tenancy.bootstrappers.x`, move test
* Revert GloballyUsable condition change
* Delete assigning bootstrappers to tenancy.bootstrappers.x
* Exclude cache prefixing bootstrapper from the initial configuration
* Fix test
* Unset bypass parameter
* Set static kernel identification-related properties in TestCase
* Update bootstrapper name in annotation
* Move unset() into a condition
* Update TenancyUrlGenerator condition
* Set static properties without instantiating Tenancy
* Fix unsetting bypass parameter
* formatting changes
* add a comment
* improve docblock
* add docblock to TenancyUrlGenerator [ci skip]
* docblock changes [ci skip]
* Update TenancyUrlGenerator (rename variable, allow bypassing prefixing temporarySignedRoute name)
* Improve determineContextFromRequest
* Only return the new url generator instance when extending 'url' in UrlBindingBootstrapper
* Check route's MW groups for the path ID MW
* Remove extra imports from config
* Rename MiddlewareContext to Context, add condition for skipping ID MW
* Set only the needed bootstrappers in TestCase
* Fix code style (php-cs-fixer)
* Remove condition
* Use correct return type
* Fix PHPStan issue
* Update comment
* Check for tenant parameter instead of prefix
* Update shouldBeSkipped condition for universal routes
* Don't remove the 'universal' MW group after route re-registration, update test
* Fix code style (php-cs-fixer)
* Fix typo
* Add test for mixing placement of access prevention and identification MW
* Add test for mixing placement of access prevention and identification MW
* Update docblock
* Add setting the session and key resolvers in UrlBindingBootstrapper (required with LW file uploads)
* Update stub
* Update variable name in route reregistering action
* Add trailing comma
* Fix code style (php-cs-fixer)
* Require routes using path identification to be flagged as tenant in order to be recognized as tenant routes
* Add tenant flag while re-registering routes
* Update determineContextFromRequest condition (wip)
* Fix code style (php-cs-fixer)
* Update the middleware context logic so that universal routes have to be flagged as tenant instead of just having ID MW
* Update path identification condition
* Fix re-registering the LW localized route (add 'tenant' MW)
* Update docblock
* Simplify LW route re-registration
* Add comment
* Update comment
* Simplify determineContextFromRequest, add comment
* Improve stub
* Add skipRoute method + test
* Fix typo
* Update assets/TenancyServiceProvider.stub.php
* Update src/Concerns/DealsWithEarlyIdentification.php
* Fix typo
Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com>
* Improve comment
* Update test structure
* Restructure Fortify test
* code style
* Fix typo
* Update ReregisterUniversalRoutes annotation
* Only prefix route name if it wasn't already prefixed
* Add todo@docs
* Delete `Tenancy::$kernelAccessPreventionSkipped` and related logic
* Delete test tenant cleanup
* Test MW group unpacking, restructure and improve test
* Test that tenancy isn't initialized after visiting a central route with the tenant parameter
* Delete "in both central and tenant contexts" from test names
* Test that re-registering works with controllers too
* Set misc route properties during re-registering
* Determine context instead of guessing, update universal route tests
* Use randomly generated tenant ID instead of hardcoding `acme`
* Remove setting route validators
* Rename and update determine context method, add comments
* Update ForgetTenantParameter annotation
* Add comment
* Delete comment, delete variable assignment
* Update early domain identification test
* Improve domain identification tests (test defaulting accurately)
* Improve readability
* Simplify domain early ID test
* Use randomly generated tenant instead of 'acme'
* Simplify request data ID test, use random tenant instead of 'acme'
* Simplify defaulting domain identification test
* Use RouteFacade alias for the Route facade, improve test code
* Add defaulting to the request data and path ID tests
* Merge path identification tenant parameter removal tests, clean up
* Correct wording
Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com>
* Delete debugging things from UniversalRouteTest
* Update annotation
* Add `// Creates a matrix`
* Improve comment wording
* Add MiddlewareUsableWithUniversalRoutes, refactor code accordingly
* Fix code style (php-cs-fixer)
* Delete debugging leftovers
* Delete unused import
* Update universal route GloballyUsable condition
* Don't implement the universal route interface in access prevention MW
* Check if request host is in the central domains in domain ID MW
* Test universal routes with domain identification without access prevent MW
* Test that universal routes work only with identification MW implementing the universal route interface
* Fix code style (php-cs-fixer)
* Rename GloballyUsable to UsableWithEarlyIdentification
* Fix annotation
* Update requestHasTenant annotations
* Update comment
* Add `with()` comments
* Add with() comments where missing
* Rename interface, update/add comments
* Rename exception, update its default message
* Fix code style (php-cs-fixer)
* Fix interface name
* Delete redundant code from subdomain ID MW
* Change domainOrSubdomain ID MW so that instead of passing the identification to other MWs, it happens in the domainOrSubdomain MW
* Test domainOrSubdomain identification with universal routes
* Fix code style (php-cs-fixer)
* Rename universal routes interface
* Fix code style (php-cs-fixer)
* Try explaining forgetting the tenant parameter better
* update interface name reference
* uncouple example from query parameters
* Update ForgetTenantParameter.php
* Update ForgetTenantParameter annotation
* Check both routeHasMiddleware and routeHasIdentificationMiddleware in the route MW detection test
* Hardcode tenant subdomain
* Delete redundant event listening code
* Delete unused imports
* Delete misuse of `tenancy()->getMiddlewareContext()` from conditions
* Delete unused variable
* Update comment
* Correct request data identification test (defaulting)
* Fix defaulting in path id test
* Move default route context configuration in domian id test
* Rename and update the tenant parameter test
* Delete extra tenant parameter test
* Use `tenant-domain.test` instead of `127.0.0.2`
* Add `default_to_universal_routes` config key
* Deal with defaulting to universal routes in the reregistering action
* Update logic to make defaulting to universal routes possible
* Test defaulting to universal routes
* Fix code style (php-cs-fixer)
* Delete extra tests
* Delete "without access prevention" from datasets
* Add defaulting to universal routes to datasets
* Override universal flag by central/tenant flag
* Add universal flag overriding test
* Update "a route can be universal in both route modes" so that the name corresponds with the tested thing
* Ignore the PHPStan error
* Reset `InitializeTenancyByPath::$onFail` in PathIdentificationTest
* Simplify expression
* Use 'Tenancy (not) initialized.' in instead of `tenant()?->getTenantKey()` for better assertions
* Properly test removing tenant parameter
* Reset static properties in tests
* Correct comments in EarlyIdentificationTest
* Add comment
* Add detail to annotation
* Throw exception if payload isn't string or null in request data ID MW
* Fix code style (php-cs-fixer)
* Delete static `$kernelIdentificationSkipped` property, use `$request->attributes` instead
* Use 'default_route_mode' instead of 'default_to_tenant/universal_routes'
* Fix code style (php-cs-fixer)
* Make path identification MW, tenantParameterName and tenantRouteNamePrefix configurable in ReregisterUniversalRoutes
* Delete unused import
* Add `$passTenantParameterToRoute` to TenancyUrlGenerator
* Use `$passTenantParameterToRoute` in BootstrapperTest
* Bypass tenant parameter passing
* Improve TenancyUrlGenerator so that both ID methods work
* Fix code style (php-cs-fixer)
* Improve TenancyUrlGenerator readability
* Add modifyBehavior() to TenancyUrlGenerator
* Fix code style (php-cs-fixer)
* Improve comment
* Toggle route name prefixing in path/request data ID MW (route-level identification)
* Fix code style (php-cs-fixer)
* Add path identification MW config key, add `getTenantParameterName()` to ForgetTenantParameter
* Fix code style (php-cs-fixer)
* Fix modifyBehavior and routeBehaviorModificationBypassed
* Add type to `$parameters` parameter
* Split modifyBehavior into two methods, don't pass name and parameters by reference
* Update UrlBindingBootstrapper annotation
* Correct naming in tests (request data -> query string identification)
* Add info to annotation
* Pass arrays to the behavior modification methods instead of `mixed`
* Fix default value of static property in Fortify bootstrapper
* Fix code style (php-cs-fixer)
* Correct annotation
* Enable prefixing routes directly using path identification MW
* Test re-registration of routes with path ID MW
* Prefix names of routes directly using path ID MW
* Fix code style (php-cs-fixer)
* Add Livewire v3 integration example to TSP stub
* Prefix route name only if it's not prefixed already
* Rename ReregisterUniversalRoutes to ReregisterRoutesAsTenant
* Fix code style (php-cs-fixer)
* Improve ReregisterRoutesAsTenant
* Add/update TenancyUrlGenerator docblocks
* Update action name in comments/test names
* Update reregister action annotation
* Delete unused imports
* Improve comments
* Make method protected
* Improve TenancyUrlGenerator code
* Test bypass parameter removal
* Fix comment
* Update annotation
* Improve shouldReregisterRoute
* Fix typo, delete redundant comment
* Improve skipRoute
* Improve shouldBeSkipped
* Add and test `$passTenantParameterToRoutes`
* add a comment
* Fix typo in comment
* Pass array as $parameters in prepareRouteInputs
* Make path_identification_middleware an array
* Fix code style (php-cs-fixer)
* Fix ReregisterRouteAsTenant
* Move tenantParameterName and tenantRouteNamePrefix getting to PathIdentificationManager
* Make PathIdentificationManager properties `Closure|null`
* Fix code style (php-cs-fixer)
* Fix PathIdentificationManager
* Update comments
* Use foreach for dataset definition
* Extract repetitive inGlobalStack and routeHasMiddleware calls
* Refactor PathIdentificationManager
* Update TenancyUrlGenerator annotation
* Add $skippedRoutes, refactor ReregisterRoutesAsTenant
* Improve reregisterRoute
* Update re-register action annotation
* update test name
* Make PathIdentificationManager methods static again, update comments
* Add test comment
* Update ForgetTenantParameter annotation
* Improve route re-registration condition, add comment
* Change "re-register" to "clone"
* minor code improvements
---------
Co-authored-by: lukinovec <lukinovec@gmail.com>
Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com>
Co-authored-by: PHP CS Fixer <phpcsfixer@example.com>
* Instead of querying Domain model, find Tenant and eager load it's domain via Tenant model. Fixed cached lookup issue - when caching Tenant, also include the current Domain, so it can be later accessed via $tenant->domains->first() (even, when using multiple domains per tenant). Added tenantIdentifiedFromCache method in CachedTenantResolver.php, which can be used to set custom properties in resolvers after Tenant is loaded from cache.
* StlyeCi Fix - removed PHP 8 nullsafe operator for compatibility with older PHP versions, replaced with inline if
* Redundant variable '$domain', because $tenant is not null, only, when current domain is found and relationship is loaded (with only one domain).
* Fixed tenant()->domains showing incorrect data. Renamed tenantIdentifiedFromCache() method and removed duplicate code, when setting current domain.
* Removed select() for better flexibility, added new method setCurrentDomain(), refactored the usage of tenantIdentified().
* rename method to resolved()
* clean up code
* StyleCi Fix
Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com>