Skip to content

Commit

Permalink
Merge pull request #8 from jvdyck/master
Browse files Browse the repository at this point in the history
fix for array_* functions & str_* filters & functions not working
  • Loading branch information
dinhquochan authored Oct 21, 2020
2 parents dd8878d + 45bf7c3 commit d60b1e9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/Extensions/Arr.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Arr extends AbstractExtension implements ExtensionInterface
public function getFunctions()
{
return [
new TwigFunction('array_*', function ($name, $arguments) {
new TwigFunction('array_*', function ($name, ...$arguments) {
return call_user_func_array([\Illuminate\Support\Arr::class, Str::camel($name)], $arguments);
}),
new TwigFunction('data_fill', 'data_fill'),
Expand Down
25 changes: 13 additions & 12 deletions src/Extensions/Str.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Twig\Extension\ExtensionInterface;
use Twig\TwigFilter;
use Twig\TwigFunction;
use Illuminate\Support\Str as IlluminateStr;

class Str extends AbstractExtension implements ExtensionInterface
{
Expand All @@ -20,13 +21,13 @@ public function getFilters()
new TwigFilter('__', '__'),
new TwigFilter('class_basename', 'class_basename'),
new TwigFilter('preg_replace_array', 'preg_replace_array'),
new TwigFilter('str_*', function ($name, $arguments) {
return call_user_func_array([Str::class, Str::camel($name)], $arguments);
new TwigFilter('str_*', function ($name, ...$arguments) {
return call_user_func_array([IlluminateStr::class, IlluminateStr::camel($name)], $arguments);
}),
new TwigFilter('snake_case', [Str::class, 'snake']),
new TwigFilter('camel_case', [Str::class, 'camel']),
new TwigFilter('studly_case', [Str::class, 'studly']),
new TwigFilter('kebab_case', [Str::class, 'kebab']),
new TwigFilter('snake_case', [IlluminateStr::class, 'snake']),
new TwigFilter('camel_case', [IlluminateStr::class, 'camel']),
new TwigFilter('studly_case', [IlluminateStr::class, 'studly']),
new TwigFilter('kebab_case', [IlluminateStr::class, 'kebab']),
];
}

Expand All @@ -39,13 +40,13 @@ public function getFunctions()
{
return [
new TwigFunction('__', '__'),
new TwigFunction('str_*', function ($name, $arguments) {
return call_user_func_array([Str::class, Str::camel($name)], $arguments);
new TwigFunction('str_*', function ($name, ...$arguments) {
return call_user_func_array([IlluminateStr::class, IlluminateStr::camel($name)], $arguments);
}),
new TwigFunction('snake_case', [Str::class, 'snake']),
new TwigFunction('camel_case', [Str::class, 'camel']),
new TwigFunction('studly_case', [Str::class, 'studly']),
new TwigFunction('kebab_case', [Str::class, 'kebab']),
new TwigFunction('snake_case', [IlluminateStr::class, 'snake']),
new TwigFunction('camel_case', [IlluminateStr::class, 'camel']),
new TwigFunction('studly_case', [IlluminateStr::class, 'studly']),
new TwigFunction('kebab_case', [IlluminateStr::class, 'kebab']),
];
}
}

0 comments on commit d60b1e9

Please sign in to comment.