Ejemplo n.º 1
0
 /**
  * Configure a Value parameter, based on the supplied object-type value
  *
  * @todo Re-use one Mapper instance
  *
  * @param \google\appengine\datastore\v4\Value $obj_val
  * @param object $mix_value
  */
 protected function configureObjectValueParamForQuery($obj_val, $mix_value)
 {
     if ($mix_value instanceof Entity) {
         $this->createMapper()->configureGoogleKey($obj_val->mutableKeyValue(), $mix_value);
     } elseif ($mix_value instanceof \DateTime) {
         $obj_val->setTimestampMicrosecondsValue($mix_value->format('Uu'));
     } elseif (method_exists($mix_value, '__toString')) {
         $obj_val->setStringValue($mix_value->__toString());
     } else {
         throw new \InvalidArgumentException('Unexpected, non-string-able object parameter: ' . get_class($mix_value));
     }
 }
Ejemplo n.º 2
0
 /**
  * Populate a ProtoBuf Property Value from a GDS Entity field definition & value
  *
  * @todo compare with Google API implementation
  *
  * @param Value $obj_val
  * @param array $arr_field_def
  * @param $mix_value
  */
 private function configureGooglePropertyValue(Value $obj_val, array $arr_field_def, $mix_value)
 {
     // Indexed?
     $bol_index = TRUE;
     if (isset($arr_field_def['index']) && FALSE === $arr_field_def['index']) {
         $bol_index = FALSE;
     }
     $obj_val->setIndexed($bol_index);
     // null checks
     if (null === $mix_value) {
         return;
     }
     // Value
     switch ($arr_field_def['type']) {
         case Schema::PROPERTY_STRING:
             $obj_val->setStringValue((string) $mix_value);
             break;
         case Schema::PROPERTY_INTEGER:
             $obj_val->setIntegerValue((int) $mix_value);
             break;
         case Schema::PROPERTY_DATETIME:
             if ($mix_value instanceof \DateTime) {
                 $obj_dtm = $mix_value;
             } else {
                 $obj_dtm = new \DateTime($mix_value);
             }
             $obj_val->setTimestampMicrosecondsValue($obj_dtm->format('Uu'));
             break;
         case Schema::PROPERTY_DOUBLE:
         case Schema::PROPERTY_FLOAT:
             $obj_val->setDoubleValue(floatval($mix_value));
             break;
         case Schema::PROPERTY_BOOLEAN:
             $obj_val->setBooleanValue((bool) $mix_value);
             break;
         case Schema::PROPERTY_STRING_LIST:
             $obj_val->clearIndexed();
             // Ensure we only index the values, not the list
             foreach ((array) $mix_value as $str) {
                 $obj_val->addListValue()->setStringValue($str)->setIndexed($bol_index);
             }
             break;
         default:
             throw new \RuntimeException('Unable to process field type: ' . $arr_field_def['type']);
     }
 }