Skip to content

Commit 82f238c

Browse files
committed
Merge pull request #4 from symfony-cmf/added_basic_docs
Added some basic documentation
2 parents 74c19eb + 4a53fa3 commit 82f238c

File tree

2 files changed

+53
-7
lines changed

2 files changed

+53
-7
lines changed

CoreBundle/SlugifierInterface.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
/**
66
* @deprecated Since 1.0, to be removed in 2.0. Use Symfony\Cmf\Api\Slugifier\SlugifierInterface instead.
77
*/
8-
interface SlugifierInterface {
8+
interface SlugifierInterface
9+
{
910
/**
1011
* Return a slugified (or urlized) representation of a given string.
1112
*

README.md

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,72 @@
77
This package is part of the [Symfony Content Management Framework (CMF)](http://cmf.symfony.com/)
88
and licensed under the [MIT License](LICENSE).
99

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".
1312

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`.
1417

1518
## Requirements
1619

1720
* See also the `require` section of [composer.json](composer.json)
1821

19-
2022
## Documentation
2123

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+
}
2341

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.
2563

2664
See also:
2765

2866
* [All Symfony CMF documentation](http://symfony.com/doc/master/cmf/index.html) - complete Symfony CMF reference
2967
* [Symfony CMF Website](http://cmf.symfony.com/) - introduction, live demo, support and community links
3068

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.
3176

3277
## Contributing
3378

0 commit comments

Comments
 (0)