mirror of
https://github.com/archtechx/tenancy.git
synced 2026-08-06 04:54:04 +00:00
improve comments
This commit is contained in:
parent
c76ae9ed68
commit
9f344bf81d
3 changed files with 13 additions and 15 deletions
|
|
@ -18,11 +18,11 @@ use Stancl\Tenancy\Contracts\Tenant;
|
|||
* Makes cache tenant-aware by applying a prefix.
|
||||
*
|
||||
* Using this bootstrapper together with DatabaseTenancyBootstrapper
|
||||
* with a database cache store results in double scoping. The store is scoped by
|
||||
* DB connection (entries go into the tenant's database) *and* by the prefix. This is
|
||||
* harmless for most use cases, but can produce unexpected behavior.
|
||||
* with a database cache store will result in "double scoping". The store will be scoped
|
||||
* by the DB connection (entries will go into the tenant's database) *and* by the prefix.
|
||||
* This is harmless in most cases, but is important to be aware of.
|
||||
*
|
||||
* If you're using a database cache store, use DatabaseCacheBootstrapper instead of this one.
|
||||
* If you only use database cache stores, consider using DatabaseCacheBootstrapper instead.
|
||||
*
|
||||
* @see Stancl\Tenancy\Bootstrappers\DatabaseCacheBootstrapper
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -21,14 +21,15 @@ use Stancl\Tenancy\TenancyServiceProvider;
|
|||
*
|
||||
* By default, this bootstrapper scopes ALL cache stores that use the database driver. If you only
|
||||
* want to scope SOME stores, set the static $stores property to an array of names of the stores
|
||||
* you want to scope. These stores must use 'database' as their driver.
|
||||
* you want to scope. Those stores must use 'database' as their driver.
|
||||
*
|
||||
* Notably, this bootstrapper sets TenancyServiceProvider::$adjustCacheManagerUsing to a callback
|
||||
* that ensures all affected stores still use the central connection when accessed via global cache
|
||||
* (typically the GlobalCache facade or global_cache() helper), even though this bootstrapper explicitly
|
||||
* sets the connection to tenant for all scoped cache stores. Extending database store on the global cache manager
|
||||
* cannot fix globalCache on its own because it reads 'tenant' from config (set by this bootstrapper), not null,
|
||||
* so the callback is still needed to correct the connection to central for globalCache.
|
||||
* (typically the GlobalCache facade or global_cache() helper). The code in TenancyServiceProvider
|
||||
* that uses `extend()` callbacks to make database stores on the global cache manager use the central
|
||||
* connection only corrects stores scoped by the Database*Tenancy*Bootstrapper. This bootstrapper
|
||||
* also changes the stores' connection in the *config* to 'tenant' which doesn't let that callback
|
||||
* change the connection back to central on the global cache manager.
|
||||
*/
|
||||
class DatabaseCacheBootstrapper implements TenancyBootstrapper
|
||||
{
|
||||
|
|
|
|||
|
|
@ -99,8 +99,7 @@ class TenancyServiceProvider extends ServiceProvider
|
|||
// config is null fall back to the default DB connection ('tenant'). Reset each
|
||||
// such store to its explicitly configured connection, or fall back to central.
|
||||
$centralConnection = $app['config']['tenancy.database.central_connection'];
|
||||
|
||||
$manager->extend('database', function ($app, array $config) use ($centralConnection) {
|
||||
$manager->extend('database', function ($_app, array $config) use ($centralConnection) {
|
||||
$config['connection'] ??= $centralConnection;
|
||||
|
||||
/** @var CacheManager $this */
|
||||
|
|
@ -108,10 +107,8 @@ class TenancyServiceProvider extends ServiceProvider
|
|||
});
|
||||
|
||||
// DatabaseCacheBootstrapper explicitly writes 'tenant' into each store's 'connection'
|
||||
// config. The database store extend above would then read 'tenant' as the
|
||||
// configured value (not null) and use it directly, so the central connection fallback
|
||||
// wouldn't be used.
|
||||
//
|
||||
// config. The extend() closure above would then read 'tenant' as the configured value
|
||||
// (not null) and use it directly, so the central connection fallback wouldn't be used.
|
||||
// This callback is used to correct those connections back to central for globalCache.
|
||||
if (static::$adjustCacheManagerUsing !== null) {
|
||||
(static::$adjustCacheManagerUsing)($manager);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue