2018-11-23 18:17:00 +01:00
|
|
|
<?php
|
|
|
|
|
2019-02-17 14:33:19 +01:00
|
|
|
namespace Infinito\Attribut;
|
2018-11-23 18:17:00 +01:00
|
|
|
|
2019-04-14 23:37:30 +02:00
|
|
|
use Infinito\Exception\Validation\ValueInvalidException;
|
2019-01-20 11:03:21 +01:00
|
|
|
|
2019-01-13 16:32:00 +01:00
|
|
|
/**
|
|
|
|
* @author kevinfrantz
|
2019-02-07 14:32:23 +01:00
|
|
|
*
|
|
|
|
* @see SlugAttributInterface
|
2019-01-13 16:32:00 +01:00
|
|
|
*/
|
2018-11-23 18:17:00 +01:00
|
|
|
trait SlugAttribut
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $slug;
|
|
|
|
|
2019-01-20 11:03:21 +01:00
|
|
|
/**
|
2019-04-14 23:37:30 +02:00
|
|
|
* @todo Maybe throw an other Exception here?
|
2019-04-15 01:37:17 +02:00
|
|
|
*
|
2019-01-20 11:03:21 +01:00
|
|
|
* @param string $slug
|
2019-04-15 01:37:17 +02:00
|
|
|
*
|
2019-04-14 23:37:30 +02:00
|
|
|
* @throws ValueInvalidException
|
2019-01-20 11:03:21 +01:00
|
|
|
*/
|
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)) {
|
2019-04-14 23:37:30 +02:00
|
|
|
throw new ValueInvalidException('A slug must not be numeric!');
|
2019-01-20 11:03:21 +01:00
|
|
|
}
|
2018-11-23 18:17:00 +01:00
|
|
|
$this->slug = $slug;
|
|
|
|
}
|
|
|
|
|
2019-01-20 11:03:21 +01:00
|
|
|
/**
|
2019-02-13 18:03:25 +01:00
|
|
|
* @return string|null
|
2019-01-20 11:03:21 +01:00
|
|
|
*/
|
2019-02-13 18:03:25 +01:00
|
|
|
public function getSlug(): ?string
|
2018-11-23 18:17:00 +01:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|