File tree Expand file tree Collapse file tree 2 files changed +15
-5
lines changed Expand file tree Collapse file tree 2 files changed +15
-5
lines changed Original file line number Diff line number Diff line change @@ -50,7 +50,7 @@ public function getAllDocs($options = []) : array
50
50
// we have some data - extract the docs to return
51
51
$ docs = [];
52
52
foreach ($ json_data ["rows " ] as $ document ) {
53
- $ docs [] = new Document ($ document ["doc " ]);
53
+ $ docs [] = new Document ($ this -> client , $ this -> db_name , $ document ["doc " ]);
54
54
}
55
55
return $ docs ;
56
56
} else {
@@ -117,8 +117,8 @@ public function getDocById($id) : \PHPCouchDB\Document
117
117
$ endpoint = "/ " . $ this ->db_name . "/ " . $ id ;
118
118
$ response = $ this ->client ->request ("GET " , $ endpoint );
119
119
if ($ response ->getStatusCode () == 200 ) {
120
- if ($ json_data = json_decode ($ response ->getBody (), true )) {
121
- $ doc = new Document ($ json_data );
120
+ if ($ data = json_decode ($ response ->getBody (), true )) {
121
+ $ doc = new Document ($ this -> client , $ this -> db_name , $ data );
122
122
return $ doc ;
123
123
} else {
124
124
throw new \PHPCouchDB \Exception \ServerException ('JSON response not received or not understood ' );
Original file line number Diff line number Diff line change 8
8
9
9
/**
10
10
* Documents are the "rows" in a document database. The object has keys and
11
- * values to represent the keys and values of the document.
11
+ * values to represent the keys and values of the document. Operations on
12
+ * an existing document, such as update and delete, are done by this object
12
13
*/
13
14
14
15
15
16
class Document
16
17
{
18
+ protected $ client ;
19
+ protected $ db_name ;
20
+
17
21
/**
18
22
* Usually constructed by the Database object as it gets documents for us
19
23
*
24
+ * @param \GuzzleHTTP\ClientInterface $client Our HTTP client
25
+ * @param string $db_name The database this document is in
20
26
* @param array $data Representation of the document
21
27
*/
22
- public function __construct ($ data )
28
+ */
29
+
30
+ public function __construct (\GuzzleHttp \ClientInterface $ client , string $ db_name , array $ data )
23
31
{
32
+ $ this ->client = $ client ;
33
+ $ this ->db_name = $ db_name ;
24
34
// possibly overly simple!
25
35
// Add all array elements as properties on the new object
26
36
foreach ($ data as $ field => $ value ) {
You can’t perform that action at this time.
0 commit comments