Skip to content

Commit ad3235a

Browse files
committed
fix snake case
1 parent c9a5928 commit ad3235a

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/SDK/SDK.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,14 @@ public function __construct(Language $language, Spec $spec)
101101
return str_replace([' ', '_'], '.', strtolower(preg_replace('/([a-zA-Z])(?=[A-Z])/', '$1.', $value)));
102102
}));
103103
$this->twig->addFilter(new TwigFilter('caseSnake', function ($value) {
104-
return str_replace([' ', '-'], '_', strtolower(preg_replace('/([a-zA-Z])(?=[A-Z])/', '$1_', $value)));
104+
preg_match_all('!([A-Z][A-Z0-9]*(?=$|[A-Z][a-z0-9])|[A-Za-z][a-z0-9]+)!', $value, $matches);
105+
$ret = $matches[0];
106+
foreach ($ret as &$match) {
107+
$match = $match == strtoupper($match)
108+
? strtolower($match)
109+
: lcfirst($match);
110+
}
111+
return implode('_', $ret);
105112
}));
106113
$this->twig->addFilter(new TwigFilter('caseJson', function ($value) {
107114
return (is_array($value)) ? json_encode($value) : $value;

0 commit comments

Comments
 (0)