mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 15:54:03 +00:00
[3.x] Use static properties instead of config for features (#391)
* Use static properites instead of config for features * update tests
This commit is contained in:
parent
3bb2759fe2
commit
c2c90ff755
4 changed files with 14 additions and 13 deletions
|
|
@ -231,9 +231,6 @@ return [
|
||||||
// Stancl\Tenancy\Features\TelescopeTags::class, // https://tenancy.samuelstancl.me/docs/v2/telescope/
|
// Stancl\Tenancy\Features\TelescopeTags::class, // https://tenancy.samuelstancl.me/docs/v2/telescope/
|
||||||
// Stancl\Tenancy\Features\CrossDomainRedirect::class, // https://tenancy.samuelstancl.me/docs/v2/features/tenant-redirect/
|
// Stancl\Tenancy\Features\CrossDomainRedirect::class, // https://tenancy.samuelstancl.me/docs/v2/features/tenant-redirect/
|
||||||
],
|
],
|
||||||
'storage_to_config_map' => [ // Used by the TenantConfig feature
|
|
||||||
// 'paypal_api_key' => 'services.paypal.api_key',
|
|
||||||
],
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The URL to which users will be redirected when they try to acceess a central route on a tenant domain.
|
* The URL to which users will be redirected when they try to acceess a central route on a tenant domain.
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,10 @@ class TenantConfig implements Feature
|
||||||
/** @var array */
|
/** @var array */
|
||||||
public $originalConfig = [];
|
public $originalConfig = [];
|
||||||
|
|
||||||
|
public static $storageToConfigMap = [
|
||||||
|
// 'paypal_api_key' => 'services.paypal.api_key',
|
||||||
|
];
|
||||||
|
|
||||||
public function __construct(Repository $config)
|
public function __construct(Repository $config)
|
||||||
{
|
{
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
|
|
@ -56,6 +60,6 @@ class TenantConfig implements Feature
|
||||||
|
|
||||||
public function getStorageToConfigMap(): array
|
public function getStorageToConfigMap(): array
|
||||||
{
|
{
|
||||||
return $this->config['tenancy.storage_to_config_map'] ?? [];
|
return static::$storageToConfigMap;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,8 @@ class Timestamps implements Feature
|
||||||
/** @var Repository */
|
/** @var Repository */
|
||||||
protected $config;
|
protected $config;
|
||||||
|
|
||||||
|
public static $format = 'c'; // ISO 8601
|
||||||
|
|
||||||
public function __construct(Repository $config)
|
public function __construct(Repository $config)
|
||||||
{
|
{
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
|
|
@ -38,9 +40,6 @@ class Timestamps implements Feature
|
||||||
|
|
||||||
public function now(): string
|
public function now(): string
|
||||||
{
|
{
|
||||||
// Add this key to your tenancy.php config if you need to change the format.
|
return Date::now()->format(static::$format);
|
||||||
return Date::now()->format(
|
|
||||||
$this->config->get('tenancy.timestamp_format') ?? 'c' // ISO 8601
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Stancl\Tenancy\Tests\Features;
|
namespace Stancl\Tenancy\Tests\Features;
|
||||||
|
|
||||||
|
use Stancl\Tenancy\Features\TenantConfig;
|
||||||
use Stancl\Tenancy\Tests\TestCase;
|
use Stancl\Tenancy\Tests\TestCase;
|
||||||
|
|
||||||
class TenantConfigTest extends TestCase
|
class TenantConfigTest extends TestCase
|
||||||
|
|
@ -16,12 +17,12 @@ class TenantConfigTest extends TestCase
|
||||||
{
|
{
|
||||||
$this->assertSame(null, config('services.paypal'));
|
$this->assertSame(null, config('services.paypal'));
|
||||||
config([
|
config([
|
||||||
'tenancy.storage_to_config_map' => [
|
'tenancy.features' => [TenantConfig::class],
|
||||||
'paypal_api_public' => 'services.paypal.public',
|
|
||||||
'paypal_api_private' => 'services.paypal.private',
|
|
||||||
],
|
|
||||||
'tenancy.features' => ['Stancl\Tenancy\Features\TenantConfig'],
|
|
||||||
]);
|
]);
|
||||||
|
TenantConfig::$storageToConfigMap = [
|
||||||
|
'paypal_api_public' => 'services.paypal.public',
|
||||||
|
'paypal_api_private' => 'services.paypal.private',
|
||||||
|
];
|
||||||
|
|
||||||
tenancy()->create('foo.localhost', [
|
tenancy()->create('foo.localhost', [
|
||||||
'paypal_api_public' => 'foo',
|
'paypal_api_public' => 'foo',
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue