Skip to content

Commit ad6710f

Browse files
committed
Fix PHP
1 parent 27b46f9 commit ad6710f

File tree

5 files changed

+28
-27
lines changed

5 files changed

+28
-27
lines changed

templates/php/base/params.twig

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,11 @@
1111
if (!is_null(${{ parameter.name | caseCamel | escapeKeyword }})) {
1212
$apiParams['{{ parameter.name }}'] = ${{ parameter.name | caseCamel | escapeKeyword }};
1313
}
14-
1514
{% endfor %}
1615
{% for parameter in method.parameters.body %}
1716
if (!is_null(${{ parameter.name | caseCamel | escapeKeyword }})) {
1817
$apiParams['{{ parameter.name }}'] = ${{ parameter.name | caseCamel | escapeKeyword }};
1918
}
20-
2119
{% endfor %}
2220
{% for parameter in method.parameters.formData %}
2321
if (!is_null(${{ parameter.name | caseCamel | escapeKeyword }})) {

templates/php/base/requests/api.twig

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
return $this->client->call(Client::METHOD_{{ method.method | caseUpper }}, $apiPath, [
2-
{% for parameter in method.parameters.header %}
3-
'{{ parameter.name }}' => ${{ parameter.name | caseCamel | escapeKeyword }},
4-
{% endfor %}
5-
{% for key, header in method.headers %}
6-
'{{ key }}' => '{{ header }}',
7-
{% endfor %}
8-
], $apiParams{% if method.type == 'webAuth' %}, "location"{% endif %});
1+
return $this->client->call(
2+
Client::METHOD_{{ method.method | caseUpper }},
3+
$apiPath,
4+
[
5+
{%~ for parameter in method.parameters.header %}
6+
'{{ parameter.name }}' => ${{ parameter.name | caseCamel | escapeKeyword }},
7+
{%~ endfor %}
8+
{%~ for key, header in method.headers %}
9+
'{{ key }}' => '{{ header }}',
10+
{%~ endfor %}
11+
],
12+
$apiParams{% if method.type == 'webAuth' -%}, 'location'{% endif %}
13+
14+
);

templates/php/src/Client.php.twig

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,9 @@ class Client
122122
*/
123123
public function call($method, $path = '', $headers = array(), array $params = array(), ?string $responseType = null)
124124
{
125-
$headers = array_merge($this->headers, $headers);
126-
$ch = curl_init($this->endpoint . $path . (($method == self::METHOD_GET && !empty($params)) ? '?' . http_build_query($params) : ''));
127-
$responseHeaders = [];
128-
$responseStatus = -1;
129-
$responseType = '';
130-
$responseBody = '';
125+
$headers = array_merge($this->headers, $headers);
126+
$ch = curl_init($this->endpoint . $path . (($method == self::METHOD_GET && !empty($params)) ? '?' . http_build_query($params) : ''));
127+
$responseHeaders = [];
131128
132129
switch ($headers['content-type']) {
133130
case 'application/json':
@@ -152,7 +149,7 @@ class Client
152149
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
153150
curl_setopt($ch, CURLOPT_USERAGENT, php_uname('s') . '-' . php_uname('r') . ':{{ language.name | caseLower }}-' . phpversion());
154151
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
155-
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, $responseType === 'location' ? false : true);
152+
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, $responseType !== 'location');
156153
curl_setopt($ch, CURLOPT_HEADERFUNCTION, function($curl, $header) use (&$responseHeaders) {
157154
$len = strlen($header);
158155
$header = explode(':', strtolower($header), 2);

templates/php/src/Services/Service.php.twig

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ class {{ service.name | caseUcfirst }} extends Service
4949
{
5050
$apiPath = str_replace([{% for parameter in method.parameters.path %}'{{ '{' }}{{ parameter.name | caseCamel }}{{ '}' }}'{% if not loop.last %}, {% endif %}{% endfor %}], [{% for parameter in method.parameters.path %}${{ parameter.name | caseCamel | escapeKeyword }}{% if not loop.last %}, {% endif %}{% endfor %}], '{{ method.path }}');
5151
52-
{{ include('php/base/params.twig') }}
53-
{% if 'multipart/form-data' in method.consumes %}
54-
{{ include('php/base/requests/file.twig') }}
55-
{% else %}
56-
{{ include('php/base/requests/api.twig') }}
57-
{% endif %}
52+
{{~ include('php/base/params.twig') -}}
53+
{%~ if 'multipart/form-data' in method.consumes %}
54+
{{~ include('php/base/requests/file.twig') }}
55+
{%~ else %}
56+
{{~ include('php/base/requests/api.twig') }}
57+
{%~ endif %}
5858
}
59-
{% if not loop.last %}
59+
{%~ if not loop.last %}
6060
61-
{% endif %}
62-
{% endfor %}
61+
{%~ endif %}
62+
{%~ endfor %}
6363
}

tests/languages/php/test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@
110110
$general->empty();
111111

112112
$url = $general->oauth2('clientId', 'https://localhost', ['test'], '123456');
113-
echo $url;
113+
echo $url . "\n";
114114

115115
// Query helper tests
116116
echo Query::equal('released', [true]) . "\n";

0 commit comments

Comments
 (0)