1 | <?php |
||
8 | final class FQCN |
||
9 | { |
||
10 | /** @var string */ |
||
11 | private $fqcn; |
||
12 | |||
13 | /** |
||
14 | * FQCN constructor. |
||
15 | * |
||
16 | * @param string $fqcn |
||
17 | */ |
||
18 | 23 | public function __construct($fqcn) |
|
26 | |||
27 | /** |
||
28 | * @return mixed |
||
29 | */ |
||
30 | 16 | public function getFqcn() |
|
34 | |||
35 | 1 | public function append(string $postfix): self |
|
39 | |||
40 | 1 | public function preppend(string $prefix): self |
|
44 | |||
45 | /** |
||
46 | * toPSR4File |
||
47 | * Ref: http://www.php-fig.org/psr/psr-4/ |
||
48 | * |
||
49 | * |
||
50 | * @param $base_fqcn will be excluded from final path |
||
51 | * |
||
52 | * @return string |
||
53 | */ |
||
54 | 1 | public function toPSR4File($base_fqcn = ""): string |
|
64 | |||
65 | /** |
||
66 | * toPSR4Dir |
||
67 | * Ref: http://www.php-fig.org/psr/psr-4/ |
||
68 | * |
||
69 | * |
||
70 | * @param $base_fqcn will be excluded from final path |
||
71 | * |
||
72 | * @return string |
||
73 | */ |
||
74 | 3 | public function toPSR4Path($base_fqcn = ""): string |
|
82 | |||
83 | /** |
||
84 | * getLastPart - return only last block from namespace |
||
85 | * |
||
86 | * |
||
87 | * @return string |
||
88 | */ |
||
89 | 4 | public function getLastPart(): string |
|
95 | |||
96 | /** |
||
97 | * getLastPart - return base namespace without trailing part |
||
98 | * |
||
99 | * |
||
100 | * @return string |
||
101 | */ |
||
102 | 3 | public function getBasePart(): string |
|
103 | { |
||
104 | 3 | $string = str_replace($this->getLastPart(), "", $this->getFqcn()); |
|
105 | 3 | if (isset($string[-1]) && $string[-1] == "\\") { |
|
106 | 3 | $string = substr($string, 0, -1); |
|
107 | } |
||
108 | |||
109 | 3 | return $string; |
|
110 | } |
||
111 | |||
112 | /** |
||
113 | * fromString - will replace multiple, ending slashes |
||
114 | * |
||
115 | * |
||
116 | * @param string $string |
||
117 | * |
||
118 | * @return FQCN |
||
119 | */ |
||
120 | 18 | static function fromString(string $string): self |
|
130 | } |
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.