Skip to content

Commit

Permalink
add context bitmap
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskapp committed Sep 15, 2024
1 parent e387ade commit a967753
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/Generator/Type/CSharp.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*/
class CSharp extends GeneratorAbstract
{
public function getContentType(ContentType $contentType): string
public function getContentType(ContentType $contentType, int $context): string
{
return match ($contentType) {
ContentType::BINARY => 'byte[]',
Expand Down
2 changes: 1 addition & 1 deletion src/Generator/Type/GeneratorAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function getDocType(TypeInterface $type): string
return $this->getType($type);
}

public function getContentType(ContentType $contentType): string
public function getContentType(ContentType $contentType, int $context): string
{
return $this->getString();
}
Expand Down
7 changes: 6 additions & 1 deletion src/Generator/Type/GeneratorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
*/
interface GeneratorInterface
{
public const CONTEXT_CLIENT = 1;
public const CONTEXT_SERVER = 2;
public const CONTEXT_REQUEST = 4;
public const CONTEXT_RESPONSE = 8;

/**
* Returns a type string
*/
Expand All @@ -50,5 +55,5 @@ public function getDocType(TypeInterface $type): string;
* type it should return it, i.e. for "application/xml" Java could return "org.w3c.dom.Document" and PHP "DOMDocument".
* As default the method should simply return a string type
*/
public function getContentType(ContentType $contentType): string;
public function getContentType(ContentType $contentType, int $context): string;
}
2 changes: 1 addition & 1 deletion src/Generator/Type/Go.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*/
class Go extends GeneratorAbstract
{
public function getContentType(ContentType $contentType): string
public function getContentType(ContentType $contentType, int $context): string
{
return match ($contentType) {
ContentType::BINARY => '[]byte',
Expand Down
10 changes: 5 additions & 5 deletions src/Generator/Type/Java.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@
*/
class Java extends GeneratorAbstract
{
public function getContentType(ContentType $contentType): string
public function getContentType(ContentType $contentType, int $context): string
{
return match ($contentType) {
ContentType::BINARY => 'byte[]',
ContentType::FORM => 'java.util.Map<string, string>',
ContentType::JSON => 'Object',
ContentType::MULTIPART => 'org.apache.hc.client5.http.entity.mime.MultipartEntityBuilder',
ContentType::BINARY => 'java.io.InputStream',
ContentType::FORM => $context & self::CONTEXT_CLIENT ? 'java.util.Map<String, String>' : 'org.springframework.util.MultiValueMap<String, String>',
ContentType::JSON => $context & self::CONTEXT_CLIENT ? 'Object' : 'String',
ContentType::MULTIPART => $context & self::CONTEXT_CLIENT ? 'org.apache.hc.client5.http.entity.mime.MultipartEntityBuilder' : 'reactor.core.publisher.Mono<org.springframework.util.MultiValueMap<String, org.springframework.http.codec.multipart.Part>>',
ContentType::TEXT => $this->getString(),
ContentType::XML => 'org.w3c.dom.Document',
};
Expand Down
2 changes: 1 addition & 1 deletion src/Generator/Type/Kotlin.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*/
class Kotlin extends GeneratorAbstract
{
public function getContentType(ContentType $contentType): string
public function getContentType(ContentType $contentType, int $context): string
{
return match ($contentType) {
ContentType::BINARY => 'ByteArray',
Expand Down
8 changes: 4 additions & 4 deletions src/Generator/Type/Php.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ public function getDocType(TypeInterface $type): string
}
}

public function getContentType(ContentType $contentType): string
public function getContentType(ContentType $contentType, int $context): string
{
return match ($contentType) {
ContentType::BINARY => '\\' . StreamInterface::class,
ContentType::FORM => 'array',
ContentType::JSON => 'mixed',
ContentType::MULTIPART => 'array',
ContentType::FORM => $context & self::CONTEXT_CLIENT ? 'array' : '\\' . \stdClass::class,
ContentType::JSON => '\\' . \stdClass::class,
ContentType::MULTIPART => $context & self::CONTEXT_CLIENT ? 'array' : '\\PSX\\Data\\Reader\\Multipart',
ContentType::TEXT => $this->getString(),
ContentType::XML => '\\' . \DOMDocument::class,
};
Expand Down
2 changes: 1 addition & 1 deletion src/Generator/Type/Python.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*/
class Python extends GeneratorAbstract
{
public function getContentType(ContentType $contentType): string
public function getContentType(ContentType $contentType, int $context): string
{
return match ($contentType) {
ContentType::BINARY => 'bytearray',
Expand Down
2 changes: 1 addition & 1 deletion src/Generator/Type/Rust.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*/
class Rust extends GeneratorAbstract
{
public function getContentType(ContentType $contentType): string
public function getContentType(ContentType $contentType, int $context): string
{
return match ($contentType) {
ContentType::BINARY => 'Bytes',
Expand Down
2 changes: 1 addition & 1 deletion src/Generator/Type/Swift.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*/
class Swift extends GeneratorAbstract
{
public function getContentType(ContentType $contentType): string
public function getContentType(ContentType $contentType, int $context): string
{
return match ($contentType) {
ContentType::BINARY => 'Data',
Expand Down
2 changes: 1 addition & 1 deletion src/Generator/Type/TypeScript.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
*/
class TypeScript extends GeneratorAbstract
{
public function getContentType(ContentType $contentType): string
public function getContentType(ContentType $contentType, int $context): string
{
return match ($contentType) {
ContentType::BINARY => 'ArrayBuffer',
Expand Down
2 changes: 1 addition & 1 deletion src/Generator/Type/VisualBasic.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*/
class VisualBasic extends GeneratorAbstract
{
public function getContentType(ContentType $contentType): string
public function getContentType(ContentType $contentType, int $context): string
{
return match ($contentType) {
ContentType::BINARY => 'Byte',
Expand Down

0 comments on commit a967753

Please sign in to comment.