From 555126699272f2f6f8070c4cdb572f50c96a3a1f Mon Sep 17 00:00:00 2001 From: Mohd Saqueib Ansari Date: Thu, 5 Sep 2019 21:36:11 +0800 Subject: [PATCH] laravel 6 support --- .travis.yml | 2 +- CHANGELOG.md | 4 ++++ composer.json | 8 +++---- src/Setting/AppSettings.php | 24 ++++++++++--------- src/helpers.php | 8 ++++--- src/resources/views/_settings.blade.php | 8 +++---- .../views/fields/_boolean_radio.blade.php | 12 +++++----- .../views/fields/_description.blade.php | 6 ++--- src/resources/views/fields/_file.blade.php | 14 +++++------ src/resources/views/fields/_hint.blade.php | 4 ++-- src/resources/views/fields/_label.blade.php | 4 ++-- src/resources/views/fields/_select.blade.php | 6 ++--- src/resources/views/fields/_text.blade.php | 14 +++++------ src/resources/views/fields/boolean.blade.php | 2 +- src/resources/views/fields/checkbox.blade.php | 2 +- .../views/fields/checkbox_group.blade.php | 6 ++--- src/resources/views/fields/textarea.blade.php | 12 +++++----- src/resources/views/input_group.blade.php | 2 +- src/resources/views/section.blade.php | 10 ++++---- 19 files changed, 78 insertions(+), 70 deletions(-) diff --git a/.travis.yml b/.travis.yml index 936bf1d..d99681c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: php php: - - 7.1 + - 7.2 before_script: - travis_retry composer self-update diff --git a/CHANGELOG.md b/CHANGELOG.md index 67987a0..2a22572 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to `qcod/laravel-app-settings` will be documented in this file +## 1.2.0 - 2019-09-05 + +- Laravel 6 support + ## 1.1.0 - 2019-08-14 - Group Settings by name diff --git a/composer.json b/composer.json index 2011277..0be4a6a 100644 --- a/composer.json +++ b/composer.json @@ -21,14 +21,14 @@ } ], "require": { - "php": ">=5.6.0", - "laravel/framework": "~5.4.0|~5.5.0|~5.6.0|~5.7.0|~5.8.0", + "php": "^7.2", + "laravel/framework": "~5.4.0|~5.5.0|~5.6.0|~5.7.0|~5.8.0|^6.0", "qcod/laravel-settings": "~1.0" }, "require-dev": { - "orchestra/testbench": "~3.4", + "orchestra/testbench": "~3.4|^4.0", "mockery/mockery": "^0.9.4 || ~1.0", - "phpunit/phpunit": "~7.0" + "phpunit/phpunit": "~8.0" }, "autoload": { "psr-4": { diff --git a/src/Setting/AppSettings.php b/src/Setting/AppSettings.php index cef48c5..c6fe655 100644 --- a/src/Setting/AppSettings.php +++ b/src/Setting/AppSettings.php @@ -2,6 +2,8 @@ namespace QCod\AppSettings\Setting; +use Illuminate\Support\Arr; +use Illuminate\Support\Str; use Illuminate\Http\Request; use Illuminate\Support\Facades\Storage; use QCod\Settings\Setting\SettingStorage; @@ -55,14 +57,14 @@ public function get($name, $default = null) // get the setting and fallback to default value from config $value = $this->settingStorage->get( $name, - array_get($settingField, 'value', $default) + Arr::get($settingField, 'value', $default) ); // cast the value - $outValue = $this->castValue(array_get($settingField, 'data_type'), $value, true); + $outValue = $this->castValue(Arr::get($settingField, 'data_type'), $value, true); // check for accessor to run - if ($accessor = array_get($settingField, 'accessor')) { + if ($accessor = Arr::get($settingField, 'accessor')) { $outValue = $this->runCallback($accessor, $name, $value); } @@ -79,12 +81,12 @@ public function get($name, $default = null) public function set($name, $value) { $settingField = $this->getSettingField($name); - $dataType = array_get($settingField, 'data_type'); + $dataType = Arr::get($settingField, 'data_type'); $val = $this->castValue($dataType, $value); // check for mutator to run - if ($mutator = array_get($settingField, 'mutator')) { + if ($mutator = Arr::get($settingField, 'mutator')) { $val = $this->runCallback($mutator, $name, $value); } @@ -142,7 +144,7 @@ public function loadConfig($config) array_walk_recursive($config, function (&$value, $key) { if (!in_array($key, ['mutator', 'accessor', 'rules']) && is_callable($value)) { // skip any string which dont look like namesapce - if (is_string($value) && str_contains($value, '\\') == false) { + if (is_string($value) && Str::contains($value, '\\') == false) { return; } @@ -171,7 +173,7 @@ protected function getSettingUISections() public function getAllSettingFields() { return $this->getSettingUISections()->flatMap(function ($field) { - return array_get($field, 'inputs', []); + return Arr::get($field, 'inputs', []); }); } @@ -185,7 +187,7 @@ public function getSettingField($name) { return $this->getAllSettingFields() ->first(function ($field) use ($name) { - return array_get($field, 'name') == $name; + return Arr::get($field, 'name') == $name; }, []); } @@ -301,11 +303,11 @@ private function castToArray($value, $out) */ private function uploadFile($setting, $request) { - $settingName = array_get($setting, 'name'); + $settingName = Arr::get($setting, 'name'); // get the disk and path to upload - $disk = array_get($setting, 'disk', 'public'); - $path = array_get($setting, 'path', '/'); + $disk = Arr::get($setting, 'disk', 'public'); + $path = Arr::get($setting, 'path', '/'); $uploadedPath = null; $oldFile = $this->get($settingName); diff --git a/src/helpers.php b/src/helpers.php index dd5bf51..c385b84 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -11,14 +11,16 @@ */ function setting($key = null, $default = null) { + $settings = app()->make('app-settings'); + if (is_null($key)) { - return app()->make('app-settings'); + return $settings; } if (is_array($key)) { - return app()->make('app-settings')->set($key); + return $settings->set($key); } - return app()->make('app-settings')->get($key, value($default)); + return $settings->get($key, value($default)); } } diff --git a/src/resources/views/_settings.blade.php b/src/resources/views/_settings.blade.php index 7aa62cc..601e3e7 100644 --- a/src/resources/views/_settings.blade.php +++ b/src/resources/views/_settings.blade.php @@ -9,10 +9,10 @@ @if( isset($settingsUI) && count($settingsUI) ) - @foreach(array_get($settingsUI, 'sections', []) as $section => $fields) + @foreach(Arr::get($settingsUI, 'sections', []) as $section => $fields) @component('app_settings::section', compact('fields')) -
- @foreach(array_get($fields, 'inputs', []) as $field) +
+ @foreach(Arr::get($fields, 'inputs', []) as $field) @if(!view()->exists('app_settings::fields.' . $field['type']))
Defined setting {{ $field['name'] }} with @@ -30,7 +30,7 @@
diff --git a/src/resources/views/fields/_boolean_radio.blade.php b/src/resources/views/fields/_boolean_radio.blade.php index c282ddb..d6e066e 100644 --- a/src/resources/views/fields/_boolean_radio.blade.php +++ b/src/resources/views/fields/_boolean_radio.blade.php @@ -4,9 +4,9 @@ id="{{ $field['name'] }}" type="radio" name="{{ $field['name'] }}" - value="{{ array_get($field, 'true_value', '1') }}" - @if(setting($field['name']) == array_get($field, 'true_value', '1')) checked @endif> - {{ array_get($field, 'true_label', 'Yes') }} + value="{{ Arr::get($field, 'true_value', '1') }}" + @if(setting($field['name']) == Arr::get($field, 'true_value', '1')) checked @endif> + {{ Arr::get($field, 'true_label', 'Yes') }}
@@ -14,8 +14,8 @@ - {{ array_get($field, 'false_label', 'No') }} + value="{{ Arr::get($field, 'false_value', '0') }}" + @if(setting($field['name']) == Arr::get($field, 'false_value', '0')) checked @endif> + {{ Arr::get($field, 'false_label', 'No') }}
diff --git a/src/resources/views/fields/_description.blade.php b/src/resources/views/fields/_description.blade.php index c6f7e89..a92d277 100644 --- a/src/resources/views/fields/_description.blade.php +++ b/src/resources/views/fields/_description.blade.php @@ -1,10 +1,10 @@ -@if( $sub_title = array_get($field, 'sub_title')) +@if( $sub_title = Arr::get($field, 'sub_title'))

