@@ -75,7 +75,14 @@ class Document
75
75
*
76
76
* @var bool
77
77
*/
78
- protected $ _hidden = array ();
78
+ protected $ _hiddenAttributes = array ();
79
+
80
+ /**
81
+ * Flag to indicate whether document was changed locally
82
+ *
83
+ * @var bool
84
+ */
85
+ protected $ _ignoreHiddenAttributes = false ;
79
86
80
87
/**
81
88
* Document id index
@@ -100,7 +107,12 @@ class Document
100
107
/**
101
108
* hidden attribute index
102
109
*/
103
- const ENTRY_HIDDEN = '_hidden ' ;
110
+ const ENTRY_HIDDENATTRIBUTES = '_hiddenAttributes ' ;
111
+
112
+ /**
113
+ * hidden attribute index
114
+ */
115
+ const ENTRY_IGNOREHIDDENATTRIBUTES = '_ignoreHiddenAttributes ' ;
104
116
105
117
/**
106
118
* waitForSync option index
@@ -121,7 +133,12 @@ class Document
121
133
* Constructs an empty document
122
134
*
123
135
* @param array $options - optional, initial $options for document
124
- *
136
+ * <p>Options are :<br>
137
+ * <li>'_hiddenAttributes' - Set an array of hidden attributes for created documents.
138
+ * <li>'hiddenAttributes' - Deprecated, please use '_hiddenAttributes'.</li>
139
+ * <li>'_ignoreHiddenAttributes' - true to show hidden attributes. Defaults to false</li>
140
+ * <p>
141
+ * *
125
142
* @return Document
126
143
*/
127
144
public function __construct (array $ options = null )
@@ -131,8 +148,11 @@ public function __construct(array $options = null)
131
148
if (isset ($ options ['hiddenAttributes ' ])) {
132
149
$ this ->setHiddenAttributes ($ options ['hiddenAttributes ' ]);
133
150
}
134
- if (isset ($ options ['_hiddenAttributes ' ])) {
135
- $ this ->setHiddenAttributes ($ options ['_hiddenAttributes ' ]);
151
+ if (isset ($ options [self ::ENTRY_HIDDENATTRIBUTES ])) {
152
+ $ this ->setHiddenAttributes ($ options [self ::ENTRY_HIDDENATTRIBUTES ]);
153
+ }
154
+ if (isset ($ options [self ::ENTRY_IGNOREHIDDENATTRIBUTES ])) {
155
+ $ this ->setIgnoreHiddenAttributes ($ options [self ::ENTRY_IGNOREHIDDENATTRIBUTES ]);
136
156
}
137
157
if (isset ($ options [self ::ENTRY_ISNEW ])) {
138
158
$ this ->setIsNew ($ options [self ::ENTRY_ISNEW ]);
@@ -148,7 +168,7 @@ public function __construct(array $options = null)
148
168
*
149
169
* @throws ClientException
150
170
*
151
- * @param array $values - initial values for document
171
+ * @param array $values - initial values for document
152
172
* @param array $options - optional, initial options for document
153
173
*
154
174
* @return Document|Edge
@@ -161,7 +181,7 @@ public static function createFromArray(array $values, array $options = array())
161
181
}
162
182
163
183
$ document ->setChanged (true );
164
-
184
+
165
185
return $ document ;
166
186
}
167
187
@@ -174,7 +194,7 @@ public static function createFromArray(array $values, array $options = array())
174
194
*/
175
195
public function __clone ()
176
196
{
177
- $ this ->_id = null ;
197
+ $ this ->_id = null ;
178
198
$ this ->_key = null ;
179
199
$ this ->_rev = null ;
180
200
// do not change the _changed flag here
@@ -233,9 +253,9 @@ public function toSerialized($options = array())
233
253
*
234
254
* @return array - attributes array
235
255
*/
236
- public function filterHiddenAttributes ($ attributes )
256
+ public function filterHiddenAttributes ($ attributes, $ _hiddenAttributes = null )
237
257
{
238
- $ hiddenAttributes = $ this ->getHiddenAttributes ();
258
+ $ hiddenAttributes = $ _hiddenAttributes !== null ? $ _hiddenAttributes : $ this ->getHiddenAttributes ();
239
259
240
260
if (is_array ($ hiddenAttributes )) {
241
261
foreach ($ hiddenAttributes as $ hiddenAttributeName ) {
@@ -245,7 +265,7 @@ public function filterHiddenAttributes($attributes)
245
265
}
246
266
}
247
267
248
- unset ($ attributes [' _hidden ' ]);
268
+ unset ($ attributes [self :: ENTRY_HIDDENATTRIBUTES ]);
249
269
250
270
return $ attributes ;
251
271
}
@@ -259,8 +279,8 @@ public function filterHiddenAttributes($attributes)
259
279
*
260
280
* @throws ClientException
261
281
*
262
- * @param string $key - attribute name
263
- * @param mixed $value - value for attribute
282
+ * @param string $key - attribute name
283
+ * @param mixed $value - value for attribute
264
284
*
265
285
* @return void
266
286
*/
@@ -286,15 +306,15 @@ public function set($key, $value)
286
306
$ this ->setRevision ($ value );
287
307
return ;
288
308
}
289
-
309
+
290
310
if ($ key === self ::ENTRY_ISNEW ) {
291
311
$ this ->setIsNew ($ value );
292
312
return ;
293
313
}
294
314
}
295
315
296
- if (! $ this ->_changed ) {
297
- if (! isset ($ this ->_values [$ key ]) || $ this ->_values [$ key ] !== $ value ) {
316
+ if (!$ this ->_changed ) {
317
+ if (!isset ($ this ->_values [$ key ]) || $ this ->_values [$ key ] !== $ value ) {
298
318
// set changed flag
299
319
$ this ->_changed = true ;
300
320
}
@@ -313,8 +333,8 @@ public function set($key, $value)
313
333
*
314
334
* @throws ClientException
315
335
*
316
- * @param string $key - attribute name
317
- * @param mixed $value - value for attribute
336
+ * @param string $key - attribute name
337
+ * @param mixed $value - value for attribute
318
338
*
319
339
* @return void
320
340
*/
@@ -367,12 +387,14 @@ public function __get($key)
367
387
public function getAll ($ options = array ())
368
388
{
369
389
// This preserves compatibility for the old includeInternals parameter.
370
- $ includeInternals = false ;
371
- $ ignoreHiddenAttributes = false ;
390
+ $ includeInternals = false ;
391
+ $ ignoreHiddenAttributes = $ this ->{self ::ENTRY_IGNOREHIDDENATTRIBUTES };
392
+ $ _hiddenAttributes = $ this ->{self ::ENTRY_HIDDENATTRIBUTES };
372
393
373
394
if (!is_array ($ options )) {
374
395
$ includeInternals = $ options ;
375
- } else {
396
+ }
397
+ else {
376
398
// keeping the non-underscored version for backwards-compatibility
377
399
$ includeInternals = array_key_exists (
378
400
'includeInternals ' ,
@@ -391,13 +413,18 @@ public function getAll($options = array())
391
413
) ? $ options ['ignoreHiddenAttributes ' ] : $ ignoreHiddenAttributes ;
392
414
393
415
$ ignoreHiddenAttributes = array_key_exists (
394
- '_ignoreHiddenAttributes ' ,
416
+ self ::ENTRY_IGNOREHIDDENATTRIBUTES ,
417
+ $ options
418
+ ) ? $ options [self ::ENTRY_IGNOREHIDDENATTRIBUTES ] : $ ignoreHiddenAttributes ;
419
+
420
+ $ _hiddenAttributes = array_key_exists (
421
+ self ::ENTRY_HIDDENATTRIBUTES ,
395
422
$ options
396
- ) ? $ options [' _ignoreHiddenAttributes ' ] : $ ignoreHiddenAttributes ;
423
+ ) ? $ options [self :: ENTRY_HIDDENATTRIBUTES ] : $ _hiddenAttributes ;
397
424
}
398
425
399
- $ data = $ this ->_values ;
400
- $ nonInternals = array ('_changed ' , '_values ' , ' _hidden ' );
426
+ $ data = $ this ->_values ;
427
+ $ nonInternals = array ('_changed ' , '_values ' , self :: ENTRY_HIDDENATTRIBUTES );
401
428
402
429
if ($ includeInternals == true ) {
403
430
foreach ($ this as $ key => $ value ) {
@@ -407,8 +434,8 @@ public function getAll($options = array())
407
434
}
408
435
}
409
436
410
- if ($ ignoreHiddenAttributes == false ) {
411
- $ data = $ this ->filterHiddenAttributes ($ data );
437
+ if ($ ignoreHiddenAttributes === false ) {
438
+ $ data = $ this ->filterHiddenAttributes ($ data, $ _hiddenAttributes );
412
439
}
413
440
414
441
if (!is_null ($ this ->_key )) {
@@ -417,7 +444,7 @@ public function getAll($options = array())
417
444
418
445
return $ data ;
419
446
}
420
-
447
+
421
448
/**
422
449
* Get all document attributes for insertion/update
423
450
*
@@ -429,7 +456,8 @@ public function getAllForInsertUpdate()
429
456
foreach ($ this ->_values as $ key => $ value ) {
430
457
if ($ key === "_id " || $ key === "_rev " ) {
431
458
continue ;
432
- } else if ($ key === "_key " ) {
459
+ }
460
+ else if ($ key === "_key " ) {
433
461
if ($ value === null ) {
434
462
// key value not yet set
435
463
continue ;
@@ -443,8 +471,8 @@ public function getAllForInsertUpdate()
443
471
444
472
return $ data ;
445
473
}
446
-
447
-
474
+
475
+
448
476
/**
449
477
* Get all document attributes, and return an empty object if the documentapped into a DocumentWrapper class
450
478
*
@@ -459,23 +487,23 @@ public function getAllForInsertUpdate()
459
487
*/
460
488
public function getAllAsObject ($ options = array ())
461
489
{
462
- $ result = $ this ->getAll ($ options );
463
- if (count ($ result ) === 0 ) {
464
- return new \StdClass ;
465
- }
466
- return $ result ;
490
+ $ result = $ this ->getAll ($ options );
491
+ if (count ($ result ) === 0 ) {
492
+ return new \StdClass ;
493
+ }
494
+ return $ result ;
467
495
}
468
496
469
497
/**
470
498
* Set the hidden attributes
471
- *
499
+ *$cursor
472
500
* @param array $attributes - array of attributes
473
501
*
474
502
* @return void
475
503
*/
476
504
public function setHiddenAttributes (array $ attributes )
477
505
{
478
- $ this ->_hidden = $ attributes ;
506
+ $ this ->{ self :: ENTRY_HIDDENATTRIBUTES } = $ attributes ;
479
507
}
480
508
481
509
/**
@@ -485,7 +513,23 @@ public function setHiddenAttributes(array $attributes)
485
513
*/
486
514
public function getHiddenAttributes ()
487
515
{
488
- return $ this ->_hidden ;
516
+ return $ this ->{self ::ENTRY_HIDDENATTRIBUTES };
517
+ }
518
+
519
+ /**
520
+ * @return boolean
521
+ */
522
+ public function isIgnoreHiddenAttributes ()
523
+ {
524
+ return $ this ->{self ::ENTRY_IGNOREHIDDENATTRIBUTES };
525
+ }
526
+
527
+ /**
528
+ * @param boolean $ignoreHiddenAttributes
529
+ */
530
+ public function setIgnoreHiddenAttributes ($ ignoreHiddenAttributes )
531
+ {
532
+ $ this ->{self ::ENTRY_IGNOREHIDDENATTRIBUTES } = (bool ) $ ignoreHiddenAttributes ;
489
533
}
490
534
491
535
/**
0 commit comments