Skip to content

Commit e175c0b

Browse files
committed
conflicts resolved
2 parents f00e465 + fba075f commit e175c0b

22 files changed

+719
-75
lines changed

.github/workflows/cs-fixer.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ on:
99
pull_request:
1010
paths:
1111
- '**/*.php'
12+
workflow_dispatch:
1213

1314
jobs:
1415
php-cs-fixer:

.github/workflows/test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ on:
55
branches:
66
- main
77
pull_request:
8+
workflow_dispatch:
89

910
concurrency:
1011
group: ${{ github.ref }}

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
#IDE
23
.idea/
34

@@ -11,4 +12,6 @@ test
1112

1213
#PHP-CS-FIXER
1314
.php-cs-fixer.php
14-
.php-cs-fixer.cache
15+
.php-cs-fixer.cache
16+
17+

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Query API
2+
3+
Usage example:
4+
5+
```php
6+
use Neo4j\QueryAPI\Neo4jQueryAPI;
7+
use Neo4j\QueryAPI\Objects\Authentication;
8+
9+
$client = Neo4jQueryAPI::login('https://myaddress.com', Authentication::bearer('mytokken'))
10+
```

composer.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
"guzzlehttp/guzzle": "^7.9",
77
"psr/http-client": "^1.0",
88
"ext-json": "*",
9-
"php": "^8.1"
9+
"php": "^8.1",
10+
"nyholm/psr7": "^1.8"
1011
},
1112
"require-dev": {
1213
"phpunit/phpunit": "^11.0",
1314
"friendsofphp/php-cs-fixer": "^3.68"
15+
1416
},
1517
"autoload": {
1618
"psr-4": {
@@ -39,4 +41,4 @@
3941
"cs:fix": "vendor/bin/php-cs-fixer fix --allow-risky=yes"
4042
}
4143

42-
}
44+
}

composer.lock

Lines changed: 91 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/AuthenticateInterface.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Neo4j\QueryAPI;
4+
5+
use Psr\Http\Message\RequestInterface;
6+
7+
interface AuthenticateInterface
8+
{
9+
/**
10+
* Authenticates the request by returning a new instance of the request with the authentication information attached.
11+
*/
12+
public function authenticate(RequestInterface $request): RequestInterface;
13+
}

src/BasicAuthentication.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace Neo4j\QueryAPI;
4+
5+
use Psr\Http\Message\RequestInterface;
6+
7+
class BasicAuthentication implements AuthenticateInterface
8+
{
9+
private string $username;
10+
private string $password;
11+
12+
public function __construct(?string $username = null, ?string $password = null)
13+
{
14+
$this->username = $username ?? getenv("NEO4J_USERNAME") ?: '';
15+
$this->password = $password ?? getenv("NEO4J_PASSWORD") ?: '';
16+
}
17+
18+
public function authenticate(RequestInterface $request): RequestInterface
19+
{
20+
$authHeader = $this->getHeader();
21+
return $request->withHeader('Authorization', $authHeader);
22+
}
23+
24+
public function getHeader(): string
25+
{
26+
return 'Basic ' . base64_encode($this->username . ':' . $this->password);
27+
}
28+
29+
public function getType(): string
30+
{
31+
return 'Basic';
32+
}
33+
}

src/BearerAuthentication.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace Neo4j\QueryAPI;
4+
5+
use Psr\Http\Message\RequestInterface;
6+
7+
class BearerAuthentication implements AuthenticateInterface
8+
{
9+
public function __construct(private string $token)
10+
{
11+
}
12+
13+
public function authenticate(RequestInterface $request): RequestInterface
14+
{
15+
$authHeader = 'Bearer ' . $this->token;
16+
return $request->withHeader('Authorization', $authHeader);
17+
}
18+
19+
public function getHeader(): string
20+
{
21+
return 'Bearer ' . $this->token;
22+
}
23+
24+
public function getType(): string
25+
{
26+
return 'Bearer';
27+
}
28+
}

0 commit comments

Comments
 (0)