diff --git a/.travis.yml b/.travis.yml index af3785d..fe6c2a7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,5 @@ language: php -sudo: false - php: - 7.2 - 7.3 diff --git a/README.md b/README.md index a5fc5e5..3b4b8f0 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Feel free to check out the [releases](https://github.com/ARCANEDEV/LaravelSettin ### Features - * Laravel `5.2` to `6.0` are supported. + * Laravel `5.2` to `6.x` are supported. * Multiple store drivers: `array`, `json`, `database`, `redis`. * Easy setup & configuration. * Well documented & IDE Friendly. @@ -45,7 +45,7 @@ Any ideas are welcome. Feel free to submit any issues or pull requests, please c - [All Contributors][link-contributors] [badge_license]: https://img.shields.io/packagist/l/arcanedev/laravel-settings.svg?style=flat-square -[badge_laravel]: https://img.shields.io/badge/Laravel-5.2%20to%206.0-orange.svg?style=flat-square +[badge_laravel]: https://img.shields.io/badge/Laravel-5.2%20to%206.x-orange.svg?style=flat-square [badge_build]: https://img.shields.io/travis/ARCANEDEV/LaravelSettings.svg?style=flat-square [badge_coverage]: https://img.shields.io/scrutinizer/coverage/g/ARCANEDEV/LaravelSettings.svg?style=flat-square [badge_quality]: https://img.shields.io/scrutinizer/g/ARCANEDEV/LaravelSettings.svg?style=flat-square diff --git a/_docs/0-Home.md b/_docs/0-Home.md index 3ee5a67..79b58c7 100644 --- a/_docs/0-Home.md +++ b/_docs/0-Home.md @@ -6,7 +6,7 @@ Feel free to check out the [releases](https://github.com/ARCANEDEV/LaravelSettin ### Features - * Laravel `5.2` to `6.0` are supported. + * Laravel `5.2` to `6.x` are supported. * Multiple store drivers: `array`, `json`, `database`, `redis`. * Easy setup & configuration. * Well documented & IDE Friendly. diff --git a/_docs/1-Installation-and-Setup.md b/_docs/1-Installation-and-Setup.md index 901dd84..b363c34 100644 --- a/_docs/1-Installation-and-Setup.md +++ b/_docs/1-Installation-and-Setup.md @@ -8,15 +8,15 @@ ## Version Compatibility -| LaravelSettings | Laravel | -|:--------------------------------------------------|:----------------------------------------------------------| -| ![LaravelSettings v0.x][laravel_settings_0_x] | ![Laravel v5.2][laravel_5_2] ![Laravel v5.3][laravel_5_3] | -| ![LaravelSettings v1.x][laravel_settings_1_x] | ![Laravel v5.4][laravel_5_4] | -| ![LaravelSettings v2.x][laravel_settings_2_x] | ![Laravel v5.5][laravel_5_5] | -| ![LaravelSettings v3.x][laravel_settings_3_x] | ![Laravel v5.6][laravel_5_6] | -| ![LaravelSettings v4.x][laravel_settings_4_x] | ![Laravel v5.7][laravel_5_7] | -| ![LaravelSettings v5.x][laravel_settings_5_x] | ![Laravel v5.8][laravel_5_8] | -| ![LaravelSettings v6.0.x][laravel_settings_6_0_x] | ![Laravel v6.0][laravel_6_0] | +| LaravelSettings | Laravel | +|:----------------------------------------------|:----------------------------------------------------------| +| ![LaravelSettings v0.x][laravel_settings_0_x] | ![Laravel v5.2][laravel_5_2] ![Laravel v5.3][laravel_5_3] | +| ![LaravelSettings v1.x][laravel_settings_1_x] | ![Laravel v5.4][laravel_5_4] | +| ![LaravelSettings v2.x][laravel_settings_2_x] | ![Laravel v5.5][laravel_5_5] | +| ![LaravelSettings v3.x][laravel_settings_3_x] | ![Laravel v5.6][laravel_5_6] | +| ![LaravelSettings v4.x][laravel_settings_4_x] | ![Laravel v5.7][laravel_5_7] | +| ![LaravelSettings v5.x][laravel_settings_5_x] | ![Laravel v5.8][laravel_5_8] | +| ![LaravelSettings v6.x][laravel_settings_6_x] | ![Laravel v6.x][laravel_6_x] | [laravel_5_2]: https://img.shields.io/badge/v5.2-supported-brightgreen.svg?style=flat-square "Laravel v5.2" [laravel_5_3]: https://img.shields.io/badge/v5.3-supported-brightgreen.svg?style=flat-square "Laravel v5.3" @@ -25,16 +25,15 @@ [laravel_5_6]: https://img.shields.io/badge/v5.6-supported-brightgreen.svg?style=flat-square "Laravel v5.6" [laravel_5_7]: https://img.shields.io/badge/v5.7-supported-brightgreen.svg?style=flat-square "Laravel v5.7" [laravel_5_8]: https://img.shields.io/badge/v5.8-supported-brightgreen.svg?style=flat-square "Laravel v5.8" -[laravel_5_8]: https://img.shields.io/badge/v5.8-supported-brightgreen.svg?style=flat-square "Laravel v5.8" -[laravel_6_0]: https://img.shields.io/badge/v6.0-supported-brightgreen.svg?style=flat-square "Laravel v6.0" - -[laravel_settings_0_x]: https://img.shields.io/badge/version-0.*-blue.svg?style=flat-square "LaravelSettings v0.*" -[laravel_settings_1_x]: https://img.shields.io/badge/version-1.*-blue.svg?style=flat-square "LaravelSettings v1.*" -[laravel_settings_2_x]: https://img.shields.io/badge/version-2.*-blue.svg?style=flat-square "LaravelSettings v2.*" -[laravel_settings_3_x]: https://img.shields.io/badge/version-3.*-blue.svg?style=flat-square "LaravelSettings v3.*" -[laravel_settings_4_x]: https://img.shields.io/badge/version-4.*-blue.svg?style=flat-square "LaravelSettings v4.*" -[laravel_settings_5_x]: https://img.shields.io/badge/version-5.*-blue.svg?style=flat-square "LaravelSettings v5.*" -[laravel_settings_6_0_x]: https://img.shields.io/badge/version-6.0.*-blue.svg?style=flat-square "LaravelSettings v6.0.*" +[laravel_6_x]: https://img.shields.io/badge/v6.x-supported-brightgreen.svg?style=flat-square "Laravel v6.x" + +[laravel_settings_0_x]: https://img.shields.io/badge/version-0.x-blue.svg?style=flat-square "LaravelSettings v0.x" +[laravel_settings_1_x]: https://img.shields.io/badge/version-1.x-blue.svg?style=flat-square "LaravelSettings v1.x" +[laravel_settings_2_x]: https://img.shields.io/badge/version-2.x-blue.svg?style=flat-square "LaravelSettings v2.x" +[laravel_settings_3_x]: https://img.shields.io/badge/version-3.x-blue.svg?style=flat-square "LaravelSettings v3.x" +[laravel_settings_4_x]: https://img.shields.io/badge/version-4.x-blue.svg?style=flat-square "LaravelSettings v4.x" +[laravel_settings_5_x]: https://img.shields.io/badge/version-5.x-blue.svg?style=flat-square "LaravelSettings v5.x" +[laravel_settings_6_x]: https://img.shields.io/badge/version-6.x-blue.svg?style=flat-square "LaravelSettings v6.x" ## Composer diff --git a/_docs/3-Usage.md b/_docs/3-Usage.md index 6251504..20fedb5 100644 --- a/_docs/3-Usage.md +++ b/_docs/3-Usage.md @@ -50,8 +50,6 @@ class RandomNameClass } ``` -You can also use the `Arcanedev\LaravelSettings\Facades\Settings` façade or whatever. - ```php =7.2.0", - "arcanedev/support": "~5.0.0" + "ext-json": "*", + "arcanedev/support": "^5.0" }, "require-dev": { - "orchestra/testbench": "~4.0.0", - "mockery/mockery": "~1.2", - "phpunit/phpunit": "~8.0", - "phpunit/phpcov": "~6.0", - "predis/predis": "~1.1", - "illuminate/redis": "~6.0.0" + "orchestra/testbench": "^4.0", + "mockery/mockery": "^1.2", + "phpunit/phpunit": "^8.0", + "phpunit/phpcov": "^6.0", + "predis/predis": "^1.1" }, "autoload": { "psr-4": { diff --git a/src/Contracts/Manager.php b/src/Contracts/Manager.php index 6ae0142..a87e014 100644 --- a/src/Contracts/Manager.php +++ b/src/Contracts/Manager.php @@ -52,4 +52,14 @@ public function driver($driver = null); * @return \Arcanedev\LaravelSettings\Contracts\Manager */ public function extend($driver, Closure $callback); + + /** + * Register a new store. + * + * @param string $driver + * @param array $params + * + * @return \Arcanedev\LaravelSettings\Contracts\Manager + */ + public function registerStore(string $driver, array $params); } diff --git a/src/Facades/Settings.php b/src/Facades/Settings.php deleted file mode 100644 index 0b339f1..0000000 --- a/src/Facades/Settings.php +++ /dev/null @@ -1,20 +0,0 @@ - - */ -class Settings extends Facade -{ - /** - * Get the registered name of the component. - * - * @return string - */ - protected static function getFacadeAccessor() { return Manager::class; } -} diff --git a/src/SettingsManager.php b/src/SettingsManager.php index b603215..3e4fe55 100644 --- a/src/SettingsManager.php +++ b/src/SettingsManager.php @@ -1,8 +1,7 @@ config()->get('settings.default', 'json'); + return $this->container['config']->get('settings.default', 'json'); } - /* ----------------------------------------------------------------- - | Constructor - | ----------------------------------------------------------------- - */ - - /** - * SettingsManager constructor. - * - * @param \Illuminate\Foundation\Application $app - */ - public function __construct($app) - { - parent::__construct($app); - - foreach ($this->getConfig('drivers') as $driver => $configs) { - $this->registerDriver($driver, $configs); - } - } - - /* ----------------------------------------------------------------- - | Other Methods - | ----------------------------------------------------------------- - */ - /** - * Get the config repository. - * - * @return \Illuminate\Contracts\Config\Repository - */ - private function config() - { - return $this->app['config']; - } - - /** - * Get the package configs. - * - * @param string $key - * @param mixed|null $default - * - * @return mixed - */ - private function getConfig($key, $default = null) - { - return $this->config()->get("settings.{$key}", $default); - } - - /** - * Register the driver. + * Register a new store. * * @param string $driver - * @param array $configs + * @param array $params + * + * @return \Arcanedev\LaravelSettings\SettingsManager */ - private function registerDriver($driver, array $configs) + public function registerStore(string $driver, array $params) { - $this->extend($driver, function () use ($configs) { - return new $configs['driver']( - $this->app, Arr::get($configs, 'options', []) - ); + return $this->extend($driver, function () use ($params) { + return $this->container->make($params['driver'], [ + 'options' => Arr::get($params, 'options', []), + ]); }); } } diff --git a/src/SettingsServiceProvider.php b/src/SettingsServiceProvider.php index 07d2092..08e3f31 100644 --- a/src/SettingsServiceProvider.php +++ b/src/SettingsServiceProvider.php @@ -1,6 +1,8 @@ */ -class SettingsServiceProvider extends PackageServiceProvider +class SettingsServiceProvider extends PackageServiceProvider implements DeferrableProvider { /* ----------------------------------------------------------------- | Properties @@ -30,7 +32,7 @@ class SettingsServiceProvider extends PackageServiceProvider /** * Register the service provider. */ - public function register() + public function register(): void { parent::register(); @@ -42,10 +44,8 @@ public function register() /** * Boot the service provider. */ - public function boot() + public function boot(): void { - parent::boot(); - $this->publishConfig(); SettingsManager::$runsMigrations ? $this->loadMigrations() : $this->publishMigrations(); @@ -56,7 +56,7 @@ public function boot() * * @return array */ - public function provides() + public function provides(): array { return [ Contracts\Manager::class, @@ -70,19 +70,22 @@ public function provides() */ /** - * Register the Settings Manager. + * Register the Settings Manager & Store drivers. */ - private function registerSettingsManager() + private function registerSettingsManager(): void { - $this->singleton(Contracts\Manager::class, function ($app) { - return new SettingsManager($app); - }); + $this->singleton(ManagerContract::class, SettingsManager::class); $this->singleton(Contracts\Store::class, function ($app) { - /** @var \Arcanedev\LaravelSettings\Contracts\Manager $manager */ - $manager = $app[Contracts\Manager::class]; + return $app[ManagerContract::class]->driver(); + }); + + $this->app->extend(ManagerContract::class, function (ManagerContract $manager, $app) { + foreach ($app['config']->get('settings.drivers', []) as $driver => $params) { + $manager->registerStore($driver, $params); + } - return $manager->driver(); + return $manager; }); } } diff --git a/src/Stores/AbstractStore.php b/src/Stores/AbstractStore.php index e681a24..1dda369 100644 --- a/src/Stores/AbstractStore.php +++ b/src/Stores/AbstractStore.php @@ -121,9 +121,8 @@ public function set($key, $value = null) Arr::set($this->data, $k, $v); } } - else { + else Arr::set($this->data, $key, $value); - } return $this; } @@ -222,7 +221,8 @@ public function isSaved() */ protected function checkLoaded() { - if ($this->isLoaded()) return; + if ($this->isLoaded()) + return; $this->data = $this->read(); $this->loaded = true; diff --git a/tests/SettingsServiceProviderTest.php b/tests/SettingsServiceProviderTest.php index e2e584e..5c38b73 100644 --- a/tests/SettingsServiceProviderTest.php +++ b/tests/SettingsServiceProviderTest.php @@ -40,8 +40,9 @@ public function it_can_be_instantiated() { $expectations = [ \Illuminate\Support\ServiceProvider::class, - \Arcanedev\Support\ServiceProvider::class, - \Arcanedev\Support\PackageServiceProvider::class, + \Illuminate\Contracts\Support\DeferrableProvider::class, + \Arcanedev\Support\Providers\ServiceProvider::class, + \Arcanedev\Support\Providers\PackageServiceProvider::class, \Arcanedev\LaravelSettings\SettingsServiceProvider::class ];