diff --git a/src/Admin/Classes/FullBodyLocation.php b/src/Admin/Classes/FullBodyLocation.php index ae6c142..a4237ca 100644 --- a/src/Admin/Classes/FullBodyLocation.php +++ b/src/Admin/Classes/FullBodyLocation.php @@ -2,13 +2,18 @@ namespace Keycloak\Admin\Classes; -use \GuzzleHttp\Command\CommandInterface; -use \GuzzleHttp\Command\Guzzle\Operation; -use \GuzzleHttp\Command\Guzzle\Parameter; -use \GuzzleHttp\Psr7; -use \Psr\Http\Message\MessageInterface; -use \Psr\Http\Message\RequestInterface; -use \GuzzleHttp\Command\Guzzle\RequestLocation\JsonLocation; +use GuzzleHttp\Command\CommandInterface; +use GuzzleHttp\Command\Guzzle\Operation; +use GuzzleHttp\Command\Guzzle\Parameter; +use GuzzleHttp\Psr7; +use GuzzleHttp\Psr7\Utils; +use Psr\Http\Message\MessageInterface; +use Psr\Http\Message\RequestInterface; +use GuzzleHttp\Command\Guzzle\RequestLocation\JsonLocation; + +use Psr\Http\Message\StreamInterface; + +use function GuzzleHttp\Psr7\stream_for; /** * Creates a JSON document @@ -53,11 +58,26 @@ public function visit( $request = $request->withHeader('Content-Type', $this->jsonContentType); } - return $request->withBody(Psr7\stream_for(\GuzzleHttp\json_encode($this->jsonData))); + return $request->withBody($this->getStream(\GuzzleHttp\json_encode($this->jsonData))); } public function after(CommandInterface $command, RequestInterface $request, Operation $operation) { return $request; } + + /** + * Create stream from given data + * + * @param string $data + * @return StreamInterface + */ + final protected function getStream($data) + { + if (class_exists(Utils::class)) { + return Utils::streamFor($data); // guzzlehttp/psr7 >= 2.0 + } + + return stream_for($data); // guzzlehttp/psr7 < 2.0 + } } diff --git a/src/Admin/Resources/keycloak-1_0.php b/src/Admin/Resources/keycloak-1_0.php index 479de2a..c1e7826 100644 --- a/src/Admin/Resources/keycloak-1_0.php +++ b/src/Admin/Resources/keycloak-1_0.php @@ -3693,7 +3693,7 @@ ), 'partialImportRealm' => array( - 'uri' => 'auth/admin/realms/{realm}/partial-export', + 'uri' => 'auth/admin/realms/{realm}/partialImport', 'description' => 'Partial import from a JSON file to an existing realm.', 'httpMethod' => 'POST', 'parameters' => array(