-
Notifications
You must be signed in to change notification settings - Fork 3
Slugging
sunrise-php edited this page Jan 7, 2019
·
1 revision
Learn more about Sunrise Slugger
composer require sunrise/slugger
Adding the following code to
config/definitions.php
/**
* Sunrise Slugger
*
* @link https://github.com/sunrise-php/slugger
*/
Sunrise\Slugger\SluggerInterface::class => function($container)
{
$slugger = new Sunrise\Slugger\Slugger();
$slugger->setTransliteratorId('de-ASCII');
return $slugger;
},
use Sunrise\Slugger\SluggerInterface;
/**
* @Inject
*
* @var SluggerInterface
*/
protected $slugger;
public function process(
ServerRequestInterface $request,
RequestHandlerInterface $handler) : ResponseInterface
{
// some code
if (null === $entity->getSlug()) {
if (null !== $entity->getTitle()) {
$slug = $this->slugger->slugify($entity->getTitle());
$entity->setSlug($slug);
}
}
// some code
}
Have questions?
Ask your questions in our chat:
Get more features for your application using Awesome PSR-15 Middleware