示例#1
0
 /**
  * @param array $updates
  *
  * @return \Riak\Client\Command\DataType\SetUpdate
  */
 public static function createFromArray(array $updates)
 {
     $update = new MapUpdate();
     foreach ($updates as $key => $val) {
         if (is_bool($val)) {
             $update->updateFlag($key, new FlagOp($val));
             continue;
         }
         if (is_string($val)) {
             $update->updateRegister($key, new RegisterOp($val));
             continue;
         }
         if (is_int($val)) {
             $update->updateCounter($key, new CounterOp($val));
             continue;
         }
         if (is_array($val) && $val === array_values($val)) {
             $update->updateSet($key, new SetOp($val, []));
             continue;
         }
         if (is_array($val)) {
             $update->updateMap($key, self::createFromArray($val)->getOp());
             continue;
         }
         $message = 'Map element "%s" must be of the type (boolean, string, integer, or an array), "%s" given.';
         $type = is_object($val) ? get_class($val) : gettype($val);
         throw new InvalidArgumentException(sprintf($message, $key, $type));
     }
     return $update;
 }
示例#2
0
 /**
  * Update the map in Riak by adding/updating the map mapped to the provided key.
  *
  * @param string                                        $key
  * @param \Riak\Client\Command\DataType\MapUpdate|array $value
  *
  * @return \Riak\Client\Command\DataType\StoreMap
  */
 public function updateMap($key, $value)
 {
     $update = !$value instanceof MapUpdate ? MapUpdate::createFromArray($value) : $value;
     $this->update->updateMap($key, $update->getOp());
     return $this;
 }