From b7c8de755637db188b93b9ee4c6d7953bc749efc Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Tue, 22 Sep 2020 16:05:37 +0200 Subject: [PATCH] [String] Allow to define slugger substitutions with PHP closures --- components/string.rst | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/components/string.rst b/components/string.rst index 7d2ec49a198..10c0ab43e66 100644 --- a/components/string.rst +++ b/components/string.rst @@ -473,10 +473,19 @@ that only includes safe ASCII characters:: $slug = $slugger->slug('10% or 5€'); // $slug = '10-percent-or-5-euro' + // for more dynamic substitutions, pass a PHP closure instead of an array + $slugger = new AsciiSlugger('en', function ($string, $locale) { + return str_replace('❤️', 'love', $string); + }); + .. versionadded:: 5.1 The feature to define additional substitutions was introduced in Symfony 5.1. +.. versionadded:: 5.2 + + The feature to use a PHP closure to define substitutions was introduced in Symfony 5.2. + The separator between words is a dash (``-``) by default, but you can define another separator as the second argument::