zelenin / slug
Slug generation library
Installs: 3 847
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: >=5.4
- ext-intl: *
This package is not auto-updated.
Last update: 2018-09-18 19:03:36 UTC
README
SEE STRING
Slug
Slug generation library uses the DDD principes.
Library uses transformer concept. You may write new transformer implementing Transformer
interface.
Built-in transformers:
RawTransformer
uses a value as isIntlTransliterator
transliterates a value as is (uses php-intl)UrlifyTransformer
cleans a value from not-letters/numerical charactersTemplateTransformer
transforms a value according a template
Installation
Composer
The preferred way to install this extension is through Composer.
Either run
php composer.phar require zelenin/slug "~1.1.0"
or add
"zelenin/slug": "~1.1.0"
to the require section of your composer.json
Usage
$string = 'Jeanne Françoise Julie Adélaïde Récamier'; $transformers = [ new IntlTransliterateTransformer(), new UrlifyTransformer(), new TemplateTransformer('{id}-{slug}', ['{id}' => $model->id]) ]; $slugifier = new DefaultSlugifier($transformers); $slug = $slugifier->slugify($string); // '12-jeanne-francoise-julie-adelaide-recamier'
You may set some options:
$string = 'Jeanne Françoise Julie Adélaïde Récamier'; $transformers = [ new IntlTransliterateTransformer('Russian-Latin/BGN; Any-Latin; Latin-ASCII; NFD; [:Nonspacing Mark:] Remove; NFKC;'), new UrlifyTransformer('_', false), new TemplateTransformer('{id}-{slug}', ['{id}' => $model->id]) ]; $slugifier = new DefaultSlugifier($transformers); $slug = $slugifier->slugify($string);
Author
Aleksandr Zelenin, e-mail: aleksandr@zelenin.me