Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/SDK/Language/Dart.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Appwrite\SDK\Language;

use Appwrite\SDK\Language;
use Twig\TwigFilter;

class Dart extends Language {

Expand Down Expand Up @@ -434,4 +435,17 @@ public function getFiles()
],
];
}

public function getFilters(): array
{
return [
new TwigFilter('dartComment', function ($value) {
$value = explode("\n", $value);
foreach ($value as $key => $line) {
$value[$key] = " /// " . wordwrap($value[$key], 75, "\n /// ");
}
return implode("\n", $value);
}, ['is_safe' => ['html']]),
];
}
}
14 changes: 14 additions & 0 deletions src/SDK/Language/DotNet.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Appwrite\SDK\Language;

use Appwrite\SDK\Language;
use Twig\TwigFilter;

class DotNet extends Language {

Expand Down Expand Up @@ -376,5 +377,18 @@ public function getFiles()
]
];
}

public function getFilters(): array
{
return [
new TwigFilter('dotnetComment', function ($value) {
$value = explode("\n", $value);
foreach ($value as $key => $line) {
$value[$key] = " /// " . wordwrap($value[$key], 75, "\n /// ");
}
return implode("\n", $value);
}, ['is_safe' => ['html']])
];
}
}

14 changes: 14 additions & 0 deletions src/SDK/Language/Go.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Appwrite\SDK\Language;

use Appwrite\SDK\Language;
use Twig\TwigFilter;

class Go extends Language {

Expand Down Expand Up @@ -246,4 +247,17 @@ public function getParamExample(array $param)

return $output;
}

public function getFilters(): array
{
return [
new TwigFilter('godocComment', function ($value) {
$value = explode("\n", $value);
foreach ($value as $key => $line) {
$value[$key] = "// " . wordwrap($value[$key], 75, "\n// ");
}
return implode("\n", $value);
}, ['is_safe' => ['html']])
];
}
}
18 changes: 18 additions & 0 deletions src/SDK/Language/PHP.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Appwrite\SDK\Language;

use Appwrite\SDK\Language;
use Twig\TwigFilter;

class PHP extends Language {

Expand Down Expand Up @@ -356,4 +357,21 @@ protected function jsonToAssoc(array $data):string

return $output;
}

protected function getReturn(array $method): string
{
if(($method['emptyResponse'] ?? true) || $method['type'] === 'location') {
return 'string';
}

return 'array';
}

public function getFilters(): array {
return [
new TwigFilter('getReturn', function($value) {
return $this->getReturn($value);
})
];
}
}
14 changes: 14 additions & 0 deletions src/SDK/Language/Ruby.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Appwrite\SDK\Language;

use Appwrite\SDK\Language;
use Twig\TwigFilter;

class Ruby extends Language {

Expand Down Expand Up @@ -327,4 +328,17 @@ protected function jsonToHash(array $data):string

return $output;
}

public function getFilters(): array
{
return [
new TwigFilter('rubyComment', function ($value) {
$value = explode("\n", $value);
foreach ($value as $key => $line) {
$value[$key] = " # " . wordwrap($line, 75, "\n # ");
}
return implode("\n", $value);
}, ['is_safe' => ['html']])
];
}
}
14 changes: 14 additions & 0 deletions src/SDK/Language/Swift.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Appwrite\SDK\Language;

use Appwrite\SDK\Language;
use Twig\TwigFilter;

class Swift extends Language {

Expand Down Expand Up @@ -432,4 +433,17 @@ public function getParamExample(array $param)

return $output;
}

public function getFilters(): array
{
return [
new TwigFilter('swiftComment', function ($value) {
$value = explode("\n", $value);
foreach ($value as $key => $line) {
$value[$key] = " /// " . wordwrap($value[$key], 75, "\n /// ");
}
return implode("\n", $value);
}, ['is_safe' => ['html']])
];
}
}
15 changes: 15 additions & 0 deletions src/SDK/Language/Web.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Twig\TwigFilter;


