2017 © Pedro PelĂĄez
 

library slug

image

ddd/slug

  • Thursday, August 15, 2013
  • by rouffj
  • Repository
  • 4 Watchers
  • 8 Stars
  • 8,168 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 1 % Grown

The README.md

Slug is a component which generates slugs easily whatever persistence mecanism you use (Propel2, Doctrine2, custom ORM...)., (*1)

To generate a slug of a string there is always two 2 steps:, (*2)

  • The transliteration step which converts a given string from any writing system (French, Deutsh, Greek, Arabic...) into its ASCII representation.
  • The slug generation step which basically separates each word and field by a custom delimiter.

Therefore Slug component has 2 services: TransliteratorInterface and SlugGeneratorInterface. Each of these services can have multiple implementations:, (*3)

  • LatinTransliterator: Transliterate a string written in any Latin alphabet (French, Deutsh, Spanish...) into its ASCII equivalent.
  • DefaultSlugGenerator: Customize the word and field separator.
  • PatternSlugGenerator: Complete customization of slug generation.

Installation

Using Composer, just require the ddd/components package:, (*4)

``` javascript { "require": { "ddd/components": "dev-master" } }, (*5)


Usage ----- To be able to slugify an entity or model, you just have to implement the `SluggableInterface`: ``` php <?php use Ddd\Slug\Model\SluggableInterface; use Ddd\Slug\Service\SlugGeneratorInterface; class Article implements SluggableInterface { private $createdAt; private $title; private $slug; public function slugify(SlugGeneratorInterface $slugifier) { $this->slug = $slugifier->slugify(array($this->createdAt->format('Y'), $this->title)); } // other methods... }

Then you just have to call the slugify method to generate the slug:, (*6)

``` php use Ddd\Slug\Infra\SlugGenerator\DefaultSlugGenerator; use Ddd\Slug\Infra\Transliterator\LatinTransliterator;, (*7)

$article = new Article(); $article->setTitle('Hello world!'); $article->slugify(new DefaultSlugGenerator(array(new LatinTransliterator())));, (*8)

echo $article->getSlug(); // writes "2013-hello-world" ```, (*9)

Credits

The Versions

15/08 2013

dev-master

9999999-dev https://github.com/ddd-php/Slug

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

slug ddd

15/08 2013

v1.0

1.0.0.0 https://github.com/ddd-php/Slug

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

slug ddd