zelenin / string
String transformers collection
Installs: 71 603
Dependents: 1
Suggesters: 0
Security: 0
Stars: 5
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: >=5.4
- ext-intl: *
This package is not auto-updated.
Last update: 2024-12-21 19:21:14 UTC
README
String transformers collection.
Library uses transformer concept. You may write new transformer implementing \Zelenin\Ddd\String\Domain\Service\Transformer
interface.
Built-in transformers:
RawTransformer
uses a string as isIntlNormalizeTransformer
normalizes a string (uses php-intl)IntlTransliterator
transliterates a string (uses php-intl)UrlifyTransformer
cleans a string for friendly url (slugifier)TemplateTransformer
transforms a string according a template
Installation
Composer
The preferred way to install this extension is through Composer.
Either run
php composer.phar require zelenin/string "~0.0.0"
or add
"zelenin/string": "~0.0.0"
to the require section of your composer.json
Usage
$string = 'Jeanne Françoise Julie Adélaïde Récamier'; $transformers = [ new IntlNormalizeTransformer(), new IntlTransliterateTransformer(), new UrlifyTransformer(), new TemplateTransformer('{id}-{slug}', ['{id}' => $model->id]) ]; $transformer = new Transformer(new TransformerCollection($transformers)); $slug = $transformer->transform($string); // '12-jeanne-francoise-julie-adelaide-recamier'
You may set some options:
$string = 'Jeanne Françoise Julie Adélaïde Récamier'; $transformers = [ new IntlNormalizeTransformer(Normalizer::FORM_C), new IntlTransliterateTransformer('Russian-Latin/BGN; Any-Latin; Latin-ASCII; NFD; [:Nonspacing Mark:] Remove; NFKC;'), new UrlifyTransformer('_', false), new TemplateTransformer('{id}-{slug}', ['{id}' => $model->id]) ]; $transformer = new Transformer(new TransformerCollection($transformers)); $slug = $transformer->transform($string);
Author
Aleksandr Zelenin, e-mail: aleksandr@zelenin.me