New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[templates] add shuffle filter #3966
base: 3.x
Are you sure you want to change the base?
Conversation
21a8260
to
3e94978
Compare
e7a0e6a
to
e26a4e8
Compare
992dc6d
to
09b6bcf
Compare
2 | ||
6 | ||
3 | ||
3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These tests don't really test anything, right?
@@ -222,6 +222,7 @@ public function getFilters(): array | |||
|
|||
// string/array filters | |||
new TwigFilter('reverse', [self::class, 'reverseFilter'], ['needs_environment' => true]), | |||
new TwigFilter('shuffle', [self::class, 'shuffleFilter'], ['needs_environment' => true]), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new TwigFilter('shuffle', [self::class, 'shuffleFilter'], ['needs_environment' => true]), | |
new TwigFilter('shuffle', [self::class, 'shuffleFilter'], ['needs_charset' => true]), |
* | ||
* @internal | ||
*/ | ||
public static function shuffleFilter(Environment $env, mixed $item): mixed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public static function shuffleFilter(Environment $env, mixed $item): mixed | |
public static function shuffleFilter(string $charset $item): mixed |
For $item
, we can be more precise than mixed
o the phpdocs.
public static function shuffleFilter(Environment $env, mixed $item): mixed | ||
{ | ||
if (\is_string($item)) { | ||
$charset = $env->getCharset(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be removed
@@ -920,6 +921,38 @@ public static function reverseFilter(Environment $env, $item, $preserveKeys = fa | |||
return $string; | |||
} | |||
|
|||
/** | |||
* Shuffle an array, a \Traversable instance, or a string. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Shuffle an array, a \Traversable instance, or a string. | |
* Shuffles an array, a \Traversable instance, or a string. |
New feature :
The filter displays the values in an array at random.
I'm open of any feedback.