alex-kalanis /
pohoda
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Riesenia\Pohoda\DI; |
||
| 4 | |||
| 5 | trait ClassNameTrait |
||
| 6 | { |
||
| 7 | /** |
||
| 8 | * @param string|class-string $name |
||
|
0 ignored issues
–
show
Documentation
Bug
introduced
by
Loading history...
|
|||
| 9 | * @return string |
||
| 10 | * The difference in absolute-relative paths are signalized by slash in the beginning of string |
||
| 11 | */ |
||
| 12 | 19 | public function getClassName(string $name): string |
|
| 13 | { |
||
| 14 | 19 | $namespaceSub = explode('\\', __NAMESPACE__); |
|
| 15 | 19 | $namespaceSub = array_slice($namespaceSub, 0, -1); |
|
| 16 | 19 | $namespaceSub = implode('\\', $namespaceSub); |
|
| 17 | |||
| 18 | 19 | if (str_starts_with($name, '\\')) { |
|
| 19 | // absolute path |
||
| 20 | 1 | return substr($name, 1); |
|
| 21 | } |
||
| 22 | |||
| 23 | 18 | if (str_starts_with($name, $namespaceSub)) { |
|
| 24 | 2 | return $name; |
|
| 25 | } |
||
| 26 | |||
| 27 | 17 | return $namespaceSub . '\\' . $name; |
|
| 28 | } |
||
| 29 | } |
||
| 30 |