| Total Complexity | 11 |
| Total Lines | 83 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 10 | class IncludeManager implements PathInterface |
||
| 11 | { |
||
| 12 | use PathTrait; |
||
| 13 | /** |
||
| 14 | * 默认命名空间 |
||
| 15 | * |
||
| 16 | * @var array |
||
| 17 | */ |
||
| 18 | protected $namespace = [ __NAMESPACE__ ]; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * 包含路径 |
||
| 22 | * |
||
| 23 | * @var array |
||
| 24 | */ |
||
| 25 | protected $includePath = []; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * 将JAVA,路径分割转换为PHP分割符 |
||
| 29 | * |
||
| 30 | * @param string $name 类名 |
||
| 31 | * @return string 真实分隔符 |
||
| 32 | */ |
||
| 33 | public static function realName(string $name):string |
||
| 36 | } |
||
| 37 | |||
| 38 | /** |
||
| 39 | * 载入依赖控制变量环境 |
||
| 40 | * @param string $path |
||
| 41 | */ |
||
| 42 | public static function requireOnce(string $path) |
||
| 45 | } |
||
| 46 | |||
| 47 | /** |
||
| 48 | * 获取真实或者虚拟存在的地址 |
||
| 49 | * |
||
| 50 | * @param string $name |
||
| 51 | * @return string|null |
||
| 52 | */ |
||
| 53 | public static function realPath(string $name):?string |
||
| 54 | { |
||
| 55 | return Path::format($name); |
||
| 56 | } |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @param string $path |
||
| 60 | * @param string|null $namespace |
||
| 61 | */ |
||
| 62 | public function addIncludePath(string $path, ?string $namespace = null) |
||
| 63 | { |
||
| 64 | if ($path = static::realPath($path)) { |
||
| 65 | $namespace = $namespace ?? 0; |
||
| 66 | if (array_key_exists($namespace, $this->includePath)) { |
||
| 67 | if (!in_array($path, $this->includePath[$namespace])) { |
||
| 68 | $this->includePath[$namespace][] = $path; |
||
| 69 | } |
||
| 70 | } else { |
||
| 71 | $this->includePath[$namespace][] = $path; |
||
| 72 | } |
||
| 73 | } |
||
| 74 | } |
||
| 75 | |||
| 76 | public function getIncludePath() |
||
| 77 | { |
||
| 78 | return $this->includePath; |
||
| 79 | } |
||
| 80 | |||
| 81 | public function getNamespace() |
||
| 84 | } |
||
| 85 | |||
| 86 | /** |
||
| 87 | * @param string $namespace |
||
| 88 | */ |
||
| 89 | public function setNamespace(string $namespace) |
||
| 93 | } |
||
| 94 | } |
||
| 95 | } |
||
| 96 |