Skip to content

Commit 947023b

Browse files
authored
Add DynamoDB instruction and remove APC (#159)
1 parent 4042e1e commit 947023b

7 files changed

Lines changed: 122 additions & 69 deletions

File tree

‎app/Filament/Clusters/Settings/Enums/CacheDriver.php‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace App\Filament\Clusters\Settings\Enums;
44

5+
use Composer\InstalledVersions;
56
use Filament\Support\Contracts\HasDescription;
67
use Filament\Support\Contracts\HasLabel;
78

@@ -11,8 +12,6 @@ enum CacheDriver: string implements HasDescription, HasLabel
1112

1213
case Database = 'database';
1314

14-
case APC = 'apc';
15-
1615
case Memcached = 'memcached';
1716

1817
case Redis = 'redis';
@@ -21,11 +20,19 @@ enum CacheDriver: string implements HasDescription, HasLabel
2120

2221
public function getLabel(): string
2322
{
24-
return __(sprintf('setting.cache.%s_driver', $this->value));
23+
return __(sprintf('setting.cache.%s.label', $this->value));
2524
}
2625

2726
public function getDescription(): string
2827
{
29-
return __(sprintf('setting.cache.%s_description', $this->value));
28+
return __(sprintf('setting.cache.%s.description', $this->value));
29+
}
30+
31+
public function isInstalled(): bool
32+
{
33+
return match ($this) {
34+
self::DynamoDB => InstalledVersions::isInstalled('aws/aws-sdk-php'),
35+
default => true,
36+
};
3037
}
3138
}

‎app/Filament/Clusters/Settings/Forms/Cache/DynamoDBForm.php‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,40 @@
22

33
namespace App\Filament\Clusters\Settings\Forms\Cache;
44

5+
use App\Filament\Clusters\Settings\Enums\CacheDriver;
56
use Filament\Forms\Components\TextInput;
7+
use Filament\Schemas\Components\Callout;
68

