Exemple #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;
 }
 /**
  * Update the map in Riak by adding/updating the counter mapped to the provided key.
  *
  * @param string  $key
  * @param integer $value
  *
  * @return \Riak\Client\Command\DataType\StoreMap
  */
 public function updateCounter($key, $value)
 {
     $this->update->updateCounter($key, new CounterOp($value));
     return $this;
 }