Class Yiisoft\YiiDevTool\App\Component\Package\PackageList
| Inheritance | Yiisoft\YiiDevTool\App\Component\Package\PackageList |
|---|
Public Methods
Method Details
| public mixed __construct ( string $ownerPackages, string $configFile, string $packagesRootDir ) | ||
| $ownerPackages | string | |
| $configFile | string | |
| $packagesRootDir | string | |
public function __construct(string $ownerPackages, string $configFile, string $packagesRootDir)
{
/** @noinspection PhpIncludeInspection */
$config = require $configFile;
foreach ($config as $rootPackageId => $packageConfig) {
$this->list[$rootPackageId] = new Package($rootPackageId, $packageConfig, $ownerPackages, $packagesRootDir, null);
if (is_array($packageConfig)) {
$isPackageMonorepo = (bool) ($packageConfig['monorepo'] ?? false);
if ($isPackageMonorepo) {
foreach ($packageConfig['packages'] as $packageId => $packageConfig) {
$index = "{$rootPackageId}__{$packageId}";
$this->list[$index] = new Package($packageId, $packageConfig, $ownerPackages, $packagesRootDir, $this->list[$rootPackageId]);
}
}
}
}
}
| public Yiisoft\YiiDevTool\App\Component\Package\Package[] getAllPackages ( ) |
public function getAllPackages(): array
{
return $this->list;
}
| public Yiisoft\YiiDevTool\App\Component\Package\Package[] getEnabledPackages ( ) |
public function getEnabledPackages(): array
{
$packages = [];
foreach ($this->list as $id => $package) {
if ($package->enabled()) {
$packages[$id] = $package;
}
}
return $packages;
}
| public Yiisoft\YiiDevTool\App\Component\Package\Package[] getInstalledAndEnabledPackages ( ) |
public function getInstalledAndEnabledPackages(): array
{
if ($this->installedAndEnabledList === null) {
$this->installedAndEnabledList = array_filter(
$this->getInstalledPackages(),
static fn (Package $package) => $package->enabled(),
);
}
return $this->installedAndEnabledList;
}
| public Yiisoft\YiiDevTool\App\Component\Package\Package[] getInstalledPackages ( ) |
public function getInstalledPackages(): array
{
if ($this->installedList === null) {
$this->installedList = [];
foreach ($this->list as $id => $package) {
if (file_exists($package->getPath())) {
$this->installedList[$id] = $package;
}
}
}
return $this->installedList;
}
| public Yiisoft\YiiDevTool\App\Component\Package\Package|null getPackage ( string $packageId ) | ||
| $packageId | string | |
public function getPackage(string $packageId): ?Package
{
return $this->hasPackage($packageId) ? $this->list[$packageId] : null;
}
| public array getTree ( ) |
public function getTree(): array
{
$result = [];
foreach ($this->list as $package) {
if ($package->isVirtual()) {
$rootPackage = $package->getRootPackage();
if ($rootPackage !== null) {
$config = $result[$rootPackage->getId()] ?? true;
if (is_bool($config)) {
$config = [
'enabled' => $config,
'monorepo' => true,
'packages' => [
$package->getId() => $package->enabled(),
],
];
} elseif (is_array($config)) {
$config['packages'][$package->getId()] = $package->enabled();
}
$result[$rootPackage->getId()] = $config;
continue;
}
}
$config = $result[$package->getId()] ?? $package->enabled();
if (is_array($config)) {
$config = array_merge([
'enabled' => $package->enabled(),
'monorepo' => true,
'packages' => [],
], $config);
}
$result[$package->getId()] = $config;
}
return $result;
}
| public boolean hasPackage ( string $packageId ) | ||
| $packageId | string | |
public function hasPackage(string $packageId): bool
{
return array_key_exists($packageId, $this->list);
}
Signup or Login in order to comment.