class Web extends JS
{

Expand Down Expand Up @@ -337,6 +338,20 @@ public function getFilters(): array
new TwigFilter('getReturn', function (array $method, array $spec) {
return $this->getReturn($method, $spec);
}),
new TwigFilter('comment2', function ($value) {
$value = explode("\n", $value);
foreach ($value as $key => $line) {
$value[$key] = " * " . wordwrap($value[$key], 75, "\n * ");
}
return implode("\n", $value);
}, ['is_safe' => ['html']]),
new TwigFilter('comment3', function ($value) {
$value = explode("\n", $value);
foreach ($value as $key => $line) {
$value[$key] = " * " . wordwrap($value[$key], 75, "\n * ");
}
return implode("\n", $value);
}, ['is_safe' => ['html']]),
];
}
}
57 changes: 0 additions & 57 deletions src/SDK/SDK.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,48 +141,6 @@ public function __construct(Language $language, Spec $spec)
}
return implode("\n", $value);
}, ['is_safe' => ['html']]));
$this->twig->addFilter(new TwigFilter('comment2', function ($value) {
$value = explode("\n", $value);
foreach ($value as $key => $line) {
$value[$key] = " * " . wordwrap($value[$key], 75, "\n * ");
}
return implode("\n", $value);
}, ['is_safe' => ['html']]));
$this->twig->addFilter(new TwigFilter('comment3', function ($value) {
$value = explode("\n", $value);
foreach ($value as $key => $line) {
$value[$key] = " * " . wordwrap($value[$key], 75, "\n * ");
}
return implode("\n", $value);
}, ['is_safe' => ['html']]));
$this->twig->addFilter(new TwigFilter('dartComment', function ($value) {
$value = explode("\n", $value);
foreach ($value as $key => $line) {
$value[$key] = " /// " . wordwrap($value[$key], 75, "\n /// ");
}
return implode("\n", $value);
}, ['is_safe' => ['html']]));
$this->twig->addFilter(new TwigFilter('dotnetComment', function ($value) {
$value = explode("\n", $value);
foreach ($value as $key => $line) {
$value[$key] = " /// " . wordwrap($value[$key], 75, "\n /// ");
}
return implode("\n", $value);
}, ['is_safe' => ['html']]));
$this->twig->addFilter(new TwigFilter('swiftComment', function ($value) {
$value = explode("\n", $value);
foreach ($value as $key => $line) {
$value[$key] = " /// " . wordwrap($value[$key], 75, "\n /// ");
}
return implode("\n", $value);
}, ['is_safe' => ['html']]));
$this->twig->addFilter(new TwigFilter('rubyComment', function ($value) {
$value = explode("\n", $value);
foreach ($value as $key => $line) {
$value[$key] = " # " . wordwrap($line, 75, "\n # ");
}
return implode("\n", $value);
}, ['is_safe' => ['html']]));
$this->twig->addFilter(new TwigFilter('escapeDollarSign', function ($value) {
return str_replace('$', '\$', $value);
}, ['is_safe'=>['html']]));
Expand All @@ -199,28 +157,13 @@ public function __construct(Language $language, Spec $spec)
$this->twig->addFilter(new TwigFilter('html', function ($value) {
return $value;
}, ['is_safe' => ['html']]));
$this->twig->addFilter(new TwigFilter('godocComment', function ($value) {
$value = explode("\n", $value);
foreach ($value as $key => $line) {
$value[$key] = "// " . wordwrap($value[$key], 75, "\n// ");
}
return implode("\n", $value);
}, ['is_safe' => ['html']]));
$this->twig->addFilter(new TwigFilter('escapeKeyword', function ($value) use ($language) {
if(in_array($value, $language->getKeywords())) {
return 'x' . $value;
}

return $value;
}, ['is_safe' => ['html']]));
$this->twig->addFilter(new TwigFilter('ucFirstAndEscape', function ($value) use ($language) {
$value = ucfirst((string)$this->helperCamelCase($value));
if(in_array($value, $language->getKeywords())) {
$value = 'x' . $value;
}

return ucfirst((string)$this->helperCamelCase($value));
}, ['is_safe' => ['html']]));
$this->twig->addFilter(new TwigFilter('caseHTML', function ($value) {
return $value;
}, ['is_safe' => ['html']]));
Expand Down
5 changes: 5 additions & 0 deletions src/Spec/Swagger2.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,11 @@ public function getMethods($service)

$responses = $method['responses'];
$responseModel = '';
$emptyResponse = true;
foreach($responses as $code => $desc) {
if($code != '204') {
$emptyResponse = false;
}
if(isset($desc['schema']) && isset($desc['schema']['$ref'])) {
$responseModel = $desc['schema']['$ref'];
if(!empty($responseModel)) {
Expand Down Expand Up @@ -178,6 +182,7 @@ public function getMethods($service)
'query' => [],
'body' => [],
],
'emptyResponse' => $emptyResponse,
'responseModel' => $responseModel,
];

Expand Down
4 changes: 2 additions & 2 deletions templates/php/src/Services/Service.php.twig
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ class {{ service.name | caseUcfirst }} extends Service
* @param {{ parameter.type | typeName }}${{ parameter.name | caseCamel | escapeKeyword }}
{% endfor %}
* @throws {{spec.title | caseUcfirst}}Exception
* @return {% if (method.type == 'location') %}string{% else %}array{% endif %}
* @return {{ method | getReturn }}

*/
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 %}): {% if (method.type == 'location') %}string{% else %}array{% endif %}
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 }}

{
{% for parameter in method.parameters.all %}
Expand Down