/** * * @param DataTransferAgentInterface $dataTransferAgent */ public function visit(DataTransferAgentInterface $dataTransferAgent) { $connexionType = $dataTransferAgent->getConnectionType(); $connexionParameters = $dataTransferAgent->getConnectionParameters(); $concreteConnexion = null; switch ($connexionType) { case self::DATABASE_TYPE: $keys = array('driver', 'dbname', 'host', 'user', 'password', 'port'); foreach ($keys as $key) { if (!$connexionParameters->offsetExists($key)) { throw new ProcessException("Les paramètres de base de données sont incomplets : manque " . $key); } } $dsn = $connexionParameters->driver . ':dbname=' . $connexionParameters->dbname . ';host=' . $connexionParameters->host . ';port=' . $connexionParameters->port; $user = $connexionParameters->user; $password = $connexionParameters->password; $concreteConnexion = new \PDO($dsn, $user, $password); break; case self::WEB_SERVICE_TYPE: $concreteConnexion = $this->getJsonRestClient(); if (!$connexionParameters->offsetExists("url")) { throw new ProcessException("Les paramètres du client rest sont incomplets : manque l'url"); } try { $concreteConnexion->setBaseUrl($connexionParameters->url); if ($connexionParameters->offsetExists("host")) { $concreteConnexion->setHost($connexionParameters->host); } if ($connexionParameters->offsetExists("key")) { $concreteConnexion->setKey($connexionParameters->key); } } catch (\Exception $e) { throw new ProcessException("Url du web service non valable :" . $connexionParameters->url . " " . $e->getMessage()); } break; case self::SCP_TYPE: $concreteConnexion = $this->getScpClient(); if (!$connexionParameters->offsetExists("host")) { throw new ProcessException("Invalid parameters for scp client : missing host"); } if (!$connexionParameters->offsetExists("port")) { throw new ProcessException("Invalid parameters for scp client : missing port"); } if (!$connexionParameters->offsetExists("username")) { throw new ProcessException("Invalid parameters for scp client : missing username"); } if (!$connexionParameters->offsetExists("pubkeyfile")) { throw new ProcessException("Invalid parameters for scp client : missing pubkeyfile"); } if (!$connexionParameters->offsetExists("privkeyfile")) { throw new ProcessException("Invalid parameters for scp client : missing privkeyfile"); } $concreteConnexion->setConfig($connexionParameters); break; case self::FAKE_TYPE: $concreteConnexion = $this->getFakeConnection(); break; default: throw new ProcessException("Le type de connexion {$connexionType} n'est pas connu."); break; } $endPointConnection = new EndPointConnection(); $endPointConnection->setObject($concreteConnexion); $dataTransferAgent->setEndPointConnection($endPointConnection); }
/** * * @param ServiceLocatorInterface $serviceLocator * @param DataTransferAgentInterface $dataTransferAgent */ private function injectLogger(ServiceLocatorInterface $serviceLocator, DataTransferAgentInterface $dataTransferAgent) { $logFilePath = $this->getLogPath($dataTransferAgent->getExecution(), $serviceLocator); $writer = new \Zend\Log\Writer\Stream($logFilePath); $logger = new \Zend\Log\Logger(); $logger->addWriter($writer); $logger->info($this->translate($serviceLocator, "Injection of logger to file") . " " . $logFilePath); $dataTransferAgent->setLogger($logger); $dataTransferAgent->setLogFilePath($logFilePath); }