elegantmedia /
PHP-Toolkit
| 1 | <?php |
||
| 2 | |||
| 3 | namespace ElegantMedia\PHPToolkit; |
||
| 4 | |||
| 5 | class Reflector |
||
| 6 | { |
||
| 7 | /** |
||
| 8 | * Get the inherited class' directory path. |
||
| 9 | * |
||
| 10 | * @param object|string $self |
||
| 11 | * @param null $pathSuffix |
||
|
0 ignored issues
–
show
Documentation
Bug
introduced
by
Loading history...
|
|||
| 12 | * |
||
| 13 | * @return string |
||
| 14 | * |
||
| 15 | * @throws \ReflectionException |
||
| 16 | */ |
||
| 17 | public static function classPath($self, $pathSuffix = null): string |
||
| 18 | { |
||
| 19 | $class = $self; |
||
| 20 | |||
| 21 | if (is_object($self)) { |
||
| 22 | $class = get_class($self); |
||
| 23 | } |
||
| 24 | |||
| 25 | $reflector = new \ReflectionClass($class); |
||
| 26 | |||
| 27 | $path = dirname($reflector->getFileName()); |
||
| 28 | |||
| 29 | if ($pathSuffix) { |
||
|
0 ignored issues
–
show
|
|||
| 30 | $path .= DIRECTORY_SEPARATOR . ltrim($pathSuffix, DIRECTORY_SEPARATOR); |
||
| 31 | } |
||
| 32 | |||
| 33 | return Path::canonical($path); |
||
| 34 | } |
||
| 35 | } |
||
| 36 |