|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the SexyField package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Dion Snoeijen <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
declare (strict_types = 1); |
|
13
|
|
|
|
|
14
|
|
|
namespace Tardigrades\SectionField\ValueObject; |
|
15
|
|
|
|
|
16
|
|
|
use Assert\Assertion; |
|
17
|
|
|
|
|
18
|
|
|
final class FullyQualifiedClassName |
|
19
|
|
|
{ |
|
20
|
|
|
/** @var string */ |
|
21
|
|
|
private $fullyQualifiedClassName; |
|
22
|
|
|
|
|
23
|
|
|
private function __construct(string $fullyQualifiedClassName) |
|
24
|
|
|
{ |
|
25
|
|
|
$this->fullyQualifiedClassName = str_replace('.', '\\', $fullyQualifiedClassName); |
|
26
|
|
|
$this->fullyQualifiedClassName = str_replace('Proxies\\__CG__\\', '', $this->fullyQualifiedClassName); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function getClassName() |
|
30
|
|
|
{ |
|
31
|
|
|
$type = explode('\\', $this->fullyQualifiedClassName); |
|
32
|
|
|
$className = $type[count($type) - 1]; |
|
33
|
|
|
|
|
34
|
|
|
return $className; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function __toString(): string |
|
38
|
|
|
{ |
|
39
|
|
|
return $this->fullyQualifiedClassName; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function toHandle(): Handle |
|
43
|
|
|
{ |
|
44
|
|
|
$handle = explode('\\', $this->fullyQualifiedClassName); |
|
45
|
|
|
$handle = end($handle); |
|
46
|
|
|
return Handle::fromString(lcfirst($handle)); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public static function fromNamespaceAndClassName(SectionNamespace $namespace, ClassName $className) |
|
50
|
|
|
{ |
|
51
|
|
|
return new self((string) $namespace . '\\Entity\\' . (string) $className); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public static function fromString(string $fullyQualifiedClassName): self |
|
55
|
|
|
{ |
|
56
|
|
|
return new self($fullyQualifiedClassName); |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|