50 lines
834 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\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
/**
* @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
*
* @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)) {
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
/**
* @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
}