forked from ILIAS-eLearning/ILIAS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Alphanumeric.php
52 lines (42 loc) · 1022 Bytes
/
Alphanumeric.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
declare(strict_types=1);
/* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
/**
* @author Niels Theen <[email protected]>
*/
namespace ILIAS\Data;
use ILIAS\Refinery\ConstraintViolationException;
class Alphanumeric
{
/**
* @var mixed
*/
private $value;
/**
* @param mixed $value
* @throws ConstraintViolationException
*/
public function __construct($value)
{
$matches = null;
if (!preg_match('/^[a-zA-Z0-9]+$/', (string) $value, $matches)) {
throw new ConstraintViolationException(
sprintf('The value "%s" is not an alphanumeric value.', $value),
'exception_not_alphanumeric',
array($value)
);
}
$this->value = $value;
}
/**
* @return mixed
*/
public function getValue()
{
return $this->value;
}
public function asString(): string
{
return (string) $this->value;
}
}