|
1
|
|
|
<?php |
|
2
|
|
|
namespace Fathomminds\Rest\Database\Clusterpoint; |
|
3
|
|
|
|
|
4
|
|
|
use Clusterpoint\Client; |
|
5
|
|
|
use Fathomminds\Rest\Contracts\IDatabase; |
|
6
|
|
|
use Fathomminds\Rest\Database\Clusterpoint\Resource; |
|
7
|
|
|
use Fathomminds\Rest\Helpers\ReflectionHelper; |
|
8
|
|
|
|
|
9
|
|
|
class Database implements IDatabase |
|
10
|
|
|
{ |
|
11
|
|
|
protected $client; |
|
12
|
|
|
protected $databaseName; |
|
13
|
|
|
|
|
14
|
31 |
|
public function __construct(Client $client = null, $databaseName = null) |
|
15
|
|
|
{ |
|
16
|
31 |
|
$this->client = $client === null ? new Client : $client; |
|
17
|
31 |
|
$this->databaseName = $databaseName === null ? getenv('CLUSTERPOINT_DATABASE') : $databaseName; |
|
18
|
31 |
|
} |
|
19
|
|
|
|
|
20
|
4 |
|
public function get($resourceName, $primaryKey, $resourceId = null) |
|
21
|
|
|
{ |
|
22
|
4 |
|
return (new Resource( |
|
23
|
4 |
|
$resourceName, |
|
24
|
4 |
|
$primaryKey, |
|
25
|
4 |
|
$this->client, |
|
26
|
4 |
|
$this->databaseName |
|
27
|
4 |
|
))->get($resourceId); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
1 |
|
public function post($resourceName, $primaryKey, $newResource) |
|
31
|
|
|
{ |
|
32
|
1 |
|
return (new Resource( |
|
33
|
1 |
|
$resourceName, |
|
34
|
1 |
|
$primaryKey, |
|
35
|
1 |
|
$this->client, |
|
36
|
1 |
|
$this->databaseName |
|
37
|
1 |
|
))->post($newResource); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
1 |
|
public function patch($resourceName, $primaryKey, $resourceId, $newResource) |
|
41
|
|
|
{ |
|
42
|
1 |
|
return (new Resource( |
|
43
|
1 |
|
$resourceName, |
|
44
|
1 |
|
$primaryKey, |
|
45
|
1 |
|
$this->client, |
|
46
|
1 |
|
$this->databaseName |
|
47
|
1 |
|
))->patch($resourceId, $newResource); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
1 |
|
public function put($resourceName, $primaryKey, $resourceId, $newResource) |
|
51
|
|
|
{ |
|
52
|
1 |
|
return (new Resource( |
|
53
|
1 |
|
$resourceName, |
|
54
|
1 |
|
$primaryKey, |
|
55
|
1 |
|
$this->client, |
|
56
|
1 |
|
$this->databaseName |
|
57
|
1 |
|
))->put($resourceId, $newResource); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
2 |
|
public function delete($resourceName, $primaryKey, $resourceId) |
|
61
|
|
|
{ |
|
62
|
2 |
|
return (new Resource( |
|
63
|
2 |
|
$resourceName, |
|
64
|
2 |
|
$primaryKey, |
|
65
|
2 |
|
$this->client, |
|
66
|
2 |
|
$this->databaseName |
|
67
|
2 |
|
))->delete($resourceId); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
1 |
|
public function setDatabaseName($databaseName) |
|
71
|
|
|
{ |
|
72
|
1 |
|
$this->databaseName = $databaseName; |
|
73
|
1 |
|
} |
|
74
|
|
|
|
|
75
|
10 |
|
public function getDatabaseName() |
|
76
|
|
|
{ |
|
77
|
10 |
|
return $this->databaseName; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
7 |
|
public function getClient() |
|
81
|
|
|
{ |
|
82
|
7 |
|
return $this->client; |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|