php.md.blade.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. @php
  2. use Knuckles\Scribe\Tools\WritingUtils as u;
  3. /** @var Knuckles\Camel\Output\OutputEndpointData $endpoint */
  4. @endphp
  5. ```php
  6. $client = new \GuzzleHttp\Client();
  7. @if($endpoint->hasHeadersOrQueryOrBodyParams())
  8. $response = $client->{{ strtolower($endpoint->httpMethods[0]) }}(
  9. '{{ rtrim($baseUrl, '/') . '/' . ltrim($endpoint->boundUri, '/') }}',
  10. [
  11. @if(!empty($endpoint->headers))
  12. 'headers' => {!! u::printPhpValue($endpoint->headers, 8) !!},
  13. @endif
  14. @if(!empty($endpoint->cleanQueryParameters))
  15. 'query' => {!! u::printQueryParamsAsKeyValue($endpoint->cleanQueryParameters, "'", "=>", 12, "[]", 8) !!},
  16. @endif
  17. @if($endpoint->hasFiles())
  18. 'multipart' => [
  19. @foreach($endpoint->cleanBodyParameters as $parameter => $value)
  20. @foreach(u::getParameterNamesAndValuesForFormData($parameter, $value) as $key => $actualValue)
  21. [
  22. 'name' => '{!! $key !!}',
  23. 'contents' => '{!! $actualValue !!}'
  24. ],
  25. @endforeach
  26. @endforeach
  27. @foreach($endpoint->fileParameters as $parameter => $value)
  28. @foreach(u::getParameterNamesAndValuesForFormData($parameter, $value) as $key => $file)
  29. [
  30. 'name' => '{!! $key !!}',
  31. 'contents' => fopen('{!! $file->path() !!}', 'r')
  32. ],
  33. @endforeach
  34. @endforeach
  35. ],
  36. @elseif(!empty($endpoint->cleanBodyParameters))
  37. @if ($endpoint->headers['Content-Type'] == 'application/x-www-form-urlencoded')
  38. 'form_params' => {!! u::printPhpValue($endpoint->cleanBodyParameters, 8) !!},
  39. @else
  40. 'json' => {!! u::printPhpValue($endpoint->cleanBodyParameters, 8) !!},
  41. @endif
  42. @endif
  43. ]
  44. );
  45. @else
  46. $response = $client->{{ strtolower($endpoint->httpMethods[0]) }}('{{ rtrim($baseUrl, '/') . '/' . ltrim($endpoint->boundUri, '/') }}');
  47. @endif
  48. $body = $response->getBody();
  49. print_r(json_decode((string) $body));
  50. ```