GDS\Mapper\ProtoBuf::configureGooglePropertyValue PHP Method

configureGooglePropertyValue() private method

Populate a ProtoBuf Property Value from a GDS Entity field definition & value
private configureGooglePropertyValue ( google\appengine\datastore\v4\Value $obj_val, array $arr_field_def, $mix_value )
$obj_val google\appengine\datastore\v4\Value
$arr_field_def array
$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_GEOPOINT:
                $obj_val->mutableGeoPointValue()->setLatitude($mix_value[0])->setLongitude($mix_value[1]);
                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']);
        }
    }