2017 © Pedro Peláez
 

library string

String transformers collection

image

zelenin/string

String transformers collection

  • Tuesday, December 29, 2015
  • by zelenin
  • Repository
  • 1 Watchers
  • 3 Stars
  • 18,859 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 6 % Grown

The README.md

String

String transformers collection., (*1)

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 is - IntlNormalizeTransformer 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, (*2)

Installation

Composer

The preferred way to install this extension is through Composer., (*3)

Either run, (*4)

php composer.phar require zelenin/string "~0.0.0"

or add, (*5)

"zelenin/string": "~0.0.0"

to the require section of your composer.json, (*6)

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:, (*7)

$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, (*8)

The Versions

29/12 2015

dev-master

9999999-dev https://github.com/zelenin/string

String transformers collection

  Sources   Download

MIT

The Requires

  • php >=5.4
  • ext-intl *

 

string translit slug ddd

23/12 2015

0.0.1

0.0.1.0 https://github.com/zelenin/string

String transformers collection

  Sources   Download

MIT

The Requires

  • php >=5.4
  • ext-intl *

 

string translit slug ddd