diff --git a/CHANGELOG.md b/CHANGELOG.md index efab393..62331c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to `glorand/laravel-model-settings` will be documented in this file +## 3.3.1 - 2019-09-04 +### Added +- Laravel 6 support + ## 3.3.0 - 2019-08-29 ### Added - Default settings on Model diff --git a/composer.json b/composer.json index 127fe00..41a8662 100644 --- a/composer.json +++ b/composer.json @@ -18,16 +18,20 @@ ], "require": { "php": ">=7.1.3", - "illuminate/config": "~5.5.0|~5.6.0|~5.7.0|~5.8.0", - "illuminate/database": "~5.5.0|~5.6.0|~5.7.0|~5.8.0", - "illuminate/support": "~5.5.0|~5.6.0|~5.7.0|~5.8.0", - "illuminate/console": "~5.5.0|~5.6.0|~5.7.0|~5.8.0", - "illuminate/filesystem": "~5.5.0|~5.6.0|~5.7.0|~5.8.0" + "illuminate/config": "~5.5.0|~5.6.0|~5.7.0|~5.8.0|^6.0", + "illuminate/database": "~5.5.0|~5.6.0|~5.7.0|~5.8.0|^6.0", + "illuminate/support": "~5.5.0|~5.6.0|~5.7.0|~5.8.0|^6.0", + "illuminate/console": "~5.5.0|~5.6.0|~5.7.0|~5.8.0|^6.0", + "illuminate/filesystem": "~5.5.0|~5.6.0|~5.7.0|~5.8.0|^6.0" }, "require-dev": { - "phpunit/phpunit": "^7.5", - "orchestra/testbench": "~3.8.0", - "friendsofphp/php-cs-fixer": "^2.16@dev" + "phpunit/phpunit": "^7.5|^8.0", + "orchestra/testbench": "~3.8.0|^4.0", + "friendsofphp/php-cs-fixer": "^2.16@dev", + "predis/predis": "^1.1" + }, + "suggest": { + "predis/predis": "Required to use settings with Redis" }, "autoload": { "psr-4": { @@ -51,5 +55,6 @@ ] } }, - "minimum-stability": "dev" + "minimum-stability": "dev", + "prefer-stable": true } diff --git a/src/Managers/AbstractSettingsManager.php b/src/Managers/AbstractSettingsManager.php index 5536baa..3c72e28 100644 --- a/src/Managers/AbstractSettingsManager.php +++ b/src/Managers/AbstractSettingsManager.php @@ -6,6 +6,7 @@ use Glorand\Model\Settings\Exceptions\ModelSettingsException; use Glorand\Model\Settings\Traits\HasSettings; use Illuminate\Database\Eloquent\Model; +use Illuminate\Support\Arr; /** * Class AbstractSettingsManager @@ -46,7 +47,7 @@ public function all(): array */ public function has(string $path): bool { - return array_has($this->all(), $path); + return Arr::has($this->all(), $path); } /** @@ -56,7 +57,7 @@ public function has(string $path): bool */ public function get(string $path = null, $default = null) { - return $path ? array_get($this->all(), $path, $default) : $this->all(); + return $path ? Arr::get($this->all(), $path, $default) : $this->all(); } /** @@ -100,9 +101,25 @@ public function setMultiple(iterable $values): SettingsManagerContract { $settings = $this->all(); foreach ($values as $path => $value) { - array_set($settings, $path, $value); + Arr::set($settings, $path, $value); } return $this->apply($settings); } + + /** + * @param iterable $paths + * @return \Glorand\Model\Settings\Contracts\SettingsManagerContract + */ + public function deleteMultiple(iterable $paths): SettingsManagerContract + { + $settings = $this->all(); + foreach ($paths as $path) { + Arr::forget($settings, $path); + } + + $this->apply($settings); + + return $this; + } } diff --git a/src/Managers/FieldSettingsManager.php b/src/Managers/FieldSettingsManager.php index 9692d51..a4b62b8 100644 --- a/src/Managers/FieldSettingsManager.php +++ b/src/Managers/FieldSettingsManager.php @@ -3,6 +3,7 @@ namespace Glorand\Model\Settings\Managers; use Glorand\Model\Settings\Contracts\SettingsManagerContract; +use Illuminate\Support\Arr; /** * Class FieldSettingsManager @@ -35,23 +36,7 @@ public function delete(string $path = null): SettingsManagerContract $settings = []; } else { $settings = $this->all(); - array_forget($settings, $path); - } - - $this->apply($settings); - - return $this; - } - - /** - * @param iterable $paths - * @return \Glorand\Model\Settings\Contracts\SettingsManagerContract - */ - public function deleteMultiple(iterable $paths): SettingsManagerContract - { - $settings = $this->all(); - foreach ($paths as $path) { - array_forget($settings, $path); + Arr::forget($settings, $path); } $this->apply($settings); @@ -67,7 +52,7 @@ public function deleteMultiple(iterable $paths): SettingsManagerContract public function set(string $path, $value): SettingsManagerContract { $settings = $this->all(); - array_set($settings, $path, $value); + Arr::set($settings, $path, $value); return $this->apply($settings); } diff --git a/src/Managers/TableSettingsManager.php b/src/Managers/TableSettingsManager.php index c4dbe6f..0c92cb2 100644 --- a/src/Managers/TableSettingsManager.php +++ b/src/Managers/TableSettingsManager.php @@ -4,6 +4,7 @@ use Glorand\Model\Settings\Contracts\SettingsManagerContract; use Glorand\Model\Settings\Models\ModelSettings; +use Illuminate\Support\Arr; /** * Class TableSettingsManager @@ -42,29 +43,13 @@ public function delete(string $path = null): SettingsManagerContract } } else { $settings = $this->all(); - array_forget($settings, $path); + Arr::forget($settings, $path); $this->apply($settings); } return $this; } - /** - * @param iterable $paths - * @return \Glorand\Model\Settings\Contracts\SettingsManagerContract - */ - public function deleteMultiple(iterable $paths): SettingsManagerContract - { - $settings = $this->all(); - foreach ($paths as $path) { - array_forget($settings, $path); - } - - $this->apply($settings); - - return $this; - } - /** * @param string $path * @param mixed $value @@ -73,7 +58,7 @@ public function deleteMultiple(iterable $paths): SettingsManagerContract public function set(string $path, $value): SettingsManagerContract { $settings = $this->all(); - array_set($settings, $path, $value); + Arr::set($settings, $path, $value); return $this->apply($settings); } diff --git a/src/Traits/HasSettings.php b/src/Traits/HasSettings.php index 35ed779..6b68d29 100644 --- a/src/Traits/HasSettings.php +++ b/src/Traits/HasSettings.php @@ -2,6 +2,7 @@ namespace Glorand\Model\Settings\Traits; +use Glorand\Model\Settings\Managers\AbstractSettingsManager; use Illuminate\Support\Arr; trait HasSettings @@ -15,8 +16,7 @@ public function getDefaultSettings(): array return []; } - /** - * @return array - */ abstract public function getSettingsValue(): array; + + abstract public function settings(): AbstractSettingsManager; } diff --git a/src/Traits/HasSettingsField.php b/src/Traits/HasSettingsField.php index 89a9d49..c0abe8f 100644 --- a/src/Traits/HasSettingsField.php +++ b/src/Traits/HasSettingsField.php @@ -5,6 +5,7 @@ use Glorand\Model\Settings\Contracts\SettingsManagerContract; use Glorand\Model\Settings\Exceptions\ModelSettingsException; use Glorand\Model\Settings\Managers\FieldSettingsManager; +use Illuminate\Support\Arr; /** * Trait HasSettingsField @@ -36,7 +37,7 @@ public function getSettingsValue(): array { $settingsFieldName = $this->getSettingsFieldName(); $attributes = $this->getAttributes(); - if (!array_has($attributes, $settingsFieldName)) { + if (!Arr::has($attributes, $settingsFieldName)) { throw new ModelSettingsException("Unknown field ($settingsFieldName) on table {$this->getTable()}"); } diff --git a/tests/FieldSettingsManagerTest.php b/tests/FieldSettingsManagerTest.php index c7fdba1..824b031 100644 --- a/tests/FieldSettingsManagerTest.php +++ b/tests/FieldSettingsManagerTest.php @@ -2,6 +2,7 @@ namespace Glorand\Model\Settings\Tests; +use Glorand\Model\Settings\Exceptions\ModelSettingsException; use Glorand\Model\Settings\Tests\Models\UserWithField as User; use Glorand\Model\Settings\Traits\HasSettingsField; @@ -54,12 +55,10 @@ public function testDefaultValue() $this->assertEquals($this->model->settings()->all(), array_merge($this->defaultSettingsTestArray, $this->testArray)); } - /** - * @expectedException \Glorand\Model\Settings\Exceptions\ModelSettingsException - * @expectedExceptionMessage Unknown field - */ public function testSettingsMissingSettingsField() { + $this->expectException(ModelSettingsException::class); + $this->expectExceptionMessage('Unknown field'); $this->model->settingsFieldName = 'test'; $this->model->settings()->all(); } diff --git a/tests/TestCase.php b/tests/TestCase.php index 56b0fb7..2b3499b 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -10,6 +10,7 @@ use Glorand\Model\Settings\Tests\Models\UserWithField; use Glorand\Model\Settings\Tests\Models\WrongUser; use Illuminate\Database\Schema\Blueprint; +use Illuminate\Support\Arr; use Illuminate\Support\Facades\Schema; use Orchestra\Testbench\TestCase as OrchestraTestCase; @@ -26,7 +27,7 @@ public function setUp(): void protected function checkRequirements() { collect($this->getAnnotations())->filter(function ($location) { - return in_array('!Travis', array_get($location, 'requires', [])); + return in_array('!Travis', Arr::get($location, 'requires', [])); })->each(function ($location) { $this->markTestSkipped('Travis will not run this test.'); }); diff --git a/tests/TestWrongModelTest.php b/tests/TestWrongModelTest.php index e32b4db..ba240d8 100644 --- a/tests/TestWrongModelTest.php +++ b/tests/TestWrongModelTest.php @@ -2,6 +2,7 @@ namespace Glorand\Model\Settings\Tests; +use Glorand\Model\Settings\Exceptions\ModelSettingsException; use Glorand\Model\Settings\Managers\FieldSettingsManager; use Glorand\Model\Settings\Tests\Models\WrongUser; use Glorand\Model\Settings\Tests\Models\WrongUserWithField; @@ -9,21 +10,19 @@ class TestWrongModelTest extends TestCase { /** - * @throws \Exception - * @expectedException \Glorand\Model\Settings\Exceptions\ModelSettingsException - * @expectedExceptionMessage missing HasSettings + * @throws \Glorand\Model\Settings\Exceptions\ModelSettingsException */ public function testSettingsFieldUndefined() { + $this->expectException(ModelSettingsException::class); + $this->expectExceptionMessage('missing HasSettings'); new FieldSettingsManager(WrongUser::first()); } - /** - * @expectedException \Glorand\Model\Settings\Exceptions\ModelSettingsException - * @expectedExceptionMessage Unknown field - */ public function testSettingsMissingSettingsField() { + $this->expectException(ModelSettingsException::class); + $this->expectExceptionMessage('Unknown field'); $model = WrongUserWithField::first(); $model->settings()->all(); }