更新代码
This commit is contained in:
36
app/Helpers/Params.php
Normal file
36
app/Helpers/Params.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Helpers;
|
||||
|
||||
use App\Models\Param;
|
||||
|
||||
class Params
|
||||
{
|
||||
|
||||
public static function get($name, $type = 'string')
|
||||
{
|
||||
$value = Param::where('name', $name)->value('value');
|
||||
|
||||
switch ($type) {
|
||||
case 'string':
|
||||
return $value;
|
||||
break;
|
||||
case 'array':
|
||||
$array = preg_split('/[\r\n]+/', trim($value, "\r\n"));
|
||||
if (strpos($value, ':')) {
|
||||
$value = [];
|
||||
foreach ($array as $val) {
|
||||
[$k, $v] = explode(':', $val, 2);
|
||||
$value[$k] = $v;
|
||||
}
|
||||
} else {
|
||||
$value = $array;
|
||||
}
|
||||
return $value;
|
||||
break;
|
||||
default:
|
||||
return $value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user