getAutoloadRules() as $prefix => $prefixPath) { if ($this->isRootNamespace($prefix) || str_starts_with($path, $prefixPath)) { return $prefix . str_replace('/', '\\', substr($path, strlen($prefixPath))); } } throw new RuntimeException("Invalid project path: {$path}"); } public function className(string $path): string { return $this->namespace($path); } public function path(string $name, $extension = '.php'): string { if (Str::endsWith($name, '\\')) { $extension = ''; } foreach ($this->getAutoloadRules() as $prefix => $prefixPath) { if ($this->isRootNamespace($prefix) || str_starts_with($name, $prefix)) { return $prefixPath . str_replace('\\', '/', substr($name, strlen($prefix))) . $extension; } } throw new RuntimeException("Invalid class name: {$name}"); } protected function isRootNamespace(string $namespace): bool { return $namespace === ''; } protected function getAutoloadRules(): array { return data_get(Composer::getJsonContent(), 'autoload.psr-4', []); } }