withOptions($preInitializers, $driverOptions); } $preInitializers = $this->withSecure($preInitializers, $params); $postInitializers = $this->withCharset($postInitializers, $params); return new Connection( $host, $params['user'] ?? null, $params['password'] ?? null, $params['dbname'] ?? null, $params['port'] ?? null, $params['unix_socket'] ?? null, $flags, $preInitializers, $postInitializers ); } /** * @param list $initializers * @param array $options * * @return list */ private function withOptions(array $initializers, array $options): array { if (count($options) !== 0) { $initializers[] = new Options($options); } return $initializers; } /** * @param list $initializers * @param array $params * * @return list */ private function withSecure(array $initializers, array $params): array { if ( isset($params['ssl_key']) || isset($params['ssl_cert']) || isset($params['ssl_ca']) || isset($params['ssl_capath']) || isset($params['ssl_cipher']) ) { $initializers[] = new Secure( $params['ssl_key'] ?? '', $params['ssl_cert'] ?? '', $params['ssl_ca'] ?? '', $params['ssl_capath'] ?? '', $params['ssl_cipher'] ?? '' ); } return $initializers; } /** * @param list $initializers * @param array $params * * @return list */ private function withCharset(array $initializers, array $params): array { if (isset($params['charset'])) { $initializers[] = new Charset($params['charset']); } return $initializers; } }