zelenin/slug

This package is abandoned and no longer maintained. No replacement package was suggested.

Slug generation library

1.1.0 2015-12-06 20:18 UTC

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 is
  • IntlTransliterator transliterates a value as is (uses php-intl)
  • UrlifyTransformer cleans a value from not-letters/numerical characters
  • TemplateTransformer 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