Ejemplo n.º 1
0
 public function handleUpdate(Args $args)
 {
     $targetName = $args->getArgument('name');
     if (!$this->targetManager->hasTarget($targetName)) {
         throw NoSuchTargetException::forTargetName($targetName);
     }
     $targetToUpdate = $this->targetManager->getTarget($targetName);
     $installerName = $targetToUpdate->getInstallerName();
     $location = $targetToUpdate->getLocation();
     $urlFormat = $targetToUpdate->getUrlFormat();
     $parameters = $targetToUpdate->getParameterValues();
     if ($args->isOptionSet('installer')) {
         $installerName = $args->getOption('installer');
     }
     if ($args->isOptionSet('location')) {
         $location = $args->getOption('location');
     }
     if ($args->isOptionSet('url-format')) {
         $urlFormat = $args->getOption('url-format');
     }
     $this->parseParams($args, $parameters);
     $this->unsetParams($args, $parameters);
     $updatedTarget = new InstallTarget($targetName, $installerName, $location, $urlFormat, $parameters);
     if ($this->targetsEqual($targetToUpdate, $updatedTarget)) {
         throw new RuntimeException('Nothing to update.');
     }
     $this->targetManager->addTarget($updatedTarget);
     return 0;
 }
Ejemplo n.º 2
0
 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;
 }