With the restriction that the JSON object in the database must be an array (vector or map) since this interface is built upon key-value pairs. Keys must be strings, integers or floats. Values can be of any type.
상속: extends FileDB, implements ArrayAccess, implements Countable
예제 #1
0
 function parseData()
 {
     parent::parseData();
     $f = array($this->classname, '__set_state');
     foreach ($this->data as $k => $v) {
         $this->data[$k] = call_user_func($f, $v);
     }
 }
예제 #2
0
 /**
  * Set or remove a comment.
  * 
  * By not passing the second argument the action will be to remove a comment
  * rather than setting it to null. You can also pass an array as the first
  * and only argument in which case the whole underlying data set is replaced.
  * You have been warned.
  * 
  * Return values:
  * 
  *  - After a set operation, true is returned on success, otherwise false.
  * 
  *  - After a remove operation, the removed comment is returned (if found and
  *    removed), otherwise false.
  */
 function set($index, GBComment $comment = null)
 {
     $return_value = true;
     if ($comment !== null && $comment->post === null) {
         $comment->post = $this->post;
     }
     $this->lastComment = $comment;
     if (is_string($index)) {
         $indexpath = explode('.', $index);
         if (!$indexpath) {
             return false;
         }
         if (count($indexpath) === 1) {
             return parent::set($indexpath[0], $comment);
         }
         $superCommentIndex = intval(array_shift($indexpath));
         $superComment = $this->get($superCommentIndex);
         $subCommentIndex = array_pop($indexpath);
         $parentComment = $indexpath ? $this->resolveIndexPath($indexpath, $superComment) : $superComment;
         if ($comment === null) {
             # delete
             if ($return_value = isset($parentComment->comments[$subCommentIndex])) {
                 $return_value = $parentComment->comments[$subCommentIndex];
                 unset($parentComment->comments[$subCommentIndex]);
             }
         } else {
             # set
             $parentComment->comments[$subCommentIndex] = $comment;
             $return_value = true;
         }
         parent::set($superCommentIndex, $superComment);
     } else {
         return parent::set($index, $comment);
     }
     return $return_value;
 }