48 lines
766 B
PHP
Raw Normal View History

2018-11-23 18:17:00 +01:00
<?php
namespace Infinito\Attribut;
2018-11-23 18:17:00 +01:00
use Infinito\Exception\UnvalidValueException;
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
/**
* @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|null
2019-01-20 11:03:21 +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
}