1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-05-07 00:04:04 +00:00
Commit graph

1436 commits

Author SHA1 Message Date
lukinovec
20d494f4c6 Reset BroadcastingConfigBootstrapper::$broadcaster in tests 2026-04-14 09:09:46 +02:00
lukinovec
a247bb0b9e Correct config bootstrapper test comment 2026-04-13 15:48:03 +02:00
lukinovec
b3d5197702 Correct channel prefix test comments 2026-04-13 15:44:35 +02:00
lukinovec
4aeaa66b23 Remove unused $broadcaster parameter 2026-04-13 15:32:26 +02:00
lukinovec
9ab0a729d6
Fix typo
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2026-04-13 15:28:11 +02:00
dc344b7ae6
Merge branch 'master' into broadcasting-fixes 2026-04-12 13:29:28 +02:00
60dd5226c4
[4.x] Add Tenancy::reinitialize() method (#1449)
Some bootstrappers read attributes of the tenant during bootstrap() but
don't respond to changes made to the tenant afterwards.

Therefore, when making changes to the tenant that'd affect the behavior
of a bootstrapper, it's necessary to reinitialize tenancy (if it matters
that changes are reflected immediately). This adds a convenience helper
for that purpose.
2026-04-08 19:21:43 +02:00
lukinovec
f8528fc9ac Add 'reverb' to TenancyBroadcastManager::$tenantBroadcasters 2026-04-03 15:54:25 +02:00
lukinovec
ef476c5361 Polish comments 2026-04-03 13:40:44 +02:00
lukinovec
c831393589 Update comment 2026-04-03 13:10:19 +02:00
lukinovec
4937a74ed5 BroadcastingConfigBootstrapper and TenancyBroadcastManager: comments 2026-04-03 13:07:40 +02:00
lukinovec
29dd23db61 BroadcastingConfigBootstrapperTest: add 'reverb' driver to datasets
Adding 'reverb' to `TenancyBroadcastManager::$tenantBroadcasters` will make these tests pass.
2026-04-03 11:26:46 +02:00
lukinovec
6b99921839 BroadcastingConfigBootstrapper: correct $credentialsMap array_merge order
Previously, credential mappings from `$mapPresets` overrode mappings defined in `$credentialsMap`. If someone used pusher/reverb/ably and wanted to override some of that preset's mappings, e.g. use 'pusher_app_key' instead of 'pusher_key' by specifying 'pusher_app_key' in `$credentialsMap`, the preset's mapping ('pusher_key') would still be used.
2026-04-03 11:23:24 +02:00
lukinovec
fc45e09dc9 Update BroadcastingConfigBootstrapperTest
Tests now use datasets with all drivers that are in `TenancyBroadcastManager::$tenantBroadcasters` by default plus the custom driver. Also add assertions for updating the tenant properties/config in tenant context.
2026-04-03 11:17:06 +02:00
lukinovec
4b1cc9c84a Improve comments 2026-04-02 16:54:53 +02:00
github-actions[bot]
9e9bedc0f2 Fix code style (php-cs-fixer) 2026-04-02 14:15:16 +00:00
lukinovec
b2add06a98 Delete BroadcastingTest
Tests from BroadcastingTest moved to the appropriate bootstrapper test files. The new tenant credentials test has assertions equal to both the original property -> config mapping test and the config -> credentials test.
2026-04-02 16:14:53 +02:00
lukinovec
bbe2ff02df BroadcastingTest: update channel inheritance test
Test that the bound Broadcaster instance inherits the channels too. Also test that the channels aren't lost when switching context to another tenant.
2026-04-02 15:33:35 +02:00
lukinovec
b6c035c912 Improve comments 2026-04-02 15:28:33 +02:00
lukinovec
0fbe1bc846 TenancyBroadcastManager: delete Broadcaster singleton binding
Moved binding `Broadcaster` to the bootstrapper.
2026-04-02 15:24:52 +02:00
lukinovec
28b61198ed TenancyBroadcastManager: update docblocks 2026-04-01 15:50:04 +02:00
lukinovec
d939866798 Fix custom creator assertions 2026-03-31 17:12:50 +02:00
lukinovec
c4f4451fd5 Add assertions for the config of the bound manager's driver 2026-03-31 17:12:50 +02:00
github-actions[bot]
0b860ea38a Fix code style (php-cs-fixer) 2026-03-31 14:33:01 +00:00
lukinovec
65beecf265 BroadcastingConfigBootstrapper: clear the Broadcast facade's resolved Broadcasting\Factory instance
After initializing tenancy, calls like `Broadcast::auth()` use the central `BroadcastManager`. Clearing the facade's resolved `Broadcasting\Factory` instance fixes that problem.
2026-03-31 16:32:33 +02:00
lukinovec
b1e91f1029 BroadcastingConfigBootstrapper: make Broadcaster::class resolve to tenant's broadcaster on bootstrap() 2026-03-31 16:25:25 +02:00
lukinovec
c653c51928 BroadcastingConfigBootstrapper: make tenant manager inherit central manager's custom creators 2026-03-31 16:22:41 +02:00
lukinovec
fafd082261 Fix typo in test 2026-03-31 16:19:43 +02:00
lukinovec
2ecc94d8e8 BroadcastingConfigBootstrapper: test persistence of custom driver creators
Test that TenancyBroadcastManager inherits the custom driver creators from the central BroadcastManager.
2026-03-31 16:19:15 +02:00
lukinovec
7d749eb592 BroadcastingConfigBootstrapper: test mapping credentials
Test that BroadcastingConfigBootstrapper correctly maps tenant properties to broadcasting config/credentials, and that the credentials don't leak when switching contexts. Also add the `$config` property to `TestingBroadcaster` so that we can access the credentials used by the broadcaster.
2026-03-31 15:32:45 +02:00
Samuel Mwangi
fb654e7a6b
[4.x] Update Pest to v4 (#1430) 2026-03-30 09:44:53 +02:00
c4960b76cb
[4.x] Laravel 13 support (#1443)
- Update ci.yml and composer.json
- Wrap single database tenancy trait scopes in whenBooted()
- Update SessionSeparationTest to use laravel-cache- prefix in L13
  and laravel_cache_ in <=L12. Our own prefix remains tenant_%tenant%_
  (as configured in tenancy.cache.prefix). We could update this to be
  tenant-%tenant%- from now on for consistency with Laravel's prefixes
  (changed in https://github.com/laravel/framework/pull/56172) but I'm
  not sure yet. _ seems to read a bit better but perhaps consistency
  is more important. We may change this later and it can be adjusted
  in userland easily (since it's just a config option).
2026-03-18 19:17:28 +01:00
8f3ea6297f
phpstan: change InputOption syntax 2026-03-09 02:13:37 +01:00
lukinovec
16861d2599
[4.x] Make URL::temporarySignedRoute() respect the bypass parameter (#1438)
Using `URL::temporarySignedRoute()` in tenant context with
`UrlGeneratorBootstrapper` enabled doesn't work the same as `route()`.
The bypass parameter doesn't actually bypass the route name prefixing.

`route()` is called in the `parent::temporarySignedRoute()` call, and
because the bypass parameter is removed before calling
`parent::temporarySignedRoute()`, the underlying `route()` call doesn't
get the bypass parameter and it ends up attempting to generate URL for a
route with the name prefixed with 'tenant.'.

This PR adds the bypass parameter back after `prepareRouteInputs()`, so
that `parent::temporarySignedRoute()` receives it, and the underlying
`route()` call respects it. Also added basic tests for the
`URL::temporarySignedRoute()` behavior (the new bypass parameter test
works as a regression test).
2026-03-09 02:07:02 +01:00
lukinovec
37b2a91aa9
[4.x] Fix URL override example in TenancyServiceProvider stub (#1426)
This PR fixes the URL override example in TenancyServiceProvider stub
(the commented `overrideUrlInTenantContext()` segment). If the tenant
doesn't have any domain, set the root URL back to the original one.
2026-01-14 11:18:15 +01:00
Punyapal Shah
e3701f1cc1
[4.x] Add more relation type annotations (#1424)
This pull request adds improved PHPDoc type annotations to several
Eloquent relationship methods, enhancing static analysis and developer
experience. These changes clarify the expected return types for
relationships, making the codebase easier to understand and work with.

Relationship method type annotations:

* Added a detailed return type annotation to the `tenant` method in the
`BelongsToTenant` trait, specifying the related model and the current
class.
* Added a detailed return type annotation to the `domains` method in the
`HasDomains` trait, specifying the related model and the current class.
* Added a detailed return type annotation to the `tenants` method in the
`ResourceSyncing` class, specifying the related model and the current
class.
2025-12-28 23:20:05 +01:00
Victor R
3c0e21b726
[4.x] Filesystem bootstrapper: scoped disk support (#1402)
Fixes #1401

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: lukinovec <lukinovec@gmail.com>
Co-authored-by: Samuel Stancl <samuel@archte.ch>
2025-12-16 23:17:11 +01:00
7955aae6d5
TSP stub: remove unnecessary imports
Also update PHP 8.5 steps in CONTRIBUTING.md since PHP 8.5 is released
now.
2025-12-12 20:20:29 +01:00
a778e17686
Merge pull request #1411 from archtechx/resource-syncing-refactor
[4.x] Improve resource syncing (refactor + mapping cleanup + morph maps)
2025-12-12 04:02:42 +01:00
lukinovec
159e600a9b Syncing: support morph maps in TriggerSyncingEvents 2025-12-12 03:43:52 +01:00
04a20ca930
[MINOR BC BREAK] Syncing: PivotWithRelation -> PivotWithCentralResource
The old names of the class and method were misleading. We don't
actually need any relation. And we don't even need a model instance
as we were returning previously -- the only use of that method was
in TriggerSyncingEvents which would immediately use ::class on the
returned value. Therefore, all we are asking for in this interface
is just the central resource class.
2025-11-26 05:52:55 +01:00
072fcc6326
Syncing: move global ID generation logic to an overridable method
Also make all resource syncing-related listener closures static.

Also correct return type for getGlobalIdentifierKey to string|int.
(We intentionally do not support returning null like many other
"get x key" methods would since such a case might break resource
syncing logic. This is also why we use inline getAttribute() in the
creating listener instead of calling the method.)
2025-11-26 05:52:55 +01:00
lukinovec
e079803025 Syncing: Add DeleteAllTenantMappings listener 2025-11-26 05:52:55 +01:00
lukinovec
44e8ec8abf Syncing: SyncedResourceDeleted event and DeleteResourceMapping listener
Also move pivot record deletion to that listener and improve tests

The 'tenant pivot records are deleted along with the tenants to which
they belong to' test is failing in this commit -- the listener
for deleting mappings when a *tenant* is deleted is only implemented
in the next commit. The only change done here is to re-add FKs
(necessary for passing *in this commit* in that specific dataset
variant) that were removed from the default test migration as we now
have the DeleteResourceMapping listener that's enabled by default.
2025-11-26 05:52:48 +01:00
45cf7029af
globalUrl: useAssetOrigin() instead of setAssetRoot()
This change was prompted by a phpstan failure after a recent update.
While making this change, I noticed we don't need the macro anymore
as useAssetOrigin() was added to the UrlGenerator earlier this year,
simplifying our implementation.
2025-11-14 10:59:31 +01:00
0cd0bc44b1
config: ignore port in default central_domains value
Recent Laravel installations often have http://localhost:8000 as
APP_URL, so we make sure to strip any port suffix from the default
central domain derived from APP_URL.
2025-11-11 02:06:13 +01:00
38aab013a4
Merge pull request #1416 from archtechx/cloning-improvements
[4.x] Route cloning improvements
2025-11-10 22:04:02 +01:00
2aca784c0b
Cloning: remove comments in TSP stub in favor of referencing class docs 2025-11-10 17:31:37 +01:00
6ef4b91744
Cloning: improve type annotations, add cloneRoutes() for convenience 2025-11-10 02:16:57 +01:00
197513dd84
Cloning: addTenantMiddleware() for specifying ID MW for cloned route
Previously, tenant identification middleware was typically specified
for the cloned route by "inheriting" it from the central route, which
necessarily meant that the central route had to also be marked as
universal so it could continue working in the central context --
despite presumably not being usable in the tenant context, thus being
universal for no proper reason. In such cases, universal routes were
used mainly as a mechanism for specifying the tenant identification
middleware to use on the cloned tenant route.

Given that recent refactors of the cloning feature have made it more
customizable and a bit nicer to use "multiple times", i.e. run handle()
with a few different configurations of the action, letting the
developer specify the used tenant middleware using a method like this
only makes sense.

The feature also becomes more independently usable and not just a
"hack for universal routes with path identification".
2025-11-09 00:27:14 +01:00