Compare commits

..

No commits in common. "a16cb846f349b4309bb271c5d734a6089c6f7830" and "b3b628ba67372cfc2d5eb0637f772e8a4a4b8a9f" have entirely different histories.

5 changed files with 8 additions and 29 deletions

View File

@ -58,8 +58,8 @@ class Rest implements AdapterInterface
case is_object($value): case is_object($value):
return Ulmus::convertObject($value); return Ulmus::convertObject($value);
# case is_array($value): case is_array($value):
# return json_encode($value); return json_encode($value);
case is_bool($value): case is_bool($value):
return (int) $value; return (int) $value;
@ -77,4 +77,4 @@ class Rest implements AdapterInterface
{ {
return RequestBuilder::class; return RequestBuilder::class;
} }
} }

View File

@ -47,7 +47,7 @@ class ApiRepository extends \Ulmus\Repository
public function save(object|array $entity, ?array $fieldsAndValue = null, bool $replace = false): bool public function save(object|array $entity, ?array $fieldsAndValue = null, bool $replace = false): bool
{ {
$response = $this->executeRequest(Attribute\Obj\Api\Create::class, $entity->entityGetDataset()); $response = $this->executeRequest(Attribute\Obj\Api\Create::class, $entity->entityLoadedDataset);
$entity->fromArray($response->getParsedBody()); $entity->fromArray($response->getParsedBody());

View File

@ -9,7 +9,7 @@ trait JsonMessageTrait
{ {
public function getParsedBody(): mixed public function getParsedBody(): mixed
{ {
return JsonStream::fromJsonEncoded( $this->getBody()->getContents() )->decode() ; return JsonStream::fromJsonEncoded( $this->getBody()->getContents() )->decode();
} }
public function withParsedBody(mixed $data) : MessageInterface public function withParsedBody(mixed $data) : MessageInterface

View File

@ -45,12 +45,6 @@ class JsonStream extends Stream
public function decode(): mixed public function decode(): mixed
{ {
$content = $this->getContents(); return json_decode($this->getContents(), true, $this->depth, $this->decodingOptions);
if ($content === "") {
return null;
}
return json_decode($content, true, $this->depth, $this->decodingOptions);
} }
} }

View File

@ -5,7 +5,7 @@ namespace Ulmus\Api\Transport;
use Ulmus\Api\Common\{ ContentTypeEnum, MethodEnum, HttpHeaderEnum }; use Ulmus\Api\Common\{ ContentTypeEnum, MethodEnum, HttpHeaderEnum };
use Ulmus\Api\Stream\JsonStream; use Ulmus\Api\Stream\JsonStream;
use Ulmus\Api\Stream\Stream; use Ulmus\Api\Stream\Stream;
use Psr\Http\Message\{RequestInterface, ResponseInterface, StreamInterface}; use Psr\Http\Message\{ RequestInterface, ResponseInterface };
use Ulmus\Api\Response\{ Response, JsonResponse }; use Ulmus\Api\Response\{ Response, JsonResponse };
abstract class CurlTransport { abstract class CurlTransport {
@ -14,8 +14,6 @@ abstract class CurlTransport {
public int $maximumRedirections = 10; public int $maximumRedirections = 10;
protected StreamInterface $stderr;
public function __construct( public function __construct(
public array $headers = [], public array $headers = [],
public array $curlOptions = [], public array $curlOptions = [],
@ -23,7 +21,6 @@ abstract class CurlTransport {
public ContentTypeEnum $contentType = ContentTypeEnum::Json, public ContentTypeEnum $contentType = ContentTypeEnum::Json,
# Matching Guzzle's great user-agent syntax # Matching Guzzle's great user-agent syntax
public string $userAgent = "ulmus-api/1.0 curl/{curl} php/{php}", public string $userAgent = "ulmus-api/1.0 curl/{curl} php/{php}",
public bool $debug = false,
) { ) {
$this->userAgent = str_replace([ '{curl}', '{php}', ], [ curl_version()['version'] ?? "???", phpversion() ], $this->userAgent); $this->userAgent = str_replace([ '{curl}', '{php}', ], [ curl_version()['version'] ?? "???", phpversion() ], $this->userAgent);
} }
@ -62,11 +59,6 @@ abstract class CurlTransport {
{ {
$response = new Response(); $response = new Response();
if ($this->debug) {
$this->stderr = Stream::fromMemory();
$stderrResource = $this->stderr->detach();
}
$headers = array_merge_recursive(HttpHeaderEnum::normalizeHeaderArray($headers), HttpHeaderEnum::normalizeHeaderArray($this->headers)); $headers = array_merge_recursive(HttpHeaderEnum::normalizeHeaderArray($headers), HttpHeaderEnum::normalizeHeaderArray($this->headers));
$options += $this->curlOptions; $options += $this->curlOptions;
@ -100,10 +92,7 @@ abstract class CurlTransport {
return strlen($headerLine); return strlen($headerLine);
} }
] + ( $this->debug ? [ ];
CURLOPT_VERBOSE => true,
CURLOPT_STDERR => $stderrResource,
] : [] );
$ch = curl_init(); $ch = curl_init();
@ -118,10 +107,6 @@ abstract class CurlTransport {
throw new \Exception(implode(PHP_EOL, $errors), $errno); throw new \Exception(implode(PHP_EOL, $errors), $errno);
} }
if ($this->debug) {
$this->stderr->attach($stderrResource);
}
$response = $response->withBody( Stream::fromMemory($result) ); $response = $response->withBody( Stream::fromMemory($result) );
if ( $response->hasHeader('Content-Type') && false !== strpos($response->getHeader('Content-Type')[0], 'json') ) { if ( $response->hasHeader('Content-Type') && false !== strpos($response->getHeader('Content-Type')[0], 'json') ) {