mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-11 17:44:44 +08:00
Moved process of sluggifying custom slug to a filter
This commit is contained in:
31
module/Common/src/Validation/SluggerFilter.php
Normal file
31
module/Common/src/Validation/SluggerFilter.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Shlinkio\Shlink\Common\Validation;
|
||||
|
||||
use Cocur\Slugify;
|
||||
use Zend\Filter\Exception;
|
||||
use Zend\Filter\FilterInterface;
|
||||
|
||||
class SluggerFilter implements FilterInterface
|
||||
{
|
||||
/** @var Slugify\SlugifyInterface */
|
||||
private $slugger;
|
||||
|
||||
public function __construct(?Slugify\SlugifyInterface $slugger = null)
|
||||
{
|
||||
$this->slugger = $slugger ?: new Slugify\Slugify(['lowercase' => false]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the result of filtering $value
|
||||
*
|
||||
* @param mixed $value
|
||||
* @throws Exception\RuntimeException If filtering $value is impossible
|
||||
* @return mixed
|
||||
*/
|
||||
public function filter($value)
|
||||
{
|
||||
return $value ? $this->slugger->slugify($value) : $value;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user