/**
  * {@inheritdoc}
  */
 public function getConnectionAdapter(Host $host)
 {
     if (isset($this->connectionAdapters[$host->getConnectionType()])) {
         $connectionIdentifier = spl_object_hash($host);
         if (isset($this->connections[$connectionIdentifier]) === false) {
             $connectionAdapterArguments = $host->getConnectionOptions();
             $connectionAdapterArguments['hostname'] = $host->getHostname();
             $this->connections[$connectionIdentifier] = ObjectFactory::getInstance()->newInstance($this->connectionAdapters[$host->getConnectionType()], $connectionAdapterArguments);
         }
         return $this->connections[$connectionIdentifier];
     }
 }
 /**
  * Ensures a connected connection adapter for a host.
  * Returns the connection adapter instance.
  *
  * @param Host $host
  *
  * @return ConnectionAdapterInterface
  *
  * @throws ConnectionException
  */
 public function ensureConnection(Host $host)
 {
     if ($host->hasConnection()) {
         $connection = $host->getConnection();
         if ($connection->isConnected() === false && $connection->connect() === false) {
             throw new ConnectionException(sprintf('Could not connect to "%s" through "%s".', $host->getHostname(), $host->getConnectionType()));
         }
         return $connection;
     }
     throw new ConnectionException(sprintf('No connection adapter of type "%s" found on host.', $host->getConnectionType()));
 }
Exemplo n.º 3
0
 /**
  * Returns the configured hosts for $stage.
  *
  * @param string $stage
  *
  * @return Host[]
  *
  * @throws UnexpectedValueException when $stage is not a valid type
  */
 public function getHostsByStage($stage)
 {
     if (Host::isValidStage($stage) === false) {
         throw new UnexpectedValueException(sprintf("'%s' is not a valid stage.", $stage));
     }
     $hosts = array();
     foreach ($this->getHosts() as $host) {
         if ($host->getStage() === $stage) {
             $hosts[] = $host;
         }
     }
     return $hosts;
 }