@@ -1,19 +1,19 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Copyright (C) 2016 Tony Murray <[email protected]> |
|
| 4 | - * This program is free software: you can redistribute it and/or modify |
|
| 5 | - * it under the terms of the GNU General Public License as published by |
|
| 6 | - * the Free Software Foundation, either version 3 of the License, or |
|
| 7 | - * (at your option) any later version. |
|
| 8 | - * |
|
| 9 | - * This program is distributed in the hope that it will be useful, |
|
| 10 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 11 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the |
|
| 12 | - * GNU General Public License for more details. |
|
| 13 | - * |
|
| 14 | - * You should have received a copy of the GNU General Public License |
|
| 15 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
| 16 | - */ |
|
| 3 | + * Copyright (C) 2016 Tony Murray <[email protected]> |
|
| 4 | + * This program is free software: you can redistribute it and/or modify |
|
| 5 | + * it under the terms of the GNU General Public License as published by |
|
| 6 | + * the Free Software Foundation, either version 3 of the License, or |
|
| 7 | + * (at your option) any later version. |
|
| 8 | + * |
|
| 9 | + * This program is distributed in the hope that it will be useful, |
|
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the |
|
| 12 | + * GNU General Public License for more details. |
|
| 13 | + * |
|
| 14 | + * You should have received a copy of the GNU General Public License |
|
| 15 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
| 16 | + */ |
|
| 17 | 17 | |
| 18 | 18 | namespace App\Http\Controllers; |
| 19 | 19 | |
@@ -17,8 +17,6 @@ |
||
| 17 | 17 | |
| 18 | 18 | namespace App\Http\Controllers; |
| 19 | 19 | |
| 20 | -use App\Http\Requests; |
|
| 21 | -use App\Models\DbConfig; |
|
| 22 | 20 | use Illuminate\Http\Request; |
| 23 | 21 | use Settings; |
| 24 | 22 | |
@@ -15,13 +15,13 @@ |
||
| 15 | 15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | 16 | */ |
| 17 | 17 | /** |
| 18 | - * DatabaseRepository.php |
|
| 19 | - * |
|
| 20 | - * @package LibreNMS |
|
| 21 | - * @author Tony Murray <[email protected]> |
|
| 22 | - * @copyright 2016 Tony Murray |
|
| 23 | - * @license @license http://opensource.org/licenses/GPL-3.0 GNU Public License v3 or later |
|
| 24 | - */ |
|
| 18 | + * DatabaseRepository.php |
|
| 19 | + * |
|
| 20 | + * @package LibreNMS |
|
| 21 | + * @author Tony Murray <[email protected]> |
|
| 22 | + * @copyright 2016 Tony Murray |
|
| 23 | + * @license @license http://opensource.org/licenses/GPL-3.0 GNU Public License v3 or later |
|
| 24 | + */ |
|
| 25 | 25 | namespace App\Settings; |
| 26 | 26 | |
| 27 | 27 | |
@@ -32,11 +32,17 @@ discard block |
||
| 32 | 32 | { |
| 33 | 33 | // 'config_name', 'config_value' |
| 34 | 34 | |
| 35 | + /** |
|
| 36 | + * @param string $key |
|
| 37 | + */ |
|
| 35 | 38 | public function has($key) |
| 36 | 39 | { |
| 37 | 40 | return DbConfig::exactKey($key)->exists(); |
| 38 | 41 | } |
| 39 | 42 | |
| 43 | + /** |
|
| 44 | + * @param string $key |
|
| 45 | + */ |
|
| 40 | 46 | public function get($key, $default = null) |
| 41 | 47 | { |
| 42 | 48 | $results = DbConfig::key($key)->get(['config_name', 'config_value']); |
@@ -100,6 +106,9 @@ discard block |
||
| 100 | 106 | return $ret; |
| 101 | 107 | } |
| 102 | 108 | |
| 109 | + /** |
|
| 110 | + * @param \Illuminate\Database\Eloquent\Collection $objs |
|
| 111 | + */ |
|
| 103 | 112 | private function objsToArray($objs) |
| 104 | 113 | { |
| 105 | 114 | $ret = array(); |
@@ -26,7 +26,6 @@ |
||
| 26 | 26 | |
| 27 | 27 | |
| 28 | 28 | use App\Models\DbConfig; |
| 29 | -use App\Models\Notification; |
|
| 30 | 29 | |
| 31 | 30 | class DatabaseRepository |
| 32 | 31 | { |
@@ -45,7 +45,7 @@ |
||
| 45 | 45 | } |
| 46 | 46 | elseif (count($results) == 1) { |
| 47 | 47 | $entry = $results->first(); |
| 48 | - if($entry->config_name != $key) { //FIXME: better test |
|
| 48 | + if ($entry->config_name != $key) { //FIXME: better test |
|
| 49 | 49 | // trim the prefix |
| 50 | 50 | $local_key = substr($entry->config_name, strlen($key) + 1); |
| 51 | 51 | return [$local_key => $entry->config_value]; |
@@ -42,8 +42,7 @@ discard block |
||
| 42 | 42 | $results = DbConfig::key($key)->get(['config_name', 'config_value']); |
| 43 | 43 | if (count($results) > 1) { |
| 44 | 44 | return $this->collectionToArray($results); |
| 45 | - } |
|
| 46 | - elseif (count($results) == 1) { |
|
| 45 | + } elseif (count($results) == 1) { |
|
| 47 | 46 | $entry = $results->first(); |
| 48 | 47 | if($entry->config_name != $key) { //FIXME: better test |
| 49 | 48 | // trim the prefix |
@@ -53,8 +52,7 @@ discard block |
||
| 53 | 52 | |
| 54 | 53 | $value = $entry->config_value; |
| 55 | 54 | return is_null($value) ? $default : $value; |
| 56 | - } |
|
| 57 | - else { |
|
| 55 | + } else { |
|
| 58 | 56 | return $default; |
| 59 | 57 | } |
| 60 | 58 | } |
@@ -64,13 +64,13 @@ discard block |
||
| 64 | 64 | $value = $this->database->get($key, $default); |
| 65 | 65 | if (is_array($value)) { |
| 66 | 66 | $value = self::pathToArray($value, $key); |
| 67 | - $config = Config::get('config.' . $key, $default); |
|
| 67 | + $config = Config::get('config.'.$key, $default); |
|
| 68 | 68 | if (!is_null($config)) { |
| 69 | 69 | $value = array_replace_recursive($config, $value); |
| 70 | 70 | } |
| 71 | 71 | } |
| 72 | 72 | elseif (is_null($value)) { |
| 73 | - $value = Config::get('config.' . $key); |
|
| 73 | + $value = Config::get('config.'.$key); |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | //FIXME: insert cache |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | return array_replace_recursive($config_settings, $db_settings); |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | - protected static function pathToArray($data, $prefix="") |
|
| 104 | + protected static function pathToArray($data, $prefix = "") |
|
| 105 | 105 | { |
| 106 | 106 | $tree = array(); |
| 107 | 107 | foreach ($data as $key => $value) { |
@@ -120,15 +120,15 @@ discard block |
||
| 120 | 120 | return $tree; |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | - protected static function arrayToPath($array, $prefix="") |
|
| 123 | + protected static function arrayToPath($array, $prefix = "") |
|
| 124 | 124 | { |
| 125 | 125 | return self::recursive_keys($array, $prefix); |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | - private static function recursive_keys(array $array, $prefix="", array $path = array()) |
|
| 128 | + private static function recursive_keys(array $array, $prefix = "", array $path = array()) |
|
| 129 | 129 | { |
| 130 | 130 | if ($prefix != "") { |
| 131 | - $prefix = trim($prefix, '.') . '.'; |
|
| 131 | + $prefix = trim($prefix, '.').'.'; |
|
| 132 | 132 | } |
| 133 | 133 | $result = array(); |
| 134 | 134 | foreach ($array as $key => $val) { |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | $result = array_merge($result, self::recursive_keys($val, $prefix, $currentPath)); |
| 138 | 138 | } |
| 139 | 139 | else { |
| 140 | - $result[$prefix . join('.', $currentPath)] = $val; |
|
| 140 | + $result[$prefix.join('.', $currentPath)] = $val; |
|
| 141 | 141 | } |
| 142 | 142 | } |
| 143 | 143 | return $result; |
@@ -49,8 +49,7 @@ discard block |
||
| 49 | 49 | $this->database->set($k, $v); |
| 50 | 50 | // Cache::put($key, $v); |
| 51 | 51 | } |
| 52 | - } |
|
| 53 | - else { |
|
| 52 | + } else { |
|
| 54 | 53 | $this->database->set($key, $value); |
| 55 | 54 | } |
| 56 | 55 | // Cache::put($key, $v); |
@@ -68,8 +67,7 @@ discard block |
||
| 68 | 67 | if (!is_null($config)) { |
| 69 | 68 | $value = array_replace_recursive($config, $value); |
| 70 | 69 | } |
| 71 | - } |
|
| 72 | - elseif (is_null($value)) { |
|
| 70 | + } elseif (is_null($value)) { |
|
| 73 | 71 | $value = Config::get('config.' . $key); |
| 74 | 72 | } |
| 75 | 73 | |
@@ -135,8 +133,7 @@ discard block |
||
| 135 | 133 | $currentPath = array_merge($path, array($key)); |
| 136 | 134 | if (is_array($val)) { |
| 137 | 135 | $result = array_merge($result, self::recursive_keys($val, $prefix, $currentPath)); |
| 138 | - } |
|
| 139 | - else { |
|
| 136 | + } else { |
|
| 140 | 137 | $result[$prefix . join('.', $currentPath)] = $val; |
| 141 | 138 | } |
| 142 | 139 | } |
@@ -49,7 +49,7 @@ |
||
| 49 | 49 | |
| 50 | 50 | public function scopeKey($query, $key) |
| 51 | 51 | { |
| 52 | - return $query->where('config_name', 'LIKE', $key . '%'); |
|
| 52 | + return $query->where('config_name', 'LIKE', $key.'%'); |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | public function scopeExactKey($query, $key) |