13
13
14
14
use ArangoDb \Exception \GuardErrorException ;
15
15
use ArangoDb \Exception \UnexpectedResponse ;
16
+ use ArangoDb \Guard \Guard ;
16
17
use ArangoDb \Guard \SuccessHttpStatusCode ;
17
18
use ArangoDb \Http \TypeSupport ;
18
19
use ArangoDb \Type \Collection as CollectionType ;
@@ -27,20 +28,34 @@ final class Collection implements CollectionHandler
27
28
private $ client ;
28
29
29
30
/**
30
- * @var SuccessHttpStatusCode
31
+ * @var Guard
31
32
*/
32
- private static $ guard ;
33
+ private $ guard ;
33
34
34
- public function __construct (TypeSupport $ client )
35
- {
35
+ /**
36
+ * @var string
37
+ */
38
+ protected $ collectionClass ;
39
+
40
+ /**
41
+ * @param TypeSupport $client
42
+ * @param string $collectionClass FQCN of the class which implements \ArangoDb\Type\CollectionType
43
+ * @param Guard|null $guard
44
+ */
45
+ public function __construct (
46
+ TypeSupport $ client ,
47
+ string $ collectionClass = CollectionType::class,
48
+ Guard $ guard = null
49
+ ) {
36
50
$ this ->client = $ client ;
37
- self ::$ guard = SuccessHttpStatusCode::withoutContentId ();
51
+ $ this ->collectionClass = $ collectionClass ;
52
+ $ this ->guard = $ guard ?? SuccessHttpStatusCode::withoutContentId ();
38
53
}
39
54
40
55
public function create (string $ collectionName , array $ options = []): string
41
56
{
42
- $ type = CollectionType ::create ($ collectionName , $ options )
43
- ->useGuard (self :: $ guard );
57
+ $ type = ( $ this -> collectionClass ) ::create ($ collectionName , $ options )
58
+ ->useGuard ($ this -> guard );
44
59
45
60
$ response = $ this ->client ->sendType ($ type );
46
61
@@ -55,8 +70,8 @@ public function create(string $collectionName, array $options = []): string
55
70
56
71
public function has (string $ collectionName ): bool
57
72
{
58
- $ type = CollectionType ::info ($ collectionName )
59
- ->useGuard (self :: $ guard );
73
+ $ type = ( $ this -> collectionClass ) ::info ($ collectionName )
74
+ ->useGuard ($ this -> guard );
60
75
61
76
try {
62
77
$ this ->client ->sendType ($ type );
@@ -69,16 +84,16 @@ public function has(string $collectionName): bool
69
84
70
85
public function drop (string $ collectionName ): void
71
86
{
72
- $ type = CollectionType ::delete ($ collectionName )
73
- ->useGuard (self :: $ guard );
87
+ $ type = ( $ this -> collectionClass ) ::delete ($ collectionName )
88
+ ->useGuard ($ this -> guard );
74
89
75
90
$ this ->client ->sendType ($ type );
76
91
}
77
92
78
93
public function count (string $ collectionName ): int
79
94
{
80
- $ type = CollectionType ::count ($ collectionName )
81
- ->useGuard (self :: $ guard );
95
+ $ type = ( $ this -> collectionClass ) ::count ($ collectionName )
96
+ ->useGuard ($ this -> guard );
82
97
83
98
$ response = $ this ->client ->sendType ($ type );
84
99
@@ -93,16 +108,16 @@ public function count(string $collectionName): int
93
108
94
109
public function get (string $ collectionName ): ResponseInterface
95
110
{
96
- $ type = CollectionType ::info ($ collectionName )
97
- ->useGuard (self :: $ guard );
111
+ $ type = ( $ this -> collectionClass ) ::info ($ collectionName )
112
+ ->useGuard ($ this -> guard );
98
113
99
114
return $ this ->client ->sendType ($ type );
100
115
}
101
116
102
117
public function truncate (string $ collectionName ): void
103
118
{
104
- $ type = CollectionType ::truncate ($ collectionName )
105
- ->useGuard (self :: $ guard );
119
+ $ type = ( $ this -> collectionClass ) ::truncate ($ collectionName )
120
+ ->useGuard ($ this -> guard );
106
121
107
122
$ this ->client ->sendType ($ type );
108
123
}
0 commit comments