|
7 | 7 | This package is part of the [Symfony Content Management Framework (CMF)](http://cmf.symfony.com/)
|
8 | 8 | and licensed under the [MIT License](LICENSE).
|
9 | 9 |
|
10 |
| -The Slugifier API provides a basic interface to use for third party slugifiers. |
11 |
| -Besides this, it comes with a usefull `CallbackSlugifier` which is capable of |
12 |
| -handling most third party slugifiers. |
| 10 | +A "slugifier" is a function which transforms a string `such as this` into a |
| 11 | +URL-friendly string `such-as-this`. Slugifiers are also known as "urlizers". |
13 | 12 |
|
| 13 | +This package does not contain a slugifier implementation, it provides a |
| 14 | +standard interface (`SlugifierInterface`) for use by third party slugifiers |
| 15 | +and a `CallbackSlugifier` which is capable of wrapping most non-implementing |
| 16 | +third-party slugifiers to the `SlugifierInterface`. |
14 | 17 |
|
15 | 18 | ## Requirements
|
16 | 19 |
|
17 | 20 | * See also the `require` section of [composer.json](composer.json)
|
18 | 21 |
|
19 |
| - |
20 | 22 | ## Documentation
|
21 | 23 |
|
22 |
| -For the install guide and reference, see: |
| 24 | +Perhaps the best way to document this simple component is with a |
| 25 | +demonstration. You have an event subscriber which slugifies the title of a |
| 26 | +blog post: |
| 27 | + |
| 28 | +```php |
| 29 | +<?php |
| 30 | + |
| 31 | +use Symfony\Cmf\Api\Slugifier\SlugifierInterface; |
| 32 | + |
| 33 | +class FooSubscriber |
| 34 | +{ |
| 35 | + private $slugifier; |
| 36 | + |
| 37 | + public function __construct(SlugifierInterface $slugifier) |
| 38 | + { |
| 39 | + $this->slugifier = $slugifier; |
| 40 | + } |
23 | 41 |
|
24 |
| -* Slugifier documentation |
| 42 | + public function onEntitySave(\Some\Event $event) |
| 43 | + { |
| 44 | + $entity = $event->getEntity(); |
| 45 | + $entity->setSlug($this->slugifier->slugify($entity->getTitle()); |
| 46 | + } |
| 47 | +} |
| 48 | +``` |
| 49 | + |
| 50 | +You can then inject either a slugifier which already implements the CMF |
| 51 | +``SlugifierInterface`` or you can use non-implementing libraries using the |
| 52 | +`CallbackSlugifier`. The |
| 53 | +[RoutingAutoBundle](https://github.com/symfony-cmf/RoutingAutoBundle) uses |
| 54 | +[aferrandini/urlizer](https://github.com/aferrandini/Urlizer) package: |
| 55 | + |
| 56 | +```php |
| 57 | +$slugifier = new CallbackSlugifier('Ferrandini\Urlizer::urlize'); |
| 58 | +$fooSubscriber = new FooSubscriber($slugifier); |
| 59 | +``` |
| 60 | + |
| 61 | +By using the Slugifier package you decouple your application from the slugifier |
| 62 | +implementation. |
25 | 63 |
|
26 | 64 | See also:
|
27 | 65 |
|
28 | 66 | * [All Symfony CMF documentation](http://symfony.com/doc/master/cmf/index.html) - complete Symfony CMF reference
|
29 | 67 | * [Symfony CMF Website](http://cmf.symfony.com/) - introduction, live demo, support and community links
|
30 | 68 |
|
| 69 | +## FIG Proposal |
| 70 | + |
| 71 | +We [proposed this to |
| 72 | +FIG](https://groups.google.com/forum/?fromgroups=#!topic/php-fig/J-6s9Wlyk-A) |
| 73 | +but unfortunately the proposal did not get enough interest. We would still be |
| 74 | +happy to contribute this to a PSR should the interest come up and deprecate |
| 75 | +this package in favor of the PSR one. |
31 | 76 |
|
32 | 77 | ## Contributing
|
33 | 78 |
|
|
0 commit comments