Skip to content

Commit da39f0f

Browse files
PratikshaPratiksha
authored andcommitted
winp
1 parent 889765b commit da39f0f

File tree

4 files changed

+91
-30
lines changed

4 files changed

+91
-30
lines changed

src/Neo4jQueryAPI.php

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?php
2-
32
namespace Neo4j\QueryAPI;
43

54
use GuzzleHttp\Client;
@@ -14,34 +13,19 @@
1413

1514
class Neo4jQueryAPI
1615
{
16+
private ClientInterface $client;
17+
private ResponseParser $responseParser;
18+
private Neo4jRequestFactory $requestFactory;
19+
20+
// Constructor injection for flexibility
1721
public function __construct(
18-
private ClientInterface $client,
19-
private ResponseParser $responseParser,
20-
private Neo4jRequestFactory $requestFactory
22+
ClientInterface $client,
23+
ResponseParser $responseParser,
24+
Neo4jRequestFactory $requestFactory
2125
) {
22-
}
23-
24-
/**
25-
* @api
26-
*/
27-
public static function login(string $address, AuthenticateInterface $auth = null): self
28-
{
29-
$client = new Client();
30-
31-
return new self(
32-
client: $client,
33-
responseParser: new ResponseParser(
34-
ogm: new OGM()
35-
),
36-
requestFactory: new Neo4jRequestFactory(
37-
psr17Factory: new Psr17Factory(),
38-
streamFactory: new Psr17Factory(),
39-
configuration: new Configuration(
40-
baseUri: $address
41-
),
42-
auth: $auth ?? Authentication::fromEnvironment()
43-
)
44-
);
26+
$this->client = $client;
27+
$this->responseParser = $responseParser;
28+
$this->requestFactory = $requestFactory;
4529
}
4630

4731
/**

src/abc.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
require __DIR__ . '/../vendor/autoload.php';
4+
5+
use Neo4j\QueryAPI\Neo4jQueryAPI;
6+
use Neo4j\QueryAPI\Authentication\AuthenticateInterface;
7+
use Neo4j\QueryAPI\Objects\Authentication;
8+
use Neo4j\QueryAPI\Configuration;
9+
use Neo4j\QueryAPI\Results\ResultSet;
10+
11+
$neo4jUrl = 'bb79fe35.databases.neo4j.io'; // Your Neo4j Aura instance URL (without `neo4j+s://`)
12+
$neo4jUsername = 'neo4j'; // Your Neo4j username
13+
$neo4jPassword = 'OXDRMgdWFKMcBRCBrIwXnKkwLgDlmFxipnywT6t_AK0'; // Your Neo4j password
14+
15+
try {
16+
// Correctly instantiate the $auth object with basic authentication
17+
$auth = Authentication::basic($neo4jUsername, $neo4jPassword);
18+
19+
// Call the login method with your custom library (using Bolt protocol)
20+
$neo4j = Neo4jQueryAPI::login(
21+
$neo4jUrl, // URL without `neo4j+s://`
22+
$auth
23+
);
24+
25+
// Run a simple Cypher query
26+
$cypher = 'MATCH (n) RETURN n LIMIT 10';
27+
$resultSet = $neo4j->run($cypher);
28+
29+
// Check the result structure (debugging purposes)
30+
var_dump($resultSet); // To inspect the response data
31+
32+
// Handle results
33+
foreach ($resultSet as $row) {
34+
echo "Node: " . json_encode($row) . "\n";
35+
}
36+
37+
// Optionally, start a transaction
38+
$transaction = $neo4j->beginTransaction();
39+
40+
} catch (Exception $e) {
41+
echo 'Error: ' . $e->getMessage();
42+
}

tests/Integration/Neo4jQueryAPIIntegrationTest.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,23 @@ public function testInvalidQueryHandling()
8181
}
8282

8383

84-
private function initializeApi(): Neo4jQueryAPI
84+
/*private function initializeApi(): Neo4jQueryAPI
8585
{
8686
return Neo4jQueryAPI::login(getenv('NEO4J_ADDRESS'), Authentication::fromEnvironment());
87+
}*/
88+
89+
private function initializeApi(): Neo4jQueryAPI
90+
{
91+
$client = new Client();
92+
$responseParser = new ResponseParser(ogm: new OGM());
93+
94+
$requestFactory = new Neo4jRequestFactory(
95+
psr17Factory: new Psr17Factory(),
96+
streamFactory: new Psr17Factory(),
97+
configuration: new Configuration(baseUri: getenv('NEO4J_ADDRESS')),
98+
auth: Authentication::fromEnvironment()
99+
);
100+
return new Neo4jQueryAPI($client, $responseParser, $requestFactory);
87101
}
88102

89103
public function testCounters(): void

tests/Integration/Neo4jTransactionIntegrationTest.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,15 @@
33
namespace Neo4j\QueryAPI\Tests\Integration;
44

55
use Exception;
6+
use GuzzleHttp\Client;
7+
use Neo4j\QueryAPI\Configuration;
8+
use Neo4j\QueryAPI\Neo4jRequestFactory;
69
use Neo4j\QueryAPI\Objects\Authentication;
710
use GuzzleHttp\Exception\GuzzleException;
811
use Neo4j\QueryAPI\Neo4jQueryAPI;
12+
use Neo4j\QueryAPI\OGM;
13+
use Neo4j\QueryAPI\ResponseParser;
14+
use Nyholm\Psr7\Factory\Psr17Factory;
915
use PHPUnit\Framework\TestCase;
1016

1117
/**
@@ -28,14 +34,29 @@ public function setUp(): void
2834
/**
2935
* @throws Exception
3036
*/
31-
private function initializeApi(): Neo4jQueryAPI
37+
/* private function initializeApi(): Neo4jQueryAPI
3238
{
3339
return Neo4jQueryAPI::login(
3440
getenv('NEO4J_ADDRESS'),
3541
Authentication::fromEnvironment(),
3642
);
37-
}
43+
}*/
44+
private function initializeApi(): Neo4jQueryAPI
45+
{
46+
$client = new Client(); // Guzzle Client
47+
3848

49+
$responseParser = new ResponseParser(ogm: new OGM());
50+
51+
$requestFactory = new Neo4jRequestFactory(
52+
psr17Factory: new Psr17Factory(),
53+
streamFactory: new Psr17Factory(),
54+
configuration: new Configuration(baseUri: getenv('NEO4J_ADDRESS')),
55+
auth: Authentication::fromEnvironment()
56+
);
57+
58+
return new Neo4jQueryAPI($client, $responseParser, $requestFactory);
59+
}
3960
/**
4061
* @throws GuzzleException
4162
*/

0 commit comments

Comments
 (0)