public function handleList(Args $args, IO $io) { /** @var AssetMapping[][] $mappingsByTarget */ $mappingsByTarget = array(); /** @var InstallTarget[] $targets */ $targets = array(); $nonExistingTargets = array(); // Assemble mappings and validate targets foreach ($this->assetManager->getAssetMappings() as $mapping) { $targetName = $mapping->getTargetName(); if (!isset($mappingsByTarget[$targetName])) { $mappingsByTarget[$targetName] = array(); if ($this->targetManager->hasTarget($targetName)) { $targets[$targetName] = $this->targetManager->getTarget($targetName); } else { $nonExistingTargets[$targetName] = true; } } $mappingsByTarget[$targetName][] = $mapping; } if (!$mappingsByTarget) { $io->writeLine('No assets are mapped. Use "puli asset map <path> <web-path>" to map assets.'); return 0; } if (count($targets) > 0) { $io->writeLine('The following web assets are currently enabled:'); $io->writeLine(''); foreach ($targets as $targetName => $target) { $targetTitle = 'Target <bu>' . $targetName . '</bu>'; if ($targetName === InstallTarget::DEFAULT_TARGET) { $targetTitle .= ' (alias of: <bu>' . $target->getName() . '</bu>)'; } $io->writeLine(" <b>{$targetTitle}</b>"); $io->writeLine(" Location: <c2>{$target->getLocation()}</c2>"); $io->writeLine(" Installer: {$target->getInstallerName()}"); $io->writeLine(" URL Format: <c1>{$target->getUrlFormat()}</c1>"); $io->writeLine(''); $this->printMappingTable($io, $mappingsByTarget[$targetName]); $io->writeLine(''); } $io->writeLine('Use "puli asset install" to install the assets in their targets.'); } if (count($targets) > 0 && count($nonExistingTargets) > 0) { $io->writeLine(''); } if (count($nonExistingTargets) > 0) { $io->writeLine('The following web assets are disabled since their target does not exist.'); $io->writeLine(''); foreach ($nonExistingTargets as $targetName => $_) { $io->writeLine(" <b>Target <bu>{$targetName}</bu></b>"); $io->writeLine(''); $this->printMappingTable($io, $mappingsByTarget[$targetName], false); $io->writeLine(''); } $io->writeLine('Use "puli target add <target> <location>" to add a target.'); } return 0; }
public function handleRemove(Args $args) { $targetName = $args->getArgument('name'); if (!$this->targetManager->hasTarget($targetName)) { throw NoSuchTargetException::forTargetName($targetName); } $this->targetManager->removeTarget($targetName); return 0; }