1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace EventEspresso\core\domain\values; |
4
|
|
|
|
5
|
|
|
use EventEspresso\core\exceptions\InvalidClassException; |
6
|
|
|
use EventEspresso\core\exceptions\InvalidDataTypeException; |
7
|
|
|
use EventEspresso\core\exceptions\InvalidInterfaceException; |
8
|
|
|
|
9
|
|
|
defined('EVENT_ESPRESSO_VERSION') || exit; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class FullyQualifiedName |
15
|
|
|
* Value Object representing a Fully Qualified Class or Interface Name |
16
|
|
|
* |
17
|
|
|
* @package EventEspresso\core\domain\values |
18
|
|
|
* @author Brent Christensen |
19
|
|
|
* @since 4.9.51 |
20
|
|
|
*/ |
21
|
|
|
class FullyQualifiedName |
22
|
|
|
{ |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var string $fully_qualified_name |
26
|
|
|
*/ |
27
|
|
|
private $fully_qualified_name; |
28
|
|
|
|
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* FullyQualifiedName constructor. |
32
|
|
|
* |
33
|
|
|
* @param string $fully_qualified_name |
34
|
|
|
* @throws InvalidClassException |
35
|
|
|
* @throws InvalidInterfaceException |
36
|
|
|
* @throws InvalidDataTypeException |
37
|
|
|
*/ |
38
|
|
|
public function __construct($fully_qualified_name) |
39
|
|
|
{ |
40
|
|
|
if (! is_string($fully_qualified_name)) { |
41
|
|
|
throw new InvalidDataTypeException( |
42
|
|
|
'$fully_qualified_name', |
43
|
|
|
$fully_qualified_name, |
44
|
|
|
'string' |
45
|
|
|
); |
46
|
|
|
} |
47
|
|
|
if (! class_exists($fully_qualified_name) && ! interface_exists($fully_qualified_name)) { |
48
|
|
|
if (strpos($fully_qualified_name, 'Interface') !== false) { |
49
|
|
|
throw new InvalidInterfaceException($fully_qualified_name); |
50
|
|
|
} |
51
|
|
|
throw new InvalidClassException($fully_qualified_name); |
52
|
|
|
} |
53
|
|
|
$this->fully_qualified_name = $fully_qualified_name; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @return string |
59
|
|
|
*/ |
60
|
|
|
public function string() |
61
|
|
|
{ |
62
|
|
|
return $this->fully_qualified_name; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @return string |
68
|
|
|
*/ |
69
|
|
|
public function __toString() |
70
|
|
|
{ |
71
|
|
|
return $this->fully_qualified_name; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
} |
75
|
|
|
|