2018-11-23 18:17:00 +01:00
|
|
|
<?php
|
|
|
|
|
2019-01-20 10:41:58 +01:00
|
|
|
namespace App\Attribut;
|
2018-11-23 18:17:00 +01:00
|
|
|
|
2019-01-20 11:03:21 +01:00
|
|
|
use App\Exception\UnvalidValueException;
|
|
|
|
|
2019-01-13 16:32:00 +01:00
|
|
|
/**
|
|
|
|
* @author kevinfrantz
|
|
|
|
*/
|
2018-11-23 18:17:00 +01:00
|
|
|
trait SlugAttribut
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $slug;
|
|
|
|
|
2019-01-20 11:03:21 +01:00
|
|
|
/**
|
|
|
|
* @param string $slug
|
|
|
|
*
|
|
|
|
* @throws UnvalidValueException
|
|
|
|
*/
|
2018-11-23 18:17:00 +01:00
|
|
|
public function setSlug(string $slug): void
|
|
|
|
{
|
2019-01-20 11:03:21 +01:00
|
|
|
if (is_numeric($slug)) {
|
|
|
|
throw new UnvalidValueException('A slug must not be numeric!');
|
|
|
|
}
|
2018-11-23 18:17:00 +01:00
|
|
|
$this->slug = $slug;
|
|
|
|
}
|
|
|
|
|
2019-01-20 11:03:21 +01:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
2018-11-23 18:17:00 +01:00
|
|
|
public function getSlug(): string
|
|
|
|
{
|
|
|
|
return $this->slug;
|
|
|
|
}
|
2019-01-13 16:32:00 +01:00
|
|
|
|
2019-01-20 11:03:21 +01:00
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
2019-01-13 16:32:00 +01:00
|
|
|
public function hasSlug(): bool
|
|
|
|
{
|
|
|
|
return isset($this->slug);
|
|
|
|
}
|
2018-11-23 18:17:00 +01:00
|
|
|
}
|