mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 17:24:03 +00:00
* Specify namespace on global functions (fix #35) * merge * Revert some \ additions * small fixes
This commit is contained in:
parent
35abb6191d
commit
97ec172fd4
6 changed files with 9 additions and 12 deletions
|
|
@ -11,7 +11,7 @@ class CacheManager extends BaseCacheManager
|
||||||
$tags = [config('tenancy.cache.tag_base') . tenant('uuid')];
|
$tags = [config('tenancy.cache.tag_base') . tenant('uuid')];
|
||||||
|
|
||||||
if ($method === "tags") {
|
if ($method === "tags") {
|
||||||
if (count($parameters) !== 1) {
|
if (\count($parameters) !== 1) {
|
||||||
throw new \Exception("Method tags() takes exactly 1 argument. {count($parameters)} passed.");
|
throw new \Exception("Method tags() takes exactly 1 argument. {count($parameters)} passed.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
namespace Stancl\Tenancy;
|
namespace Stancl\Tenancy;
|
||||||
|
|
||||||
use Illuminate\Support\Facades\DB;
|
|
||||||
use Stancl\Tenancy\Jobs\QueuedTenantDatabaseCreator;
|
use Stancl\Tenancy\Jobs\QueuedTenantDatabaseCreator;
|
||||||
use Stancl\Tenancy\Jobs\QueuedTenantDatabaseDeleter;
|
use Stancl\Tenancy\Jobs\QueuedTenantDatabaseDeleter;
|
||||||
use Illuminate\Database\DatabaseManager as BaseDatabaseManager;
|
use Illuminate\Database\DatabaseManager as BaseDatabaseManager;
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,6 @@ use Illuminate\Support\ServiceProvider;
|
||||||
use Stancl\Tenancy\Commands\TenantList;
|
use Stancl\Tenancy\Commands\TenantList;
|
||||||
use Stancl\Tenancy\Interfaces\StorageDriver;
|
use Stancl\Tenancy\Interfaces\StorageDriver;
|
||||||
use Stancl\Tenancy\Interfaces\ServerConfigManager;
|
use Stancl\Tenancy\Interfaces\ServerConfigManager;
|
||||||
use Stancl\Tenancy\StorageDrivers\RedisStorageDriver;
|
|
||||||
|
|
||||||
class TenancyServiceProvider extends ServiceProvider
|
class TenancyServiceProvider extends ServiceProvider
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
namespace Stancl\Tenancy;
|
namespace Stancl\Tenancy;
|
||||||
|
|
||||||
use Illuminate\Support\Facades\Redis;
|
|
||||||
use Stancl\Tenancy\Interfaces\StorageDriver;
|
use Stancl\Tenancy\Interfaces\StorageDriver;
|
||||||
use Stancl\Tenancy\Traits\BootstrapsTenancy;
|
use Stancl\Tenancy\Traits\BootstrapsTenancy;
|
||||||
use Illuminate\Contracts\Foundation\Application;
|
use Illuminate\Contracts\Foundation\Application;
|
||||||
|
|
@ -166,7 +165,7 @@ class TenantManager
|
||||||
public function getDatabaseName($tenant = []): string
|
public function getDatabaseName($tenant = []): string
|
||||||
{
|
{
|
||||||
$tenant = $tenant ?: $this->tenant;
|
$tenant = $tenant ?: $this->tenant;
|
||||||
return config('tenancy.database.prefix') . $tenant['uuid'] . config('tenancy.database.suffix');
|
return $this->app['config']['tenancy.database.prefix'] . $tenant['uuid'] . $this->app['config']['tenancy.database.suffix'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -233,7 +232,7 @@ class TenantManager
|
||||||
{
|
{
|
||||||
$uuid = $uuid ?: $this->tenant['uuid'];
|
$uuid = $uuid ?: $this->tenant['uuid'];
|
||||||
|
|
||||||
if (is_array($key)) {
|
if (\is_array($key)) {
|
||||||
return $this->jsonDecodeArrayValues($this->storage->getMany($uuid, $key));
|
return $this->jsonDecodeArrayValues($this->storage->getMany($uuid, $key));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -250,7 +249,7 @@ class TenantManager
|
||||||
*/
|
*/
|
||||||
public function put($key, $value = null, string $uuid = null)
|
public function put($key, $value = null, string $uuid = null)
|
||||||
{
|
{
|
||||||
if (is_null($uuid)) {
|
if (\is_null($uuid)) {
|
||||||
if (! isset($this->tenant['uuid'])) {
|
if (! isset($this->tenant['uuid'])) {
|
||||||
throw new \Exception("No UUID supplied (and no tenant is currently identified).");
|
throw new \Exception("No UUID supplied (and no tenant is currently identified).");
|
||||||
}
|
}
|
||||||
|
|
@ -264,11 +263,11 @@ class TenantManager
|
||||||
$target = []; // black hole
|
$target = []; // black hole
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! is_null($value)) {
|
if (! \is_null($value)) {
|
||||||
return $target[$key] = json_decode($this->storage->put($uuid, $key, json_encode($value)), true);
|
return $target[$key] = json_decode($this->storage->put($uuid, $key, json_encode($value)), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! is_array($key)) {
|
if (! \is_array($key)) {
|
||||||
throw new \Exception("No value supplied for key $key.");
|
throw new \Exception("No value supplied for key $key.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -310,7 +309,7 @@ class TenantManager
|
||||||
*/
|
*/
|
||||||
public function __invoke($attribute)
|
public function __invoke($attribute)
|
||||||
{
|
{
|
||||||
if (is_null($attribute)) {
|
if (\is_null($attribute)) {
|
||||||
return $this->tenant;
|
return $this->tenant;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ class TenantRouteServiceProvider extends RouteServiceProvider
|
||||||
{
|
{
|
||||||
public function map()
|
public function map()
|
||||||
{
|
{
|
||||||
if (! in_array(request()->getHost(), $this->app['config']['tenancy.exempt_domains'] ?? [])
|
if (! \in_array(request()->getHost(), $this->app['config']['tenancy.exempt_domains'] ?? [])
|
||||||
&& file_exists(base_path('routes/tenant.php'))) {
|
&& file_exists(base_path('routes/tenant.php'))) {
|
||||||
Route::middleware(['web', 'tenancy'])
|
Route::middleware(['web', 'tenancy'])
|
||||||
->namespace($this->app['config']['tenant_route_namespace'] ?? 'App\Http\Controllers')
|
->namespace($this->app['config']['tenant_route_namespace'] ?? 'App\Http\Controllers')
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ trait BootstrapsTenancy
|
||||||
public function setPhpRedisPrefix($connections = ['default'])
|
public function setPhpRedisPrefix($connections = ['default'])
|
||||||
{
|
{
|
||||||
foreach ($connections as $connection) {
|
foreach ($connections as $connection) {
|
||||||
$prefix = config('tenancy.redis.prefix_base') . $this->tenant['uuid'];
|
$prefix = $this->app['config']['tenancy.redis.prefix_base'] . $this->tenant['uuid'];
|
||||||
$client = Redis::connection($connection)->client();
|
$client = Redis::connection($connection)->client();
|
||||||
$client->setOption($client::OPT_PREFIX, $prefix);
|
$client->setOption($client::OPT_PREFIX, $prefix);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue