Skip to content

Commit 5a01a2b

Browse files
committed
Merge branch 'afrozenpeach-master'
2 parents e12e308 + 266bc0c commit 5a01a2b

File tree

4 files changed

+53
-15
lines changed

4 files changed

+53
-15
lines changed

src/Elasticsearch/ClientBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ private function normalizeExtendedHost(array $host): array
582582
$host['scheme'] = 'http';
583583
}
584584
if (isset($host['port']) === false) {
585-
$host['port'] = '9200';
585+
$host['port'] = 9200;
586586
}
587587
return $host;
588588
}

src/Elasticsearch/Connections/Connection.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ class Connection implements ConnectionInterface
6565
*/
6666
protected $path;
6767

68+
/**
69+
* @var int
70+
*/
71+
protected $port;
72+
6873
/**
6974
* @var LoggerInterface
7075
*/
@@ -129,6 +134,8 @@ public function __construct(
129134
$connectionParams['client']['curl'][CURLOPT_USERPWD] = $hostDetails['user'].':'.$hostDetails['pass'];
130135
}
131136

137+
$connectionParams['client']['curl'][CURLOPT_PORT] = $hostDetails['port'];
138+
132139
if (isset($connectionParams['client']['headers'])) {
133140
$this->headers = $connectionParams['client']['headers'];
134141
unset($connectionParams['client']['headers']);
@@ -143,13 +150,16 @@ public function __construct(
143150
phpversion()
144151
)];
145152

146-
$host = $hostDetails['host'].':'.$hostDetails['port'];
153+
$host = $hostDetails['host'];
147154
$path = null;
148155
if (isset($hostDetails['path']) === true) {
149156
$path = $hostDetails['path'];
150157
}
158+
$port = $hostDetails['port'];
159+
151160
$this->host = $host;
152161
$this->path = $path;
162+
$this->port = $port;
153163
$this->log = $log;
154164
$this->trace = $trace;
155165
$this->connectionParams = $connectionParams;
@@ -494,6 +504,14 @@ public function getPath(): ?string
494504
return $this->path;
495505
}
496506

507+
/**
508+
* @return int
509+
*/
510+
public function getPort()
511+
{
512+
return $this->port;
513+
}
514+
497515
protected function getCurlRetryException(array $request, array $response): ElasticsearchException
498516
{
499517
$exception = null;

src/Elasticsearch/Connections/ConnectionInterface.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ public function getTransportSchema(): string;
2929
*/
3030
public function getHost(): string;
3131

32+
/**
33+
* Get the port for this connection
34+
*
35+
* @return int
36+
*/
37+
public function getPort();
38+
3239
/**
3340
* Get the username:password string for this connection, null if not set
3441
*/

tests/Elasticsearch/Tests/ClientTest.php

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,8 @@ public function testInlineHosts()
264264
]
265265
)->build();
266266
$host = $client->transport->getConnection();
267-
$this->assertSame("localhost:9200", $host->getHost());
267+
$this->assertSame("localhost", $host->getHost());
268+
$this->assertSame(9200, $host->getPort());
268269
$this->assertSame("http", $host->getTransportSchema());
269270

270271

@@ -274,7 +275,8 @@ public function testInlineHosts()
274275
]
275276
)->build();
276277
$host = $client->transport->getConnection();
277-
$this->assertSame("localhost:9200", $host->getHost());
278+
$this->assertSame("localhost", $host->getHost());
279+
$this->assertSame(9200, $host->getPort());
278280
$this->assertSame("http", $host->getTransportSchema());
279281

280282
$client = Elasticsearch\ClientBuilder::create()->setHosts(
@@ -283,7 +285,8 @@ public function testInlineHosts()
283285
]
284286
)->build();
285287
$host = $client->transport->getConnection();
286-
$this->assertSame("foo.com:9200", $host->getHost());
288+
$this->assertSame("foo.com", $host->getHost());
289+
$this->assertSame(9200, $host->getPort());
287290
$this->assertSame("http", $host->getTransportSchema());
288291

