mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-04 19:24:02 +00:00
Merge branch '1.x' into telescope-tags
This commit is contained in:
commit
f23fd125b1
9 changed files with 112 additions and 6 deletions
|
|
@ -1,5 +1,11 @@
|
|||
# Release Notes for 1.x
|
||||
|
||||
## [v1.6.0 (2019-07-30)](https://github.com/stancl/tenancy/compare/v1.5.1...v1.6.0)
|
||||
|
||||
### Added
|
||||
|
||||
- `GlobalCache` facade [#78](https://github.com/stancl/tenancy/pull/78)
|
||||
|
||||
## [v1.5.1 (2019-07-25)](https://github.com/stancl/tenancy/compare/v1.5.0...v1.5.1)
|
||||
|
||||
### Fixed
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
# Tenancy
|
||||
# [stancl/tenancy](https://stancl.github.io/tenancy/)
|
||||
|
||||
[](https://laravel.com)
|
||||
[](https://packagist.org/packages/stancl/tenancy)
|
||||
|
|
@ -20,7 +20,7 @@ You won't have to change a thing in your application's code.\*
|
|||
<details>
|
||||
<summary><strong>Click to expand/collapse</strong></summary>
|
||||
|
||||
- [Tenancy](#tenancy)
|
||||
- [stancl/tenancy](#stancltenancy)
|
||||
+ [*A Laravel multi-database tenancy package that respects your code.*](#-a-laravel-multi-database-tenancy-package-that-respects-your-code-)
|
||||
- [Installation](#installation)
|
||||
+ [Requirements](#requirements)
|
||||
|
|
@ -392,8 +392,9 @@ Connections listed in the `tenancy.redis.prefixed_connections` config array use
|
|||
|
||||
## Cache
|
||||
|
||||
Both `cache()` and `Cache` will use `Stancl\Tenancy\CacheManager`, which adds a tag (`prefix_base` + tenant UUID) to all methods called on it.
|
||||
Both the `cache()` helper and the `Cache` facade will use `Stancl\Tenancy\CacheManager`, which adds a tag (`prefix_base` + tenant UUID) to all methods called on it.
|
||||
|
||||
If you need to store something in global, non-tenant cache, you can use the `GlobalCache` facade the same way you'd use the `Cache` facade.
|
||||
|
||||
## Filesystem/Storage
|
||||
|
||||
|
|
@ -475,6 +476,8 @@ Storage::disk('public')->put($filename, $data);
|
|||
Storage::disk('local')->put("public/$filename", $data);
|
||||
```
|
||||
|
||||
If you want to store something globally, simply create a new disk and *don't* add it to the `tenancy.filesystem.disks` config.
|
||||
|
||||
## Artisan commands
|
||||
|
||||
```
|
||||
|
|
|
|||
|
|
@ -41,7 +41,8 @@
|
|||
"Stancl\\Tenancy\\TenancyServiceProvider"
|
||||
],
|
||||
"aliases": {
|
||||
"Tenancy": "Stancl\\Tenancy\\TenancyFacade"
|
||||
"Tenancy": "Stancl\\Tenancy\\TenancyFacade",
|
||||
"GlobalCache": "Stancl\\Tenancy\\GlobalCacheFacade"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@
|
|||
<php>
|
||||
<env name="APP_ENV" value="testing"/>
|
||||
<env name="BCRYPT_ROUNDS" value="4"/>
|
||||
<env name="CACHE_DRIVER" value="array"/>
|
||||
<env name="CACHE_DRIVER" value="redis"/>
|
||||
<env name="MAIL_DRIVER" value="array"/>
|
||||
<env name="QUEUE_CONNECTION" value="sync"/>
|
||||
<env name="SESSION_DRIVER" value="array"/>
|
||||
|
|
|
|||
13
src/GlobalCacheFacade.php
Normal file
13
src/GlobalCacheFacade.php
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
namespace Stancl\Tenancy;
|
||||
|
||||
use Illuminate\Support\Facades\Facade;
|
||||
|
||||
class GlobalCacheFacade extends Facade
|
||||
{
|
||||
protected static function getFacadeAccessor()
|
||||
{
|
||||
return 'globalCache';
|
||||
}
|
||||
}
|
||||
|
|
@ -13,6 +13,7 @@ use Illuminate\Support\ServiceProvider;
|
|||
use Stancl\Tenancy\Commands\TenantList;
|
||||
use Stancl\Tenancy\Interfaces\StorageDriver;
|
||||
use Stancl\Tenancy\Interfaces\ServerConfigManager;
|
||||
use Illuminate\Cache\CacheManager;
|
||||
|
||||
class TenancyServiceProvider extends ServiceProvider
|
||||
{
|
||||
|
|
@ -83,5 +84,9 @@ class TenancyServiceProvider extends ServiceProvider
|
|||
$this->app->singleton(Seed::class, function ($app) {
|
||||
return new Seed($app['db'], $app[DatabaseManager::class]);
|
||||
});
|
||||
|
||||
$this->app->bind('globalCache', function ($app) {
|
||||
return new CacheManager($app);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,4 +73,36 @@ class CacheManagerTest extends TestCase
|
|||
cache(['foo' => 'xyz'], 1);
|
||||
$this->assertSame('xyz', cache('foo'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function cache_is_persisted()
|
||||
{
|
||||
tenant()->create('foo.localhost');
|
||||
tenancy()->init('foo.localhost');
|
||||
|
||||
cache(['foo' => 'bar'], 10);
|
||||
$this->assertSame('bar', cache('foo'));
|
||||
|
||||
tenancy()->end();
|
||||
|
||||
tenancy()->init('foo.localhost');
|
||||
$this->assertSame('bar', cache('foo'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function cache_is_persisted_when_reidentification_is_used()
|
||||
{
|
||||
tenant()->create('foo.localhost');
|
||||
tenant()->create('bar.localhost');
|
||||
tenancy()->init('foo.localhost');
|
||||
|
||||
cache(['foo' => 'bar'], 10);
|
||||
$this->assertSame('bar', cache('foo'));
|
||||
|
||||
tenancy()->init('bar.localhost');
|
||||
tenancy()->end();
|
||||
|
||||
tenancy()->init('foo.localhost');
|
||||
$this->assertSame('bar', cache('foo'));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
43
tests/GlobalCacheTest.php
Normal file
43
tests/GlobalCacheTest.php
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
namespace Stancl\Tenancy\Tests;
|
||||
|
||||
use GlobalCache;
|
||||
|
||||
class GlobalCacheTest extends TestCase
|
||||
{
|
||||
public $autoCreateTenant = false;
|
||||
public $autoInitTenancy = false;
|
||||
|
||||
/** @test */
|
||||
public function global_cache_manager_stores_data_in_global_cache()
|
||||
{
|
||||
$this->assertSame(null, cache('foo'));
|
||||
GlobalCache::put(['foo' => 'bar'], 1);
|
||||
$this->assertSame('bar', GlobalCache::get('foo'));
|
||||
|
||||
tenant()->create('foo.localhost');
|
||||
tenancy()->init('foo.localhost');
|
||||
$this->assertSame('bar', GlobalCache::get('foo'));
|
||||
|
||||
GlobalCache::put(['abc' => 'xyz'], 1);
|
||||
cache(['def' => 'ghi'], 10);
|
||||
$this->assertSame('ghi', cache('def'));
|
||||
|
||||
tenancy()->end();
|
||||
$this->assertSame('xyz', GlobalCache::get('abc'));
|
||||
$this->assertSame('bar', GlobalCache::get('foo'));
|
||||
$this->assertSame(null, cache('def'));
|
||||
|
||||
tenant()->create('bar.localhost');
|
||||
tenancy()->init('bar.localhost');
|
||||
$this->assertSame('xyz', GlobalCache::get('abc'));
|
||||
$this->assertSame('bar', GlobalCache::get('foo'));
|
||||
$this->assertSame(null, cache('def'));
|
||||
cache(['def' => 'xxx'], 1);
|
||||
$this->assertSame('xxx', cache('def'));
|
||||
|
||||
tenancy()->init('foo.localhost');
|
||||
$this->assertSame('ghi', cache('def'));
|
||||
}
|
||||
}
|
||||
|
|
@ -19,6 +19,7 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase
|
|||
parent::setUp();
|
||||
|
||||
Redis::connection('tenancy')->flushdb();
|
||||
Redis::connection('cache')->flushdb();
|
||||
|
||||
if ($this->autoCreateTenant) {
|
||||
$this->createTenant();
|
||||
|
|
@ -77,6 +78,7 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase
|
|||
's3',
|
||||
],
|
||||
'tenancy.redis.tenancy' => true,
|
||||
'tenancy.redis.prefixed_connections' => ['default'],
|
||||
'tenancy.migrations_directory' => database_path('../migrations'),
|
||||
]);
|
||||
}
|
||||
|
|
@ -98,7 +100,8 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase
|
|||
protected function getPackageAliases($app)
|
||||
{
|
||||
return [
|
||||
'Tenancy' => \Stancl\Tenancy\TenancyFacade::class
|
||||
'Tenancy' => \Stancl\Tenancy\TenancyFacade::class,
|
||||
'GlobalCache' => \Stancl\Tenancy\GlobalCacheFacade::class,
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue