mirror of
https://github.com/archtechx/tenancy.git
synced 2026-06-20 22:04:02 +00:00
Improve comments
This commit is contained in:
parent
20036ef1ff
commit
566f50440a
2 changed files with 19 additions and 13 deletions
|
|
@ -25,7 +25,10 @@ use Stancl\Tenancy\TenancyServiceProvider;
|
|||
*
|
||||
* Notably, this bootstrapper sets TenancyServiceProvider::$adjustCacheManagerUsing to a callback
|
||||
* that ensures all affected stores still use the central connection when accessed via global cache
|
||||
* (typicaly the GlobalCache facade or global_cache() helper).
|
||||
* (typically the GlobalCache facade or global_cache() helper), even though this bootstrapper explicitly
|
||||
* sets the connection to tenant for all scoped cache stores. TenancyServiceProvider::makeDatabaseCacheStoresCentral()
|
||||
* 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.
|
||||
*/
|
||||
class DatabaseCacheBootstrapper implements TenancyBootstrapper
|
||||
{
|
||||
|
|
|
|||
|
|
@ -88,23 +88,26 @@ class TenancyServiceProvider extends ServiceProvider
|
|||
// This works great for cache stores that are *directly* scoped, like Redis or
|
||||
// any other tagged or prefixed stores, but it doesn't work for the database driver.
|
||||
//
|
||||
// When we use the DatabaseTenancyBootstrapper, it changes the default connection,
|
||||
// and therefore the connection of the database store that will be created when
|
||||
// this new CacheManager is instantiated again.
|
||||
// When DatabaseTenancyBootstrapper is used, it changes the default DB connection
|
||||
// to 'tenant'. A freshly created CacheManager would therefore instantiate database
|
||||
// stores with the tenant connection.
|
||||
//
|
||||
// For that reason, we also adjust the relevant stores on this new CacheManager
|
||||
// using the callback below. It is set by DatabaseCacheBootstrapper.
|
||||
// For that reason, we adjust the relevant stores on this new CacheManager
|
||||
// using the makeDatabaseCacheStoresCentral() method and the $adjustCacheManagerUsing callback below
|
||||
// (set by DatabaseCacheBootstrapper).
|
||||
$manager = new CacheManager($app);
|
||||
|
||||
// Make globalCache use either the configured non-null connection,
|
||||
// or fall back to the central connection.
|
||||
// When DatabaseTenancyBootstrapper is used, database stores whose 'connection'
|
||||
// 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.
|
||||
$this->makeDatabaseCacheStoresCentral($manager);
|
||||
|
||||
// If a bootstrapper (like DatabaseCacheBootstrapper) makes the
|
||||
// cache connection tenant explicitly, the makeDatabaseCacheStoresCentral()
|
||||
// call ends up setting the tenant connection rather than the central one,
|
||||
// and the $adjustCacheManagerUsing callback is needed to
|
||||
// make globalCache use the central connection.
|
||||
// DatabaseCacheBootstrapper explicitly writes 'tenant' into each store's 'connection'
|
||||
// config. makeDatabaseCacheStoresCentral() 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