php.blade.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. ```php
  2. $client = new \GuzzleHttp\Client();
  3. @if($hasRequestOptions)
  4. $response = $client->{{ strtolower($route['methods'][0]) }}(
  5. '{{ rtrim($baseUrl, '/') . '/' . ltrim($route['boundUri'], '/') }}',
  6. [
  7. @if(!empty($route['headers']))
  8. 'headers' => {!! \Knuckles\Scribe\Tools\WritingUtils::printPhpValue($route['headers'], 8) !!},
  9. @endif
  10. @if(!empty($route['cleanQueryParameters']))
  11. 'query' => {!! \Knuckles\Scribe\Tools\WritingUtils::printQueryParamsAsKeyValue($route['cleanQueryParameters'], "'", "=>", 12, "[]", 8) !!},
  12. @endif
  13. @if(count($route['fileParameters']))
  14. 'multipart' => [
  15. @foreach($route['cleanBodyParameters'] as $parameter => $value)
  16. @foreach(\Knuckles\Scribe\Tools\WritingUtils::getParameterNamesAndValuesForFormData($parameter, $value) as $key => $actualValue)
  17. [
  18. 'name' => '{!! $key !!}',
  19. 'contents' => '{!! $actualValue !!}'
  20. ],
  21. @endforeach
  22. @endforeach
  23. @foreach($route['fileParameters'] as $parameter => $value)
  24. @foreach(\Knuckles\Scribe\Tools\WritingUtils::getParameterNamesAndValuesForFormData($parameter, $value) as $key => $file)
  25. [
  26. 'name' => '{!! $key !!}',
  27. 'contents' => fopen('{!! $file->path() !!}', 'r')
  28. ],
  29. @endforeach
  30. @endforeach
  31. ],
  32. @elseif(!empty($route['cleanBodyParameters']))
  33. 'json' => {!! \Knuckles\Scribe\Tools\WritingUtils::printPhpValue($route['cleanBodyParameters'], 8) !!},
  34. @endif
  35. ]
  36. );
  37. @else
  38. $response = $client->{{ strtolower($route['methods'][0]) }}('{{ rtrim($baseUrl, '/') . '/' . ltrim($route['boundUri'], '/') }}');
  39. @endif
  40. $body = $response->getBody();
  41. print_r(json_decode((string) $body));
  42. ```