/**
  * Create a property object
  *
  * @param array $arr_field_def
  * @param $mix_value
  * @return mixed
  */
 protected function createProperty(array $arr_field_def, $mix_value)
 {
     $obj_property = new \Google_Service_Datastore_Property();
     // Indexed?
     $bol_index = TRUE;
     if (isset($arr_field_def['index']) && FALSE === $arr_field_def['index']) {
         $bol_index = FALSE;
     }
     $obj_property->setIndexed($bol_index);
     switch ($arr_field_def['type']) {
         case Schema::PROPERTY_STRING:
             $obj_property->setStringValue((string) $mix_value);
             break;
         case Schema::PROPERTY_INTEGER:
             $obj_property->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_property->setDateTimeValue($obj_dtm->format(\DateTime::ATOM));
             break;
         case Schema::PROPERTY_DOUBLE:
         case Schema::PROPERTY_FLOAT:
             $obj_property->setDoubleValue(floatval($mix_value));
             break;
         case Schema::PROPERTY_BOOLEAN:
             $obj_property->setBooleanValue((bool) $mix_value);
             break;
         case Schema::PROPERTY_STRING_LIST:
             $obj_property->setIndexed(null);
             // Ensure we only index the values, not the list
             $arr_values = [];
             foreach ((array) $mix_value as $str) {
                 $obj_value = new \Google_Service_Datastore_Value();
                 $obj_value->setStringValue($str);
                 $obj_value->setIndexed($bol_index);
                 $arr_values[] = $obj_value;
             }
             $obj_property->setListValue($arr_values);
             break;
         default:
             throw new \RuntimeException('Unable to process field type: ' . $arr_field_def['type']);
     }
     return $obj_property;
 }
 /**
  * Create date property.
  */
 protected function createDateProperty($date, $indexed = false)
 {
     $prop = new Google_Service_Datastore_Property();
     $dateValue = new DateTime($date);
     $prop->setDateTimeValue($dateValue->format(DateTime::ATOM));
     $prop->setIndexed($indexed);
     return $prop;
 }
示例#3
0
 protected function createProperty($input, $indexed = false, $type = null)
 {
     $prop = new \Google_Service_Datastore_Property();
     if (is_string($input)) {
         $prop->setStringValue($input);
         $prop->setIndexed($indexed);
     } elseif ($type == self::TYPE_DATE) {
         $date = new DateTime($input);
         $prop->setDateTimeValue($date->format(DateTime::ATOM));
         $prop->setIndexed($indexed);
     } else {
         if (is_array($input)) {
             $values = [];
             foreach ($input as $s) {
                 $value = new \Google_Service_Datastore_Value();
                 $value->setStringValue($s);
                 $value->setIndexed($indexed);
                 $values[] = $value;
             }
             $prop->setListValue($values);
         }
     }
     return $prop;
 }
 /**
  * @param mixed $value
  * @param Type|string $type
  * @param boolean $indexed
  * @return \Google_Service_Datastore_Property
  */
 public static function newProperty($value, $type, $indexed = true)
 {
     $property = new \Google_Service_Datastore_Property();
     if ($value instanceof \DateTime) {
         $value = $value->format(DateTime::ATOM);
     } else {
         if ($value instanceof BaseEntityModel) {
             $value = $value->exportEntity();
         }
     }
     call_user_func([$property, Type::get($type)->getFuncName('set')], $value);
     if ($indexed === true) {
         $property->setIndexed($indexed);
     }
     return $property;
 }
示例#5
0
 /**
  * Create boolean property.
  */
 protected function createBooleanProperty($b, $indexed = false)
 {
     $prop = new Google_Service_Datastore_Property();
     $prop->setBooleanValue($b);
     $prop->setIndexed($indexed);
     return $prop;
 }