289292
$client = Elasticsearch\ClientBuilder::create()->setHosts(
@@ -292,7 +295,8 @@ public function testInlineHosts()
292295
]
293296
)->build();
294297
$host = $client->transport->getConnection();
295-
$this->assertSame("foo.com:9200", $host->getHost());
298+
$this->assertSame("foo.com", $host->getHost());
299+
$this->assertSame(9200, $host->getPort());
296300
$this->assertSame("https", $host->getTransportSchema());
297301

298302

@@ -302,7 +306,8 @@ public function testInlineHosts()
302306
]
303307
)->build();
304308
$host = $client->transport->getConnection();
305-
$this->assertSame("foo.com:9200", $host->getHost());
309+
$this->assertSame("foo.com", $host->getHost());
310+
$this->assertSame(9200, $host->getPort());
306311
$this->assertSame("https", $host->getTransportSchema());
307312
$this->assertSame("user:pass", $host->getUserPass());
308313
}
@@ -319,7 +324,8 @@ public function testExtendedHosts()
319324
]
320325
)->build();
321326
$host = $client->transport->getConnection();
322-
$this->assertSame("localhost:9200", $host->getHost());
327+
$this->assertSame("localhost", $host->getHost());
328+
$this->assertSame(9200, $host->getPort());
323329
$this->assertSame("http", $host->getTransportSchema());
324330

325331

@@ -333,7 +339,8 @@ public function testExtendedHosts()
333339
]
334340
)->build();
335341
$host = $client->transport->getConnection();
336-
$this->assertSame("foo.com:9200", $host->getHost());
342+
$this->assertSame("foo.com", $host->getHost());
343+
$this->assertSame(9200, $host->getPort());
337344
$this->assertSame("http", $host->getTransportSchema());
338345

339346

@@ -347,7 +354,8 @@ public function testExtendedHosts()
347354
]
348355
)->build();
349356
$host = $client->transport->getConnection();
350-
$this->assertSame("foo.com:9200", $host->getHost());
357+
$this->assertSame("foo.com", $host->getHost());
358+
$this->assertSame(9200, $host->getPort());
351359
$this->assertSame("https", $host->getTransportSchema());
352360

353361

@@ -360,7 +368,8 @@ public function testExtendedHosts()
360368
]
361369
)->build();
362370
$host = $client->transport->getConnection();
363-
$this->assertSame("foo.com:9200", $host->getHost());
371+
$this->assertSame("foo.com", $host->getHost());
372+
$this->assertSame(9200, $host->getPort());
364373
$this->assertSame("http", $host->getTransportSchema());
365374

366375

@@ -372,7 +381,8 @@ public function testExtendedHosts()
372381
]
373382
)->build();
374383
$host = $client->transport->getConnection();
375-
$this->assertSame("foo.com:9200", $host->getHost());
384+
$this->assertSame("foo.com", $host->getHost());
385+
$this->assertSame(9200, $host->getPort());
376386
$this->assertSame("http", $host->getTransportSchema());
377387

378388

@@ -386,7 +396,8 @@ public function testExtendedHosts()
386396
]
387397
)->build();
388398
$host = $client->transport->getConnection();
389-
$this->assertSame("foo.com:9500", $host->getHost());
399+
$this->assertSame("foo.com", $host->getHost());
400+
$this->assertSame(9500, $host->getPort());
390401
$this->assertSame("https", $host->getTransportSchema());
391402

392403

@@ -413,7 +424,8 @@ public function testExtendedHosts()
413424
]
414425
)->build();
415426
$host = $client->transport->getConnection();
416-
$this->assertSame("the_foo.com:9200", $host->getHost());
427+
$this->assertSame("the_foo.com", $host->getHost());
428+
$this->assertSame(9200, $host->getPort());
417429
$this->assertSame("http", $host->getTransportSchema());
418430

419431

@@ -428,7 +440,8 @@ public function testExtendedHosts()
428440
]
429441
)->build();
430442
$host = $client->transport->getConnection();
431-
$this->assertSame("foo.com:9200", $host->getHost());
443+
$this->assertSame("foo.com", $host->getHost());
444+
$this->assertSame(9200, $host->getPort());
432445
$this->assertSame("http", $host->getTransportSchema());
433446
$this->assertSame("user:abc#$@?%!abc", $host->getUserPass());
434447
}

0 commit comments

Comments
 (0)