Quantcast
Channel: Symfony Blog
Viewing all articles
Browse latest Browse all 3057

New in Symfony 4.3: Better inflector

$
0
0
Michael BabkerNicolas Grekas

Contributed by
Michael Babker,Nicolas Grekas
in #26890 and #30810.

Symfony includes an internal component called Inflector whose responsibility is to transform English words from plural to singular. It's used in thePropertyInfo and PropertyAccess components to find the singular form of a property name:

1
2
3
4
useSymfony\Component\Inflector\Inflector;$result=Inflector::singularize('teeth');// tooth$result=Inflector::singularize('radii');// radius

In Symfony 4.3 we've improved the component in several ways. First, we've removed its @internal tag, so this component is no longer considered internal and you can make your projects depend on it thanks to theSymfony BC promise.

Second, we've turned it into a full Inflector thanks to the new pluralize() method, which returns the plural form of the given singular English word:

1
2
3
4
5
6
useSymfony\Component\Inflector\Inflector;$result=Inflector::pluralize('bacterium');// bacteria$result=Inflector::pluralize('alumnus');// alumni$result=Inflector::pluralize('news');// news$result=Inflector::pluralize('GrandChild');// GrandChildren

Be trained by Symfony experts - 2019-04-15 Clichy - 2019-04-15 Clichy - 2019-04-17 Clichy

Viewing all articles
Browse latest Browse all 3057

Trending Articles