{{ $sub_title }}

- @if($desc = array_get($field, 'desc')) + @if($desc = Arr::get($field, 'desc'))

{{ $desc }}

@endif
-@endif \ No newline at end of file +@endif diff --git a/src/resources/views/fields/_file.blade.php b/src/resources/views/fields/_file.blade.php index 4210f32..2265438 100644 --- a/src/resources/views/fields/_file.blade.php +++ b/src/resources/views/fields/_file.blade.php @@ -3,23 +3,23 @@
@if( $filePath = \setting($field['name'])) - @php $fileUrl = \Storage::disk(array_get($field, 'disk', 'public'))->url($filePath) @endphp + @php $fileUrl = \Storage::disk(Arr::get($field, 'disk', 'public'))->url($filePath) @endphp @if(in_array(pathinfo($filePath, PATHINFO_EXTENSION), ["gif", "jpg", "jpeg", "png", "tiff", "tif"])) - {{ $field['name'] }} + {{ $field['name'] }} @else View {{ $field['label'] }} diff --git a/src/resources/views/fields/_hint.blade.php b/src/resources/views/fields/_hint.blade.php index e3cac81..e6a281a 100644 --- a/src/resources/views/fields/_hint.blade.php +++ b/src/resources/views/fields/_hint.blade.php @@ -1,5 +1,5 @@ -@if($hint = array_get($field, 'hint')) - +@if($hint = Arr::get($field, 'hint')) + {{ $hint }} @endif diff --git a/src/resources/views/fields/_label.blade.php b/src/resources/views/fields/_label.blade.php index edddd5e..a19f137 100644 --- a/src/resources/views/fields/_label.blade.php +++ b/src/resources/views/fields/_label.blade.php @@ -1,3 +1,3 @@ -@if( $label = array_get($field, 'label') ) - +@if( $label = Arr::get($field, 'label') ) + @endif diff --git a/src/resources/views/fields/_select.blade.php b/src/resources/views/fields/_select.blade.php index d8d62e1..ca75073 100644 --- a/src/resources/views/fields/_select.blade.php +++ b/src/resources/views/fields/_select.blade.php @@ -3,11 +3,11 @@ @endphp - @if( $append = array_get($field, 'append')) + @if( $append = Arr::get($field, 'append')) {{ $append }} @endif diff --git a/src/resources/views/fields/boolean.blade.php b/src/resources/views/fields/boolean.blade.php index 583b74b..8708030 100644 --- a/src/resources/views/fields/boolean.blade.php +++ b/src/resources/views/fields/boolean.blade.php @@ -1,5 +1,5 @@ @component('app_settings::input_group', compact('field')) - @if( count(array_get($field, 'options', [])) ) + @if( count(Arr::get($field, 'options', [])) ) @include('app_settings::fields._select') @else
diff --git a/src/resources/views/fields/checkbox.blade.php b/src/resources/views/fields/checkbox.blade.php index c046f55..8a4f563 100644 --- a/src/resources/views/fields/checkbox.blade.php +++ b/src/resources/views/fields/checkbox.blade.php @@ -1,7 +1,7 @@
diff --git a/src/resources/views/fields/checkbox_group.blade.php b/src/resources/views/fields/checkbox_group.blade.php index 88085d2..e9daf99 100644 --- a/src/resources/views/fields/checkbox_group.blade.php +++ b/src/resources/views/fields/checkbox_group.blade.php @@ -6,8 +6,8 @@ @foreach($field['options'] as $option)
@php - $checkbox_value = array_get($option, 'value', $option, []); - $checkbox_label = array_get($option, 'label', $option, []); + $checkbox_value = Arr::get($option, 'value', $option, []); + $checkbox_label = Arr::get($option, 'label', $option, []); $current_value = old($field['name'], \setting($field['name'], [])); @endphp diff --git a/src/resources/views/fields/textarea.blade.php b/src/resources/views/fields/textarea.blade.php index 2aa9058..cca4c36 100644 --- a/src/resources/views/fields/textarea.blade.php +++ b/src/resources/views/fields/textarea.blade.php @@ -2,18 +2,18 @@ @endcomponent diff --git a/src/resources/views/input_group.blade.php b/src/resources/views/input_group.blade.php index 24d5aec..bf81f0d 100644 --- a/src/resources/views/input_group.blade.php +++ b/src/resources/views/input_group.blade.php @@ -1,4 +1,4 @@ -
+
@include('app_settings::fields._label') {{ $slot }} diff --git a/src/resources/views/section.blade.php b/src/resources/views/section.blade.php index 346447d..358095f 100644 --- a/src/resources/views/section.blade.php +++ b/src/resources/views/section.blade.php @@ -1,11 +1,11 @@ -
-
- +
+
+ {{ $fields['title'] }}
- @if( $desc = array_get($fields, 'descriptions') ) -
+ @if( $desc = Arr::get($fields, 'descriptions') ) +

{{ $desc }}

@endif