Skip to content

Commit 89be5db

Browse files
committed
php service level params and flutter fix
1 parent 68454ba commit 89be5db

File tree

5 files changed

+63
-38
lines changed

5 files changed

+63
-38
lines changed

templates/php/base/params.twig

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
$params = [];
2+
{% if method.parameters.all | length %}
3+
{% for parameter in method.parameters.all | filter((param) => not param.isGlobal ) %}
4+
{% if parameter.required %}
5+
if (!isset(${% if parameter.isGlobal %}this->{% endif %}{{ parameter.name | caseCamel | escapeKeyword }})) {
6+
throw new {{spec.title | caseUcfirst}}Exception('Missing required parameter: "{{ parameter.name | caseCamel | escapeKeyword }}"');
7+
}
8+
{% endif %}
9+
{% endfor %}
10+
{% for parameter in method.parameters.query %}
11+
if (!is_null(${% if parameter.isGlobal %}this->{% endif %}{{ parameter.name | caseCamel | escapeKeyword }})) {
12+
$params['{{ parameter.name }}'] = ${% if parameter.isGlobal %}this->{% endif %}{{ parameter.name | caseCamel | escapeKeyword }};
13+
}
14+
15+
{% endfor %}
16+
{% for parameter in method.parameters.body %}
17+
if (!is_null(${% if parameter.isGlobal %}this->{% endif %}{{ parameter.name | caseCamel | escapeKeyword }})) {
18+
$params['{{ parameter.name }}'] = ${% if parameter.isGlobal %}this->{% endif %}{{ parameter.name | caseCamel | escapeKeyword }};
19+
}
20+
21+
{% endfor %}
22+
{% for parameter in method.parameters.formData %}
23+
if (!is_null(${% if parameter.isGlobal %}this->{% endif %}{{ parameter.name | caseCamel | escapeKeyword }})) {
24+
$params['{{ parameter.name }}'] = ${% if parameter.isGlobal %}this->{% endif %}{{ parameter.name | caseCamel | escapeKeyword }};
25+
}
26+
{% endfor %}
27+
{% endif %}

templates/php/base/requests/params.twig

