Skip to content

Commit ee030a5

Browse files
refactor: unified package api. Manager classes can now be called through helper functions on the client (i.e. schema())
feat: added query statement handling fix: improved exception handling build: removed unnecessary dto package. docs: updated README.md
1 parent d68df8e commit ee030a5

29 files changed

+1081
-910
lines changed

README.md

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# ArangoDB PHP client
22

3-
Low level PHP client for ArangoDB. Supports PHP versions 7 & 8.
3+
Low level PHP client for ArangoDB. Supports PHP versions 7.4 & ^8.0
44

55
![Github CI tests](https://github.com/LaravelFreelancerNL/arangodb-php-client/workflows/CI%20tests/badge.svg)
66
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/LaravelFreelancerNL/arangodb-php-client/badges/quality-score.png?b=next)](https://scrutinizer-ci.com/g/LaravelFreelancerNL/arangodb-php-client/?branch=next)
@@ -16,27 +16,56 @@ composer require laravel-freelancer-nl/arangodb-php-client
1616
```
1717
## Quickstart
1818

19+
### Create a new client
20+
```
21+
$client = new ArangoClient($config);
1922
```
20-
// Create a new connector
21-
$this->connector = new Connector($config);
2223

23-
//Create the domain clients that suit your purpose and pass the connector to the client.
24-
$this->schemaClient = new SchemaClient($this->connector);
24+
### Create a collection
25+
Use the schemaManager to create a new collection.
26+
```
27+
$client->schema()->createCollection('users');
28+
```
2529

26-
//Create a database
27-
$this->schemaClient->createDatabase('MyKillahProject');
30+
### Get documents from the collection
31+
```
32+
$statement = $client->prepare('FOR user in Users RETURN user');
33+
$statement->execute();
34+
$users = $statement->fetchAll();
2835
```
36+
As there are no users yet in the above example this will yield an empty result.
37+
Note that this client does not have any preconceptions about the data structure
38+
and thus everything is returned as raw arrays.
2939

3040
### config
3141
The connector has a default configuration for a local ArangoDB instance at it's default port (8529).
3242

33-
## Client domains
34-
### AdministrationClient
35-
Manages administrative functions
43+
## AQL statements
44+
To run AQL queries you prepare a query, execute it and fetch the results. Much like PHP's PDO extension.
45+
46+
```
47+
$statement = $client->prepare('FOR user in users RETURN user');
48+
$statement->execute();
49+
$users = $statement->fetchAll();
50+
```
3651

52+
## Managers
53+
You have access to several managers that allow you to perform specific tasks on your ArangoDB instance(s).
3754

38-
### SchemaClient
39-
Manages schema related tasks like creating databases, collections, indexes, views and graphs
55+
(ArangoDB's endpoints are mapped to these managers in a semantically functional manner. Therefore a manager
56+
may have functionality from different endpoints within ArangoDB's HTTP API.)
57+
58+
### Admin
59+
Manages administrative functions to manage the server/cluster and retrieve server level information.
60+
```
61+
$client->admin()->getVersion();
62+
```
63+
64+
### Schema
65+
The schema manager allows you perform tasks like creating databases, collections, indexes, views and graphs
66+
```
67+
$client->schema()->createCollection('users');
68+
```
4069

4170
## Related packages
4271
[AQL query builder](https://github.com/LaravelFreelancerNL/fluentaql)

composer.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,14 @@
1919
"php": "^7.4|^8.0",
2020
"ext-json": "*",
2121
"guzzlehttp/guzzle": "^7.2",
22-
"spatie/data-transfer-object": "^2.8",
2322
"halaxa/json-machine": "^0.6.0"
2423
},
2524
"require-dev": {
2625
"phpunit/phpunit": "^9.5",
2726
"phpstan/phpstan": "^0.12.82",
2827
"phpmd/phpmd": "^2.9",
2928
"vimeo/psalm": "^4.6",
30-
"squizlabs/php_codesniffer": "^3.5",
31-
"sebastian/phpcpd": "^6.0"
29+
"squizlabs/php_codesniffer": "^3.5"
3230
},
3331
"autoload": {
3432
"psr-4": {

composer.lock

Lines changed: 1 addition & 121 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Administration/AdministrationClient.php renamed to src/Admin/AdminManager.php

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,26 @@
22

33
declare(strict_types=1);
44

5-
namespace ArangoClient\Administration;
5+
namespace ArangoClient\Admin;
66

7-
use ArangoClient\Connector;
7+
use ArangoClient\ArangoClient;
88
use ArangoClient\Exceptions\ArangoException;
9-
use GuzzleHttp\Exception\GuzzleException;
9+
use ArangoClient\Manager;
1010

11-
class AdministrationClient
11+
class AdminManager extends Manager
1212
{
1313
/**
14-
* @var Connector
14+
* @var ArangoClient
1515
*/
16-
protected Connector $connector;
16+
protected ArangoClient $arangoClient;
1717

1818
/**
1919
* Documents constructor.
20-
* @param Connector $connector
20+
* @param ArangoClient $arangoClient
2121
*/
22-
public function __construct(Connector $connector)
22+
public function __construct(ArangoClient $arangoClient)
2323
{
24-
$this->connector = $connector;
24+
$this->arangoClient = $arangoClient;
2525
}
2626

2727
/**
@@ -32,11 +32,10 @@ public function __construct(Connector $connector)
3232
* @return array<mixed>
3333
*
3434
* @throws ArangoException
35-
* @throws GuzzleException
3635
*/
37-
public function version(bool $details = false): array
36+
public function getVersion(bool $details = false): array
3837
{
39-
return (array) $this->connector->request(
38+
return $this->arangoClient->request(
4039
'get',
4140
'/_api/version',
4241
[

0 commit comments

Comments
 (0)