@@ 31-49 (lines=19) @@ | ||
28 | * @param string $namespace The namespace to register |
|
29 | * @param string|array $path The path on the filesystem (or an array of paths) |
|
30 | */ |
|
31 | public function registerPsr0Namespace($namespace, $path) { |
|
32 | // A namespace always ends with a \ |
|
33 | $namespace = trim($namespace, '\\').'\\'; |
|
34 | if ($namespace === '\\') { |
|
35 | $namespace = ''; |
|
36 | } |
|
37 | ||
38 | if (!is_array($path)) { |
|
39 | $path = [$path]; |
|
40 | } |
|
41 | // Paths always end with a / |
|
42 | $paths = array_map([self::class, 'normalizeDirectory'], $path); |
|
43 | ||
44 | if (!isset($this->psr0Namespaces[$namespace])) { |
|
45 | $this->psr0Namespaces[$namespace] = $paths; |
|
46 | } else { |
|
47 | $this->psr0Namespaces[$namespace] = array_merge($this->psr0Namespaces[$namespace], $paths); |
|
48 | } |
|
49 | } |
|
50 | ||
51 | /** |
|
52 | * Registers a PSR-4 namespace. |
|
@@ 57-75 (lines=19) @@ | ||
54 | * @param string $namespace The namespace to register |
|
55 | * @param string|array $path The path on the filesystem (or an array of paths) |
|
56 | */ |
|
57 | public function registerPsr4Namespace($namespace, $path) { |
|
58 | // A namespace always ends with a \ |
|
59 | $namespace = trim($namespace, '\\').'\\'; |
|
60 | if ($namespace === '\\') { |
|
61 | $namespace = ''; |
|
62 | } |
|
63 | ||
64 | if (!is_array($path)) { |
|
65 | $path = [$path]; |
|
66 | } |
|
67 | // Paths always end with a / |
|
68 | $paths = array_map([self::class, 'normalizeDirectory'], $path); |
|
69 | ||
70 | if (!isset($this->psr4Namespaces[$namespace])) { |
|
71 | $this->psr4Namespaces[$namespace] = $paths; |
|
72 | } else { |
|
73 | $this->psr4Namespaces[$namespace] = array_merge($this->psr4Namespaces[$namespace], $paths); |
|
74 | } |
|
75 | } |
|
76 | ||
77 | /** |
|
78 | * Create a class name mapper from the composer.json file generated by Composer. |