79
class DynamoDBForm
810
{
911
public static function schema(): array
1012
{
1113
return [
14+
Callout::make(__('setting.cache.dynamodb.no_package_title'))
15+
->description(__('setting.cache.dynamodb.no_package_description'))
16+
->warning()
17+
->hidden(CacheDriver::DynamoDB->isInstalled()),
18+
1219
TextInput::make('cache.stores.dynamodb.key')
13-
->label(__('setting.cache.dynamodb_key'))
20+
->label(__('setting.cache.dynamodb.key'))
1421
->required(),
1522

1623
TextInput::make('cache.stores.dynamodb.secret')
17-
->label(__('setting.cache.dynamodb_secret'))
24+
->label(__('setting.cache.dynamodb.secret'))
1825
->password()
1926
->revealable()
2027
->required(),
2128

2229
TextInput::make('cache.stores.dynamodb.region')
23-
->label(__('setting.cache.dynamodb_region'))
30+
->label(__('setting.cache.dynamodb.region'))
2431
->required(),
2532

2633
TextInput::make('cache.stores.dynamodb.table')
27-
->label(__('setting.cache.dynamodb_table'))
34+
->label(__('setting.cache.dynamodb.table'))
2835
->required(),
2936

3037
TextInput::make('cache.stores.dynamodb.endpoint')
31-
->label(__('setting.cache.dynamodb_endpoint'))
38+
->label(__('setting.cache.dynamodb.endpoint'))
3239
->required(),
3340
];
3441
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace App\Filament\Clusters\Settings\Forms\Cache;
4+
5+
use App\Filament\Clusters\Settings\Enums\CacheDriver;
6+
use Filament\Forms\Components\CheckboxList;
7+
8+
class FailoverForm
9+
{
10+
public static function schema(): array
11+
{
12+
return [
13+
CheckboxList::make('cache.stores.failover.stores')
14+
->options(CacheDriver::class),
15+
];
16+
}
17+
}

‎app/Filament/Clusters/Settings/Forms/Cache/MemcachedForm.php‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,21 @@ public static function schema(): array
1010
{
1111
return [
1212
TextInput::make('cache.stores.memcached.servers.host')
13-
->label(__('setting.cache.memcached_host'))
13+
->label(__('setting.cache.memcached.host'))
1414
->required(),
1515

1616
TextInput::make('cache.stores.memcached.servers.port')
17-
->label(__('setting.cache.memcached_port'))
17+
->label(__('setting.cache.memcached.port'))
1818
->numeric()
1919
->required(),
2020

2121
TextInput::make('cache.stores.memcached.sasl.username')
22-
->label(__('setting.cache.memcached_username'))
22+
->label(__('setting.cache.memcached.username'))
2323
->numeric()
2424
->nullable(),
2525

2626
TextInput::make('cache.stores.memcached.sasl.password')
27-
->label(__('setting.cache.memcached_password'))
27+
->label(__('setting.cache.memcached.password'))
2828
->password()
2929
->revealable()
3030
->nullable(),

‎app/Filament/Clusters/Settings/Forms/Cache/RedisForm.php‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,24 @@ public static function schema(): array
1010
{
1111
return [
1212
TextInput::make('database.redis.cache.host')
13-
->label(__('setting.cache.redis_host'))
13+
->label(__('setting.cache.redis.host'))
1414
->required(),
1515

1616
TextInput::make('database.redis.cache.port')
17-
->label(__('setting.cache.redis_port'))
17+
->label(__('setting.cache.redis.port'))
1818
->required(),
1919

2020
TextInput::make('database.redis.cache.database')
21-
->label(__('setting.cache.redis_database'))
21+
->label(__('setting.cache.redis.database'))
2222
->numeric()
2323
->required(),
2424

2525
TextInput::make('database.redis.cache.username')
26-
->label(__('setting.cache.redis_username'))
26+
->label(__('setting.cache.redis.username'))
2727
->string(),
2828

2929
TextInput::make('database.redis.cache.password')
30-
->label(__('setting.cache.redis_password'))
30+
->label(__('setting.cache.redis.password'))
3131
->string()
3232
->password()
3333
->revealable(),

‎app/Filament/Clusters/Settings/Pages/Cache.php‎

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -120,30 +120,32 @@ public function mount(): void
120120

121121
public function form(Schema $schema): Schema
122122
{
123-
return $schema->schema([
124-
Section::make(__('setting.cache.label'))
125-
->description(__('setting.cache.section_description'))
126-
->schema([
127-
Radio::make('cache.default')
128-
->label(__('setting.cache.driver'))
129-
->options(CacheDriver::class)
130-
->live()
131-
->required()
132-
->enum(CacheDriver::class),
133-
]),
134-
135-
Section::make(__('setting.cache.memcached_driver'))
136-
->visible(fn (Get $get): bool => $get('cache.default') === CacheDriver::Memcached)
137-
->schema(MemcachedForm::schema()),
138-
139-
Section::make(__('setting.cache.redis_driver'))
140-
->visible(fn (Get $get): bool => $get('cache.default') === CacheDriver::Redis)
141-
->schema(RedisForm::schema()),
142-
143-
Section::make(__('setting.cache.dynamodb_driver'))
144-
->visible(fn (Get $get): bool => $get('cache.default') === CacheDriver::DynamoDB)
145-
->schema(DynamoDBForm::schema()),
146-
])
147-
->disabled(user_cannot(CachePermission::Edit));
123+
return $schema
124+
->disabled(user_cannot(CachePermission::Edit))
125+
->schema([
126+
Section::make(__('setting.cache.label'))
127+
->description(__('setting.cache.section_description'))
128+
->schema([
129+
Radio::make('cache.default')
130+
->label(__('setting.cache.driver'))
131+
->options(CacheDriver::class)
132+
->live()
133+
->required()
134+
->enum(CacheDriver::class),
135+
]),
136+
137+
Section::make(__('setting.cache.memcached.label'))
138+
->visible(fn (Get $get): bool => $get('cache.default') === CacheDriver::Memcached)
139+
->schema(MemcachedForm::schema()),
140+
141+
Section::make(__('setting.cache.redis.label'))
142+
->visible(fn (Get $get): bool => $get('cache.default') === CacheDriver::Redis)
143+
->schema(RedisForm::schema()),
144+
145+
Section::make(__('setting.cache.dynamodb.label'))
146+
->visible(fn (Get $get): bool => $get('cache.default') === CacheDriver::DynamoDB)
147+
->disabled(! CacheDriver::DynamoDB->isInstalled())
148+
->schema(DynamoDBForm::schema()),
149+
]);
148150
}
149151
}

‎lang/en/setting.php‎

Lines changed: 46 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -197,39 +197,59 @@
197197
],
198198

199199
'cache' => [
200-
'redis_host' => 'Host',
201-
'redis_port' => 'Port',
202-
'redis_database' => 'Database',
203-
'redis_username' => 'Username',
204-
'redis_password' => 'Password',
205-
'dynamodb_key' => 'Key',
206-
'dynamodb_secret' => 'Secret',
207-
'dynamodb_region' => 'Region',
208-
'dynamodb_table' => 'Table',
209-
'dynamodb_endpoint' => 'Endpoint',
210-
'memcached_host' => 'Host',
211-
'memcached_port' => 'Port',
212-
'memcached_username' => 'Username',
213-
'memcached_password' => 'Password',
214200
'test_success' => 'Test success',
215201
'test_failed' => 'Test failed',
216202
'flushed' => 'Cache flushed',
217203
'section_description' => 'Configure the cache storage used by the application. Supported drivers include File, Database, Memcached, APC, Redis, and DynamoDB.',
218204
'driver' => 'Driver',
219-
'memcached_driver' => 'Memcached',
220-
'redis_driver' => 'Redis',
221-
'dynamodb_driver' => 'DynamoDB',
222205
'label' => 'Cache',
223206
'navigation' => 'Cache',
224-
'file_driver' => 'File',
225-
'database_driver' => 'Database',
226-
'apc_driver' => 'APC',
227-
'file_description' => 'Caching to the local file system',
228-
'database_description' => 'Storing cache in a database table',
229-
'apc_description' => 'In-memory caching using the APC extension',
230-
'memcached_description' => 'Distributed in-memory caching',
231-
'redis_description' => 'Advanced in-memory data structure store',
232-
'dynamodb_description' => 'AWS\'s scalable NoSQL database service',
207+
208+
'file' => [
209+
'label' => 'File',
210+
'description' => 'Caching to the local file system',
211+
],
212+
213+
'database' => [
214+
'label' => 'Database',
215+
'description' => 'Storing cache in a database table',
216+
],
217+
218+
'memcached' => [
219+
'label' => 'Memcached',
220+
'description' => 'Distributed in-memory caching',
221+
'host' => 'Host',
222+
'port' => 'Port',
223+
'username' => 'Username',
224+
'password' => 'Password',
225+
],
226+
227+
'redis' => [
228+
'label' => 'Redis',
229+
'description' => 'Advanced in-memory data structure store',
230+
'host' => 'Host',
231+
'port' => 'Port',
232+
'database' => 'Database',
233+
'username' => 'Username',
234+
'password' => 'Password',
235+
],
236+
237+
'dynamodb' => [
238+
'label' => 'DynamoDB',
239+
'description' => 'AWS\'s scalable NoSQL database service',
240+
'key' => 'Key',
241+
'secret' => 'Secret',
242+
'region' => 'Region',
243+
'table' => 'Table',
244+
'endpoint' => 'Endpoint',
245+
'no_package_title' => 'DynamoDB is not available',
246+
'no_package_description' => 'Please install AWS SDK package using command: composer require aws/aws-sdk-php',
247+
],
248+
249+
'failover' => [
250+
'label' => 'Failover',
251+
'description' => '',
252+
],
233253

234254
'btn' => [
235255
'test' => 'Test cache',

0 commit comments

Comments
 (0)