Convert booleans to string so that they're not passed as 0 and 1
public static boolToString ( array $elements ) : array | ||
$elements | array | |
return | array |
public function testBoolToString() { $array = ['key1', true, false, 'key2' => true, 'key3' => false, 'key4' => [true, false, 'key1' => true, 'key2' => false]]; $expected = ['key1', 'true', 'false', 'key2' => 'true', 'key3' => 'false', 'key4' => ['true', 'false', 'key1' => 'true', 'key2' => 'false']]; $result = QueryManipulator::boolToString($array); $this->assertSame($expected, $result); }
<?php $bodyArray = $retrofitBody->jsonSerialize(); $bodyArray = \Tebru\Retrofit\Generation\Manipulator\QueryManipulator::boolToString($bodyArray); $body = http_build_query($bodyArray);
<?php $queryArray = \Tebru\Retrofit\Generation\Manipulator\QueryManipulator::boolToString($retrofitQueryMap); $queryString = http_build_query($queryArray); $requestUrl = $this->baseUrl . '/get?' . $queryString;
<?php $queryArray = \Tebru\Retrofit\Generation\Manipulator\QueryManipulator::boolToString(array('foo' => 'bar') + $retrofitQueryMap); $queryString = http_build_query($queryArray); $requestUrl = $this->baseUrl . '/get?' . $queryString;
/** * Create serialization context * * @param HandlerContext $context * @param string $contextVar * @return null */ private function createContext(HandlerContext $context, $contextVar) { $serializationContext = $context->annotations()->getSerializationContext(); $context->body()->add('%s = \\JMS\\Serializer\\SerializationContext::create();', $contextVar); if (0 === count($serializationContext)) { return null; } if (!empty($serializationContext['groups'])) { $context->body()->add('%s->setGroups(%s);', $contextVar, $context->printer()->printArray($serializationContext['groups'])); } if (!empty($serializationContext['version'])) { $context->body()->add('%s->setVersion(%d);', $contextVar, (int) $serializationContext['version']); } if (!empty($serializationContext['serializeNull'])) { $serializeNull = QueryManipulator::boolToString([(bool) $serializationContext['serializeNull']])[0]; $context->body()->add('%s->setSerializeNull(%s);', $contextVar, $serializeNull); } if (!empty($serializationContext['enableMaxDepthChecks'])) { $context->body()->add('%s->enableMaxDepthChecks();', $contextVar); } if (!empty($serializationContext['attributes'])) { foreach ($serializationContext['attributes'] as $key => $value) { $context->body()->add('%s->setAttribute("%s", "%s");', $contextVar, $key, $value); } } }