Skip to content

Commit 9f344bf

Browse files
committed
improve comments
1 parent c76ae9e commit 9f344bf

3 files changed

Lines changed: 13 additions & 15 deletions

File tree

src/Bootstrappers/CacheTenancyBootstrapper.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
* Makes cache tenant-aware by applying a prefix.
1919
*
2020
* Using this bootstrapper together with DatabaseTenancyBootstrapper
21-
* with a database cache store results in double scoping. The store is scoped by
22-
* DB connection (entries go into the tenant's database) *and* by the prefix. This is
23-
* harmless for most use cases, but can produce unexpected behavior.
21+
* with a database cache store will result in "double scoping". The store will be scoped
22+
* by the DB connection (entries will go into the tenant's database) *and* by the prefix.
23+
* This is harmless in most cases, but is important to be aware of.
2424
*
25-
* If you're using a database cache store, use DatabaseCacheBootstrapper instead of this one.
25+
* If you only use database cache stores, consider using DatabaseCacheBootstrapper instead.
2626
*
2727
* @see Stancl\Tenancy\Bootstrappers\DatabaseCacheBootstrapper
2828
*/

src/Bootstrappers/DatabaseCacheBootstrapper.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@
2121
*
2222
* By default, this bootstrapper scopes ALL cache stores that use the database driver. If you only
2323
* want to scope SOME stores, set the static $stores property to an array of names of the stores
24-
* you want to scope. These stores must use 'database' as their driver.
24+
* you want to scope. Those stores must use 'database' as their driver.
2525
*
2626
* Notably, this bootstrapper sets TenancyServiceProvider::$adjustCacheManagerUsing to a callback
2727
* that ensures all affected stores still use the central connection when accessed via global cache
28-
* (typically the GlobalCache facade or global_cache() helper), even though this bootstrapper explicitly
29-
* sets the connection to tenant for all scoped cache stores. Extending database store on the global cache manager
30-
* cannot fix globalCache on its own because it reads 'tenant' from config (set by this bootstrapper), not null,
31-
* so the callback is still needed to correct the connection to central for globalCache.
28+
* (typically the GlobalCache facade or global_cache() helper). The code in TenancyServiceProvider
29+
* that uses `extend()` callbacks to make database stores on the global cache manager use the central
30+
* connection only corrects stores scoped by the Database*Tenancy*Bootstrapper. This bootstrapper
31+
* also changes the stores' connection in the *config* to 'tenant' which doesn't let that callback
32+
* change the connection back to central on the global cache manager.
3233
*/
3334
class DatabaseCacheBootstrapper implements TenancyBootstrapper
3435
{

src/TenancyServiceProvider.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,19 +99,16 @@ public function register(): void
9999
// config is null fall back to the default DB connection ('tenant'). Reset each
100100
// such store to its explicitly configured connection, or fall back to central.
101101
$centralConnection = $app['config']['tenancy.database.central_connection'];
102-
103-
$manager->extend('database', function ($app, array $config) use ($centralConnection) {
102+
$manager->extend('database', function ($_app, array $config) use ($centralConnection) {
104103
$config['connection'] ??= $centralConnection;
105104

106105
/** @var CacheManager $this */
107106
return $this->createDatabaseDriver($config); // @phpstan-ignore method.protected
108107
});
109108

110109
// DatabaseCacheBootstrapper explicitly writes 'tenant' into each store's 'connection'
111-
// config. The database store extend above would then read 'tenant' as the
112-
// configured value (not null) and use it directly, so the central connection fallback
113-
// wouldn't be used.
114-
//
110+
// config. The extend() closure above would then read 'tenant' as the configured value
111+
// (not null) and use it directly, so the central connection fallback wouldn't be used.
115112
// This callback is used to correct those connections back to central for globalCache.
116113
if (static::$adjustCacheManagerUsing !== null) {
117114
(static::$adjustCacheManagerUsing)($manager);

0 commit comments

Comments
 (0)