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 flag mapped to the provided key.
  *
  * @param string  $key
  * @param boolean $value
  *
  * @return \Riak\Client\Command\DataType\StoreMap
  */
 public function updateFlag($key, $value)
 {
     $this->update->updateFlag($key, new FlagOp($value));
     return $this;
 }