https://github.com/dantleech/api-slugifier
Symfony CMF Slugifier API
https://github.com/dantleech/api-slugifier
Last synced: 11 months ago
JSON representation
Symfony CMF Slugifier API
- Host: GitHub
- URL: https://github.com/dantleech/api-slugifier
- Owner: dantleech
- Created: 2015-06-18T16:44:47.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2015-06-18T16:46:47.000Z (about 11 years ago)
- Last Synced: 2025-04-20T07:58:22.549Z (about 1 year ago)
- Language: PHP
- Size: 133 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Symfony CMF API
===============
This package contains an interface for slugifier/urlizer implementations. The
aim is to enable slugifiers implementations to be reused both within the
Symfony CMF components and with the wider community.
Usage
-----
If your class requires a slugifier:
````php
use Symfony\Cmf\Api\Slugifier\SlugifierInterface;
class SomeUrlWriter
{
private $slugifier;
public function __construct(SlugifierInterface $slugifier)
{
$this->slugifier = $slugifier;
}
public function generate($string)
{
return $this->slugifier->slugify($string);
}
}
````
Callback Slugifier
------------------
This package includes a callback slugifier which enables you to use slugifier
implementations which do not implement this interface:
For example, take the following fictional urlizer:
````php
class DoNothingUrlizer
{
public static function urlize($string, $delimiter = '-')
{
return $string;
}
}
````
You can use this through the Callback slugifier as follows:
````php
$slugifier = new CallbackSlugifier('DoNothingUrlizer::urlize');
$slugified = $slugifier->slugify('slugify me');
````
The callback slugifier uses `call_user_func` internally and can accept any
[php callable](http://php.net/manual/en/language.types.callable.php).