Skip to content

Commit

Permalink
Updating the package (#23)
Browse files Browse the repository at this point in the history
* Allow to install laravel 6 minor releases
 * Updating service provider + defer
 * Removing the facade
 * Refactoring/Cleaning
  • Loading branch information
arcanedev-maroc authored Oct 2, 2019
1 parent 2089e2a commit c4bb764
Show file tree
Hide file tree
Showing 12 changed files with 73 additions and 130 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
language: php

sudo: false

php:
- 7.2
- 7.3
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion _docs/0-Home.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
37 changes: 18 additions & 19 deletions _docs/1-Installation-and-Setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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

Expand Down
2 changes: 0 additions & 2 deletions _docs/3-Usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ class RandomNameClass
}
```

You can also use the `Arcanedev\LaravelSettings\Facades\Settings` façade or whatever.

```php
<?php

Expand Down
14 changes: 7 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
"license": "MIT",
"require": {
"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": {
Expand Down
10 changes: 10 additions & 0 deletions src/Contracts/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
20 changes: 0 additions & 20 deletions src/Facades/Settings.php

This file was deleted.

68 changes: 11 additions & 57 deletions src/SettingsManager.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<?php namespace Arcanedev\LaravelSettings;

use Illuminate\Support\Arr;
use Illuminate\Support\Manager;
use Arcanedev\LaravelSettings\Contracts\Manager as SettingsManagerContract;
use Illuminate\Support\{Arr, Manager};

/**
* Class SettingsManager
Expand Down Expand Up @@ -36,68 +35,23 @@ class SettingsManager extends Manager implements SettingsManagerContract
*/
public function getDefaultDriver()
{
return $this->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', []),
]);
});
}
}
33 changes: 18 additions & 15 deletions src/SettingsServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
<?php namespace Arcanedev\LaravelSettings;

use Arcanedev\Support\PackageServiceProvider;
use Arcanedev\LaravelSettings\Contracts\Manager as ManagerContract;
use Arcanedev\Support\Providers\PackageServiceProvider;
use Illuminate\Contracts\Support\DeferrableProvider;

/**
* Class SettingsServiceProvider
*
* @package Arcanedev\LaravelSettings
* @author ARCANEDEV <[email protected]>
*/
class SettingsServiceProvider extends PackageServiceProvider
class SettingsServiceProvider extends PackageServiceProvider implements DeferrableProvider
{
/* -----------------------------------------------------------------
| Properties
Expand All @@ -30,7 +32,7 @@ class SettingsServiceProvider extends PackageServiceProvider
/**
* Register the service provider.
*/
public function register()
public function register(): void
{
parent::register();

Expand All @@ -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();
Expand All @@ -56,7 +56,7 @@ public function boot()
*
* @return array
*/
public function provides()
public function provides(): array
{
return [
Contracts\Manager::class,
Expand All @@ -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;
});
}
}
6 changes: 3 additions & 3 deletions src/Stores/AbstractStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions tests/SettingsServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
];

Expand Down

0 comments on commit c4bb764

Please sign in to comment.