Tag normalization is now in the model, this is refelcted elsewhere in code usage

This commit is contained in:
Jonny Barnes 2016-05-29 13:49:30 +01:00
parent d50e902fb9
commit 50cb351167
4 changed files with 36 additions and 12 deletions

View file

@ -36,4 +36,32 @@ class Tag extends Model
* @var array
*/
protected $guarded = ['id'];
/**
* Normalize tags so theyre lowercase and fancy diatrics are removed.
*
* @param string
*/
public function setTagAttribute($value)
{
$this->attributes['tag'] = $this->normalizeTag($value);
}
/**
* This method actually normalizes a tag. That means lowercase-ing and
* removing fancy diatric characters.
*
* @param string
*/
public static function normalizeTag($tag)
{
return mb_strtolower(
preg_replace(
'/&([a-z]{1,2})(acute|cedil|circ|grave|lig|orn|ring|slash|th|tilde|uml|caron);/i',
'$1',
htmlentities($tag)
),
'UTF-8'
);
}
}