1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @copyright Bluz PHP Team |
5
|
|
|
* @link https://github.com/bluzphp/skeleton |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
declare(strict_types=1); |
9
|
|
|
|
10
|
|
|
namespace Application\Options; |
11
|
|
|
|
12
|
|
|
use Bluz\Db\Exception\DbException; |
|
|
|
|
13
|
|
|
use Bluz\Db\Exception\InvalidPrimaryKeyException; |
|
|
|
|
14
|
|
|
use Bluz\Db\Exception\TableNotFoundException; |
|
|
|
|
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Class Table |
18
|
|
|
* |
19
|
|
|
* @package Application\Options |
20
|
|
|
* |
21
|
|
|
* @method static Row create(array $data = []) |
22
|
|
|
* @method static Row|null findRow($primaryKey) |
23
|
|
|
* @method static Row|null findRowWhere($whereList) |
24
|
|
|
*/ |
25
|
|
|
class Table extends \Bluz\Db\Table |
|
|
|
|
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* Default namespace for all keys |
29
|
|
|
*/ |
30
|
|
|
public const NAMESPACE_DEFAULT = 'default'; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Table |
34
|
|
|
* |
35
|
|
|
* @var string |
36
|
|
|
*/ |
37
|
|
|
protected $name = 'options'; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Primary key(s) |
41
|
|
|
* @var array |
42
|
|
|
*/ |
43
|
|
|
protected $primary = ['namespace', 'key']; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Get option value for use it from any application place |
47
|
|
|
* |
48
|
|
|
* @param string $key |
49
|
|
|
* @param string $namespace |
50
|
|
|
* @return mixed |
51
|
|
|
* @throws DbException |
52
|
|
|
*/ |
53
|
|
|
public static function get(string $key, string $namespace = self::NAMESPACE_DEFAULT) |
54
|
|
|
{ |
55
|
|
|
if ($row = self::findRowWhere(['key' => $key, 'namespace' => $namespace])) { |
56
|
|
|
return $row->value; |
57
|
|
|
} |
58
|
|
|
return null; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Set option value for use it from any application place |
63
|
|
|
* |
64
|
|
|
* @param string $key |
65
|
|
|
* @param mixed $value |
66
|
|
|
* @param string $namespace |
67
|
|
|
* @return mixed |
68
|
|
|
* @throws DbException |
69
|
|
|
* @throws InvalidPrimaryKeyException |
70
|
|
|
* @throws TableNotFoundException |
71
|
|
|
*/ |
72
|
|
|
public static function set(string $key, $value, string $namespace = self::NAMESPACE_DEFAULT) |
73
|
|
|
{ |
74
|
|
|
$row = self::findRowWhere(['key' => $key, 'namespace' => $namespace]); |
75
|
|
|
if (!$row) { |
76
|
|
|
$row = self::create(); |
77
|
|
|
$row->key = $key; |
78
|
|
|
$row->namespace = $namespace; |
79
|
|
|
} |
80
|
|
|
$row->value = $value; |
81
|
|
|
return $row->save(); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Remove option |
86
|
|
|
* |
87
|
|
|
* @param string $key |
88
|
|
|
* @param string $namespace |
89
|
|
|
* @return integer |
90
|
|
|
* @throws DbException |
91
|
|
|
*/ |
92
|
|
|
public static function remove(string $key, string $namespace = self::NAMESPACE_DEFAULT) |
93
|
|
|
{ |
94
|
|
|
return self::delete(['key' => $key, 'namespace' => $namespace]); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths