Skip to content

Commit 8f7626d

Browse files
committed
Merge branch 'main' into testing
2 parents cd30d2d + 601c594 commit 8f7626d

File tree

8 files changed

+48
-21
lines changed

8 files changed

+48
-21
lines changed

Jenkinsfile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,16 @@ pipeline {
2323
stage('Test') {
2424
steps {
2525
sh 'docker-compose -f docker/docker-compose-4.2.yml run client php vendor/bin/phpunit'
26+
sh 'docker-compose -f docker/docker-compose-4.2.yml down'
2627
sh 'docker-compose -f docker/docker-compose-4.1.yml run client php vendor/bin/phpunit'
28+
sh 'docker-compose -f docker/docker-compose-4.1.yml down'
2729
sh 'docker-compose -f docker/docker-compose-4.0.yml run client php vendor/bin/phpunit'
30+
sh 'docker-compose -f docker/docker-compose-4.0.yml down'
2831
sh 'docker-compose -f docker/docker-compose-3.5.yml run client php vendor/bin/phpunit'
29-
sh 'docker-compose -f docker/docker-compose-2.3.yml run client php vendor/bin/phpunit'
32+
sh 'docker-compose -f docker/docker-compose-3.5.yml down'
33+
// sh 'docker-compose -f docker/docker-compose-2.3.yml run client php vendor/bin/phpunit'
3034
sh 'docker-compose -f docker/docker-compose-php-7.4.yml run client php vendor/bin/phpunit'
35+
sh 'docker-compose -f docker/docker-compose-php-7.4.yml down'
3136
}
3237
}
3338
}

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ services:
2222
neo4j:
2323
networks:
2424
- neo4j
25-
image: neo4j:4.2
25+
image: neo4j:3.5
2626
ports:
2727
- "7474:7474"
2828
- "7687:7687"

docker/docker-compose-2.3.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ services:
1313
- neo4j
1414
depends_on:
1515
- neo4j
16+
volumes:
17+
- ../:/opt/project
1618
neo4j:
1719
networks:
1820
- neo4j

docker/docker-compose-3.5.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ services:
1212
networks:
1313
- neo4j
1414
depends_on:
15-
- neo4j
15+
- neo4j
16+
volumes:
17+
- ../:/opt/project
1618
neo4j:
1719
networks:
1820
- neo4j

src/ClientBuilder.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
use InvalidArgumentException;
1919
use Laudis\Neo4j\Contracts\ClientInterface;
2020
use Laudis\Neo4j\Contracts\DriverInterface;
21+
use Laudis\Neo4j\Formatter\HttpCypherFormatter;
22+
use Laudis\Neo4j\HttpDriver\RequestFactory;
2123
use Laudis\Neo4j\Network\Bolt\BoltDriver;
2224
use Laudis\Neo4j\Network\Bolt\BoltInjections;
2325
use Laudis\Neo4j\Network\Http\HttpDriver;
@@ -64,7 +66,10 @@ public function addHttpConnection(string $alias, string $url, HttpInjections $in
6466
if (!isset($parse['host'], $parse['user'], $parse['pass'])) {
6567
throw new InvalidArgumentException('The provided url must have a parsed host, user and pass value');
6668
}
67-
$conneciton = new HttpDriver($parse, new VersionDiscovery(), $injections ?? new HttpInjections());
69+
$injections = $injections ?? new HttpInjections();
70+
$factory = $injections->requestFactory();
71+
$requestFactory = new RequestFactory($factory, $injections->streamFactory(), new HttpCypherFormatter());
72+
$conneciton = new HttpDriver($parse, new VersionDiscovery($requestFactory, $injections->client()), $injections);
6873
$this->connectionPool->put($alias, $conneciton);
6974

7075
return $this;

src/HttpDriver/RequestFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function openTransaction(RequestData $data): RequestInterface
4040
return $this->createRequest($data, 'POST');
4141
}
4242

43-
private function createRequest(RequestData $data, string $method, string $body = ''): RequestInterface
43+
public function createRequest(RequestData $data, string $method, string $body = ''): RequestInterface
4444
{
4545
$combo = base64_encode($data->getUser().':'.$data->getPassword());
4646

src/Network/Http/HttpDriver.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,22 @@ public function aquireSession(): SessionInterface
5959
$this->parsedUrl['port'] ?? self::DEFAULT_PORT,
6060
$this->parsedUrl['path'] ?? ''
6161
);
62-
$tsx = $this->decorator->discoverTransactionUrl($url, $this->injections);
62+
63+
$requestData = new RequestData(
64+
$url,
65+
$this->parsedUrl['user'],
66+
$this->parsedUrl['pass'],
67+
false
68+
);
69+
$tsx = $this->decorator->discoverTransactionUrl($requestData, $this->injections->database());
70+
$requestData = $requestData->withEndpoint($tsx);
6371

6472
$formatter = new HttpCypherFormatter();
6573
$this->session = new HttpSession(
6674
new RequestFactory($this->injections->requestFactory(), $this->injections->streamFactory(), $formatter),
6775
$this->injections->client(),
6876
$formatter,
69-
new RequestData(
70-
$tsx,
71-
$this->parsedUrl['user'],
72-
$this->parsedUrl['pass'],
73-
false
74-
)
77+
$requestData
7578
);
7679

7780
return $this->session;

src/Network/VersionDiscovery.php

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,19 @@
1414
namespace Laudis\Neo4j\Network;
1515

1616
use JsonException;
17-
use Laudis\Neo4j\Network\Http\HttpInjections;
17+
use Laudis\Neo4j\Databags\RequestData;
18+
use Laudis\Neo4j\HttpDriver\RequestFactory;
1819
use Psr\Http\Client\ClientExceptionInterface;
1920
use Psr\Http\Client\ClientInterface;
20-
use Psr\Http\Message\RequestFactoryInterface;
2121

2222
/**
2323
* @psalm-type DiscoveryResult = array{
2424
* bolt_routing:string,
2525
* transaction: string,
2626
* bolt_direct: string,
2727
* neo4j_version: string,
28-
* neo4j_edition: string
28+
* neo4j_edition: string,
29+
* data?: string
2930
* }
3031
* @psalm-type DiscoveryResultLegacy = array{
3132
* extensions: array,
@@ -46,21 +47,30 @@
4647
*/
4748
final class VersionDiscovery
4849
{
50+
private RequestFactory $requestFactory;
51+
private ClientInterface $client;
52+
53+
public function __construct(RequestFactory $requestFactory, ClientInterface $client)
54+
{
55+
$this->requestFactory = $requestFactory;
56+
$this->client = $client;
57+
}
58+
4959
/**
5060
* @throws ClientExceptionInterface
5161
* @throws JsonException
5262
*/
53-
public function discoverTransactionUrl(string $url, HttpInjections $injections): string
63+
public function discoverTransactionUrl(RequestData $data, string $database): string
5464
{
55-
$discovery = $this->discovery($injections->client(), $injections->requestFactory(), $url);
65+
$discovery = $this->discovery($data);
5666
$version = $discovery['neo4j_version'] ?? null;
5767

5868
if ($version === null) {
59-
$discovery = $this->discovery($injections->client(), $injections->requestFactory(), $url.'/db/data');
69+
$discovery = $this->discovery($data->withEndpoint($discovery['data'] ?? $data->getEndpoint().'/db/data'));
6070
}
6171
$tsx = $discovery['transaction'];
6272

63-
return str_replace('{databaseName}', $injections->database(), $tsx);
73+
return str_replace('{databaseName}', $database, $tsx);
6474
}
6575

6676
/**
@@ -69,9 +79,9 @@ public function discoverTransactionUrl(string $url, HttpInjections $injections):
6979
*
7080
* @return DiscoveryResult|DiscoveryResultLegacy $discovery
7181
*/
72-
private function discovery(ClientInterface $client, RequestFactoryInterface $factory, string $uri): array
82+
private function discovery(RequestData $data): array
7383
{
74-
$response = $client->sendRequest($factory->createRequest('GET', $uri));
84+
$response = $this->client->sendRequest($this->requestFactory->createRequest($data, 'GET'));
7585

7686
/** @var DiscoveryResultLegacy|DiscoveryResult $result */
7787
$result = json_decode($response->getBody()->getContents(), true, 512, JSON_THROW_ON_ERROR);

0 commit comments

Comments
 (0)