Ejemplo n.º 1
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;
 }
Ejemplo n.º 2
0
    public function testListMappingsOfNonExistingDefaultServer()
    {
        $this->serverManager->expects($this->any())->method('hasServer')->willReturnMap(array(array('localhost', false), array('example.com', false)));
        $this->serverManager->expects($this->never())->method('getServer');
        $this->assetManager->expects($this->once())->method('getAssetMappings')->willReturn(array(new AssetMapping('/app/public', 'localhost', '/', Uuid::fromString(self::UUID1)), new AssetMapping('/acme/blog/public', 'example.com', '/blog', Uuid::fromString(self::UUID2)), new AssetMapping('/acme/profiler/public', 'localhost', '/profiler', Uuid::fromString(self::UUID3))));
        $args = self::$listCommand->parseArgs(new StringArgs(''));
        $expected = <<<EOF
The following public resources are disabled since their server does not exist:

    Server localhost

        e81b32 /app/public           /
        49cfdf /acme/profiler/public /profiler

    Server example.com

        33dbec /acme/blog/public /blog

Use "puli server add <name> <document-root>" to add a server.

EOF;
        $this->assertSame(0, $this->handler->handleList($args, $this->io));
        $this->assertSame($expected, $this->io->fetchOutput());
        $this->assertEmpty($this->io->fetchErrors());
    }
Ejemplo n.º 3
0
 /**
  * @expectedException \Puli\Manager\Api\Server\NoSuchServerException
  */
 public function testDeleteServerFailsIfNotFound()
 {
     $this->serverManager->expects($this->once())->method('hasServer')->with('localhost')->willReturn(false);
     $this->serverManager->expects($this->never())->method('removeServer');
     $args = self::$deleteCommand->parseArgs(new StringArgs('localhost'));
     $this->handler->handleDelete($args);
 }
Ejemplo n.º 4
0
 public function handleDelete(Args $args)
 {
     $serverName = $args->getArgument('name');
     if (!$this->serverManager->hasServer($serverName)) {
         throw NoSuchServerException::forServerName($serverName);
     }
     $this->serverManager->removeServer($serverName);
     return 0;
 }