예제 #1
0
 public function handleUpdate(Args $args)
 {
     $serverName = $args->getArgument('name');
     if (!$this->serverManager->hasServer($serverName)) {
         throw NoSuchServerException::forServerName($serverName);
     }
     $serverToUpdate = $this->serverManager->getServer($serverName);
     $installerName = $serverToUpdate->getInstallerName();
     $documentRoot = $serverToUpdate->getDocumentRoot();
     $urlFormat = $serverToUpdate->getUrlFormat();
     $parameters = $serverToUpdate->getParameterValues();
     if ($args->isOptionSet('installer')) {
         $installerName = $args->getOption('installer');
     }
     if ($args->isOptionSet('document-root')) {
         $documentRoot = $args->getOption('document-root');
     }
     if ($args->isOptionSet('url-format')) {
         $urlFormat = $args->getOption('url-format');
     }
     $this->parseParams($args, $parameters);
     $this->unsetParams($args, $parameters);
     $updatedServer = new Server($serverName, $installerName, $documentRoot, $urlFormat, $parameters);
     if ($this->serversEqual($serverToUpdate, $updatedServer)) {
         throw new RuntimeException('Nothing to update.');
     }
     $this->serverManager->addServer($updatedServer);
     return 0;
 }
예제 #2
0
 public function handleList(Args $args, IO $io)
 {
     /** @var AssetMapping[][] $mappingsByServer */
     $mappingsByServer = array();
     /** @var Server[] $servers */
     $servers = array();
     $nonExistingServers = array();
     // Assemble mappings and validate servers
     foreach ($this->assetManager->getAssetMappings() as $mapping) {
         $serverName = $mapping->getServerName();
         if (!isset($mappingsByServer[$serverName])) {
             $mappingsByServer[$serverName] = array();
             if ($this->serverManager->hasServer($serverName)) {
                 $servers[$serverName] = $this->serverManager->getServer($serverName);
             } else {
                 $nonExistingServers[$serverName] = true;
             }
         }
         $mappingsByServer[$serverName][] = $mapping;
     }
     if (!$mappingsByServer) {
         $io->writeLine('No public resources. Use "puli publish <path> <server>" to publish resources.');
         return 0;
     }
     if (count($servers) > 0) {
         $io->writeLine('The following resources are published:');
         $io->writeLine('');
         foreach ($servers as $serverName => $server) {
             $serverTitle = 'Server <bu>' . $serverName . '</bu>';
             $io->writeLine("    <b>{$serverTitle}</b>");
             $io->writeLine("    Location:   <c2>{$server->getDocumentRoot()}</c2>");
             $io->writeLine("    Installer:  {$server->getInstallerName()}");
             $io->writeLine("    URL Format: <c1>{$server->getUrlFormat()}</c1>");
             $io->writeLine('');
             $this->printMappingTable($io, $mappingsByServer[$serverName]);
             $io->writeLine('');
         }
         $io->writeLine('Use "puli publish --install" to install the resources on your servers.');
     }
     if (count($servers) > 0 && count($nonExistingServers) > 0) {
         $io->writeLine('');
     }
     if (count($nonExistingServers) > 0) {
         $io->writeLine('The following public resources are disabled since their server does not exist:');
         $io->writeLine('');
         foreach ($nonExistingServers as $serverName => $_) {
             $io->writeLine("    <b>Server <bu>{$serverName}</bu></b>");
             $io->writeLine('');
             $this->printMappingTable($io, $mappingsByServer[$serverName], false);
             $io->writeLine('');
         }
         $io->writeLine('Use "puli server add <name> <document-root>" to add a server.');
     }
     return 0;
 }