-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The previously used library Buzz lacks support of symfony/options-resolver v7. It seems that the package is not well-maintained anymore. So we switch to Guzzle instead. For the user of the JobRouter REST Client library nothing has changed.
- Loading branch information
1 parent
b7bcf6a
commit a38d16a
Showing
16 changed files
with
495 additions
and
253 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the JobRouter REST Client. | ||
* https://github.com/jobrouter/php-rest-client | ||
* | ||
* For the full copyright and license information, please view the | ||
* LICENSE.txt file that was distributed with this source code. | ||
*/ | ||
|
||
namespace JobRouter\AddOn\RestClient\Exception; | ||
|
||
final class FileNotFoundException extends \RuntimeException implements ExceptionInterface | ||
{ | ||
public static function fromEmptyPath(): self | ||
{ | ||
return new self('No file path given', 1724230703); | ||
} | ||
|
||
public static function fromPath(string $path, \Throwable $previous): self | ||
{ | ||
return new self( | ||
\sprintf( | ||
'File with path "%s" does not exist', | ||
$path, | ||
), | ||
1724230704, | ||
$previous, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the JobRouter REST Client. | ||
* https://github.com/jobrouter/php-rest-client | ||
* | ||
* For the full copyright and license information, please view the | ||
* LICENSE.txt file that was distributed with this source code. | ||
*/ | ||
|
||
namespace JobRouter\AddOn\RestClient\Mapper; | ||
|
||
use GuzzleHttp\Psr7\Utils; | ||
use JobRouter\AddOn\RestClient\Exception\FileNotFoundException; | ||
use JobRouter\AddOn\RestClient\Resource\FileInterface; | ||
|
||
final class MultipartFormDataMapper | ||
{ | ||
/** | ||
* @param array<string, string|int|float|bool|FileInterface|array{path: non-empty-string, filename?: string, contentType?: string}> $data | ||
* @return list<array{name: string, contents: string|resource, filename? :string, headers? :array{Content-Type: string}}> | ||
*/ | ||
public function map(array $data): array | ||
{ | ||
return \array_map(static function (string $name, string|int|float|bool|FileInterface|array $value): array { | ||
if ($value instanceof FileInterface) { | ||
$value = $value->toArray(); | ||
} | ||
if (\is_array($value)) { | ||
// @phpstan-ignore-next-line Offset 'path' always exists and is not nullable. | ||
if (! isset($value['path'])) { | ||
throw FileNotFoundException::fromEmptyPath(); | ||
} | ||
|
||
try { | ||
$multipart = [ | ||
'name' => $name, | ||
'contents' => Utils::tryFopen($value['path'], 'r'), | ||
]; | ||
} catch (\RuntimeException $e) { | ||
throw FileNotFoundException::fromPath($value['path'], $e); | ||
} | ||
if (($value['filename'] ?? '') !== '') { | ||
$multipart['filename'] = $value['filename']; | ||
} | ||
if (($value['contentType'] ?? '') !== '') { | ||
$multipart['headers'] = [ | ||
'Content-Type' => $value['contentType'], | ||
]; | ||
} | ||
|
||
return $multipart; | ||
} | ||
|
||
// @phpstan-ignore-next-line Use value object over return of values | ||
return [ | ||
'name' => $name, | ||
'contents' => (string)$value, | ||
]; | ||
}, \array_keys($data), \array_values($data)); | ||
Check warning on line 62 in src/Mapper/MultipartFormDataMapper.php GitHub Actions / Code Quality
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.