/**
  * Create a query filter on a date property.
  * @param $name property name
  * @param $value property value
  * @param $operator filter operator
  */
 protected static function createDateFilter($name, $value, $operator = 'greaterThan')
 {
     $date_value = new Google_Service_Datastore_Value();
     $date_time = new DateTime($value);
     $date_value->setDateTimeValue($date_time->format(DateTime::ATOM));
     $property_ref = new Google_Service_Datastore_PropertyReference();
     $property_ref->setName($name);
     $property_filter = new Google_Service_Datastore_PropertyFilter();
     $property_filter->setProperty($property_ref);
     $property_filter->setValue($date_value);
     $property_filter->setOperator($operator);
     $filter = new Google_Service_Datastore_Filter();
     $filter->setPropertyFilter($property_filter);
     return $filter;
 }
 /**
  * Configure a Value parameter, based on the supplied object-type value
  *
  * @todo Re-use one Mapper instance
  *
  * @param \Google_Service_Datastore_Value $obj_val
  * @param object $mix_value
  */
 protected function configureObjectValueParamForQuery($obj_val, $mix_value)
 {
     if ($mix_value instanceof Entity) {
         $obj_val->setKeyValue($this->createMapper()->createKey($mix_value));
     } elseif ($mix_value instanceof \DateTime) {
         $obj_val->setDateTimeValue($mix_value->format(\DateTime::ATOM));
     } 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));
     }
 }
 /**
  * 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;
 }