mirror of
https://github.com/bs-community/blessing-skin-server.git
synced 2025-02-17 14:49:27 +08:00
Support caching options
This commit is contained in:
parent
061c9d7f56
commit
e01f034ffd
36
app/Console/Commands/OptionsCacheCommand.php
Normal file
36
app/Console/Commands/OptionsCacheCommand.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Services\Option;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Filesystem\Filesystem;
|
||||
|
||||
class OptionsCacheCommand extends Command
|
||||
{
|
||||
protected $signature = 'options:cache';
|
||||
|
||||
protected $description = 'Cache Blessing Skin options';
|
||||
|
||||
/** @var Filesystem */
|
||||
protected $filesystem;
|
||||
|
||||
/** @var Option */
|
||||
protected $options;
|
||||
|
||||
public function __construct(Filesystem $filesystem, Option $options)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->filesystem = $filesystem;
|
||||
$this->options = $options;
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$content = var_export($this->options->all(), true);
|
||||
$content = '<?php'.PHP_EOL.'return '.$content.';';
|
||||
$this->filesystem->put(storage_path('options/cache.php'), $content);
|
||||
$this->info('Options cached successfully.');
|
||||
}
|
||||
}
|
@ -17,5 +17,6 @@ class Kernel extends ConsoleKernel
|
||||
Commands\BsInstallCommand::class,
|
||||
Commands\PluginEnableCommand::class,
|
||||
Commands\PluginDisableCommand::class,
|
||||
Commands\OptionsCacheCommand::class,
|
||||
];
|
||||
}
|
||||
|
@ -73,4 +73,9 @@ class Option
|
||||
{
|
||||
return $this->items->has($key);
|
||||
}
|
||||
|
||||
public function all(): array
|
||||
{
|
||||
return $this->items->all();
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@
|
||||
- Plugin system: Added Filters API.
|
||||
- Allow to enable a plugin by running `php artisan plugin:enable {name}`.
|
||||
- Allow to disable a plugin by running `php artisan plugin:disable {name}`.
|
||||
- Allow to cache options by running `php artisan options:cache`.
|
||||
- Support multiple plugins directories. (Splited by comma in ".env" file.)
|
||||
|
||||
## Tweaked
|
||||
|
@ -5,6 +5,7 @@
|
||||
- 插件系统:新增 Filters API
|
||||
- 支持以 `php artisan plugin:enable {name}` 的方式开启插件
|
||||
- 支持以 `php artisan plugin:disable {name}` 的方式关闭插件
|
||||
- 允许通过 `php artisan options:cache` 命令缓存站点选项
|
||||
- 支持指定多个插件目录(在 .env 文件中以逗号分隔)
|
||||
|
||||
## 调整
|
||||
|
2
storage/options/.gitignore
vendored
Normal file
2
storage/options/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
25
tests/CommandsTest/OptionsCacheCommandTest.php
Normal file
25
tests/CommandsTest/OptionsCacheCommandTest.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Filesystem\Filesystem;
|
||||
|
||||
class OptionsCacheCommandTest extends TestCase
|
||||
{
|
||||
public function testRun()
|
||||
{
|
||||
/*$this->mock(Filesystem::class, function ($mock) {
|
||||
$mock->shouldReceive('put')
|
||||
/*->withArgs(function ($path, $content) {
|
||||
$this->assertEquals(storage_path('options/cache.php'), $path);
|
||||
$this->assertTrue(Str::startsWith($content), '<?php');
|
||||
|
||||
return true;
|
||||
})
|
||||
->once();
|
||||
});*/
|
||||
|
||||
$this->artisan('options:cache')->expectsOutput('Options cached successfully.');
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user