Lines changed: 0 additions & 27 deletions
This file was deleted.

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

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,31 @@ use {{ spec.title | caseUcfirst }}\InputFile;
99
1010
class {{ service.name | caseUcfirst }} extends Service
1111
{
12+
{% if service.globalParams | length %}
13+
14+
{% for parameter in service.globalParams %}
15+
protected {{ parameter.type | typeName }} ${{ parameter.name | caseCamel | escapeKeyword }};
16+
17+
public function set{{ parameter.name | caseUcfirst | escapeKeyword }}({{ parameter.type | typeName }}${{ parameter.name | caseCamel | escapeKeyword }}): void
18+
{
19+
$this->{{ parameter.name | caseCamel | escapeKeyword }} = ${{ parameter.name | caseCamel | escapeKeyword }};
20+
}
21+
22+
public function get{{ parameter.name | caseUcfirst | escapeKeyword }}({{ parameter.type | typeName }}${{ parameter.name | caseCamel | escapeKeyword }}): {{ parameter.type | typeName }}
23+
{
24+
return $this->{{ parameter.name | caseCamel | escapeKeyword }};
25+
}
26+
{% endfor %}
27+
28+
public function __construct(Client $client, {% for parameter in service.globalParams %} {{ parameter.type | typeName }}${{ parameter.name | caseCamel | escapeKeyword }}{% if not parameter.required %} = null{% endif %}{% if not loop.last %}, {% endif %}{% endfor %})
29+
{
30+
$this->client = $client;
31+
{% for parameter in service.globalParams %}
32+
$this->{{ parameter.name | caseCamel | escapeKeyword }} = ${{ parameter.name | caseCamel | escapeKeyword }};
33+
{% endfor %}
34+
}
35+
36+
{% endif %}
1237
{% for method in service.methods %}
1338
/**
1439
* {{ method.title }}
@@ -17,18 +42,18 @@ class {{ service.name | caseUcfirst }} extends Service
1742
{{ method.description|comment1 }}
1843
*
1944
{% endif %}
20-
{% for parameter in method.parameters.all %}
45+
{% for parameter in method.parameters.all | filter((param) => not param.isGlobal) %}
2146
* @param {{ parameter.type | typeName }}${{ parameter.name | caseCamel | escapeKeyword }}
2247
{% endfor %}
2348
* @throws {{spec.title | caseUcfirst}}Exception
2449
* @return {{ method | getReturn }}
2550
2651
*/
27-
public function {{ method.name | caseCamel }}({% for parameter in method.parameters.all %}{{ parameter.type | typeName }}${{ parameter.name | caseCamel | escapeKeyword }}{% if not parameter.required %} = null{% endif %}{% if not loop.last %}, {% endif %}{% endfor %}{% if 'multipart/form-data' in method.consumes %}, callable $onProgress = null{% endif %}): {{ method | getReturn }}
52+
public function {{ method.name | caseCamel }}({% for parameter in method.parameters.all | filter((param) => not param.isGlobal ) %}{{ parameter.type | typeName }}${{ parameter.name | caseCamel | escapeKeyword }}{% if not parameter.required %} = null{% endif %}{% if not loop.last %}, {% endif %}{% endfor %}{% if 'multipart/form-data' in method.consumes %}, callable $onProgress = null{% endif %}): {{ method | getReturn }}
2853
{
29-
$path = 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 }}');
54+
$path = str_replace([{% for parameter in method.parameters.path %}'{{ '{' }}{{ parameter.name | caseCamel }}{{ '}' }}'{% if not loop.last %}, {% endif %}{% endfor %}], [{% for parameter in method.parameters.path %}${% if parameter.isGlobal %}this->{% endif %}{{ parameter.name | caseCamel | escapeKeyword }}{% if not loop.last %}, {% endif %}{% endfor %}], '{{ method.path }}');
3055
31-
{{ include('php/base/requests/params.twig') }}
56+
{{ include('php/base/params.twig') }}
3257
{% if 'multipart/form-data' in method.consumes %}
3358
{{ include('php/base/requests/file.twig') }}
3459
{% else %}

tests/languages/flutter/tests.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import '../lib/models.dart';
55
void main() async {
66
WidgetsFlutterBinding.ensureInitialized();
77
Client client = Client();
8-
Foo foo = Foo(client);
8+
Foo foo = Foo(client, x: 'string');
99
Bar bar = Bar(client);
1010
General general = General(client);
1111

tests/languages/php/test.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use Appwrite\Services\General;
1717

1818
$client = new Client();
19-
$foo = new Foo($client);
19+
$foo = new Foo($client, 'string');
2020
$bar = new Bar($client);
2121
$general = new General($client);
2222

@@ -26,19 +26,19 @@
2626

2727
// Foo Service
2828

29-
$response = $foo->get('string', 123, ['string in array']);
29+
$response = $foo->get(123, ['string in array']);
3030
echo "{$response['result']}\n";
3131

32-
$response = $foo->post('string', 123, ['string in array']);
32+
$response = $foo->post(123, ['string in array']);
3333
echo "{$response['result']}\n";
3434

35-
$response = $foo->put('string', 123, ['string in array']);
35+
$response = $foo->put(123, ['string in array']);
3636
echo "{$response['result']}\n";
3737

38-
$response = $foo->patch('string', 123, ['string in array']);
38+
$response = $foo->patch(123, ['string in array']);
3939
echo "{$response['result']}\n";
4040

41-
$response = $foo->delete('string', 123, ['string in array']);
41+
$response = $foo->delete(123, ['string in array']);
4242
echo "{$response['result']}\n";
4343

4444
// Bar Service

0 commit comments

Comments
 (0)