Skip to content

Commit 68e6592

Browse files
committed
added AssetPackage::isAvailable and buildNormalName
1 parent d428eef commit 68e6592

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

Diff for: src/models/AssetPackage.php

+15-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Exception;
1515
use hiqdev\assetpackagist\components\Storage;
1616
use hiqdev\assetpackagist\registry\RegistryFactory;
17+
use hiqdev\assetpackagist\repositories\PackageRepository;
1718
use Yii;
1819
use yii\base\Object;
1920

@@ -82,6 +83,11 @@ public function getFullName()
8283
return static::buildFullName($this->_type, $this->_name);
8384
}
8485

86+
public static function buildNormalName($type, $name)
87+
{
88+
return static::buildFullName($type, static::normalizeName($name));
89+
}
90+
8591
public static function buildFullName($type, $name)
8692
{
8793
return $type . '-asset/' . $name;
@@ -95,6 +101,7 @@ public static function splitFullName($full)
95101
return [$type, $name];
96102
}
97103

104+
98105
/**
99106
* @param string $full package name
100107
* @return static
@@ -112,7 +119,7 @@ public function getType()
112119

113120
public function getNormalName()
114121
{
115-
return static::buildFullName($this->_type, static::normalizeName($this->_name));
122+
return static::buildNormalName($this->_type, $this->_name);
116123
}
117124

118125
public function getName()
@@ -292,6 +299,13 @@ public function canAutoUpdate()
292299
return time() - $this->getUpdateTime() > 60 * 60 * 24; // 1 day
293300
}
294301

302+
public function isAvailable()
303+
{
304+
$repository = Yii::createObject(PackageRepository::class, []);
305+
306+
return $repository->exists($this);
307+
}
308+
295309
/**
296310
* @return array
297311
*/

0 commit comments

Comments
 (0)