-
Notifications
You must be signed in to change notification settings - Fork 179
/
Copy pathLanguage.php
140 lines (115 loc) · 3.2 KB
/
Language.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php
namespace Appwrite\SDK;
abstract class Language
{
public const TYPE_INTEGER = 'integer';
public const TYPE_NUMBER = 'number';
public const TYPE_STRING = 'string';
public const TYPE_BOOLEAN = 'boolean';
public const TYPE_ARRAY = 'array';
public const TYPE_OBJECT = 'object';
public const TYPE_FILE = 'file';
/**
* @var array
*/
protected $params = [];
/**
* @return string
*/
abstract public function getName(): string;
/**
* @return array<string>
*/
abstract public function getKeywords(): array;
/**
* @return array<string>
*/
abstract public function getIdentifierOverrides(): array;
/**
* @return array<array>
*/
abstract public function getFiles(): array;
/**
* @param array $parameter
* @return string
*/
abstract public function getTypeName(array $parameter, array $spec = []): string;
/**
* @param array $param
* @return string
*/
abstract public function getParamDefault(array $param): string;
/**
* @param array $param
* @return string
*/
abstract public function getParamExample(array $param): string;
/**
* @param string $key
* @param string $value
* @return Language
*/
public function setParam(string $key, string $value): Language
{
$this->params[$key] = $value;
return $this;
}
/**
* @return array
*/
public function getParams(): array
{
return $this->params;
}
/**
* Language specific filters.
* @return array
*/
public function getFilters(): array
{
return [];
}
/**
* Language specific functions.
* @return array
*/
public function getFunctions(): array
{
return [];
}
protected function toPascalCase(string $value): string
{
return \ucfirst($this->toCamelCase($value));
}
protected function toCamelCase($str): string
{
// Normalize the string to decompose accented characters
$str = \Normalizer::normalize($str, \Normalizer::FORM_D);
// Remove accents and other residual non-ASCII characters
$str = \preg_replace('/\p{M}/u', '', $str);
$str = \preg_replace('/[^a-zA-Z0-9]+/', ' ', $str);
$str = \trim($str);
$str = \ucwords($str);
$str = \str_replace(' ', '', $str);
$str = \lcfirst($str);
return $str;
}
protected function toSnakeCase($str): string
{
// Normalize the string to decompose accented characters
$str = \Normalizer::normalize($str, \Normalizer::FORM_D);
// Remove accents and other residual non-ASCII characters
$str = \preg_replace('/\p{M}/u', '', $str);
// Remove apostrophes before replacing non-word characters with underscores
$str = \str_replace("'", '', $str);
$str = \preg_replace('/[^a-zA-Z0-9]+/', '_', $str);
$str = \preg_replace('/_+/', '_', $str);
$str = \trim($str, '_');
$str = \strtolower($str);
return $str;
}
protected function toUpperSnakeCase($str): string
{
return \strtoupper($this->toSnakeCase($str));
}
}