Skip to content

Commit b13b523

Browse files
committed
add missing getInstance, return excpected type when empty, check isset
1 parent 344c0d7 commit b13b523

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/components/Storage.php

+13-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,17 @@ class Storage extends Component
2121
{
2222
protected $_path;
2323
protected $_locker;
24+
25+
protected static $_instance;
26+
27+
public static function getInstance()
28+
{
29+
if (static::$_instance === null) {
30+
static::$_instance = new static();
31+
}
32+
33+
return static::$_instance;
34+
}
2435

2536
public function init()
2637
{
@@ -105,7 +116,7 @@ public function readPackage(AssetPackage $package)
105116
$name = $package->getNormalName();
106117
$path = $this->buildHashedPath($name);
107118
if (!file_exists($path)) {
108-
return [];
119+
return null;
109120
}
110121
$json = file_get_contents($path);
111122
$updateTime = filemtime($path);
@@ -135,7 +146,7 @@ protected function writeProviderLatest($name, $hash)
135146
if (file_exists($latest_path)) {
136147
$data = Json::decode(file_get_contents($latest_path) ?: '[]');
137148
}
138-
if (!is_array($data)) {
149+
if (!isset($data)||!is_array($data)) {
139150
$data = [];
140151
}
141152
if (!isset($data['providers'])) {

0 commit comments

Comments
 (0)