diff --git a/otel-autoload-example.php b/otel-autoload-example.php deleted file mode 100644 index 8ac77f9..0000000 --- a/otel-autoload-example.php +++ /dev/null @@ -1,18 +0,0 @@ -collector->collectClasses(); + $this->ensureDirectoryExists(); + $classMapFileName = sprintf(static::CLASSMAP_FILE_NAME_PATTERN, $this->config->getOutputDir()); + $classMap = fopen($classMapFileName, 'a'); + fwrite($classMap, 'ensureDirectoryExists(); - if (!file_exists($this->getOutputFilepathByModule($class))) { + $hookFile = $this->getOutputFilepath($class); + if (!file_exists($hookFile)) { $content = 'getOutputFilepathByModule($class), 'a'); + + $file = fopen($hookFile, 'a'); fwrite($file, $content); fwrite($file, $this->contentCreator->createHookContent($class)); fclose($file); + fwrite($classMap, '\'' . $class[static::NAMESPACE_KEY] . '\\' . $class[static::CLASS_NAME_KEY] . '\' => \'' . $hookFile . '\',' . PHP_EOL); } + fwrite($classMap, '];' . PHP_EOL); + fclose($classMap); } /** @@ -120,14 +128,13 @@ protected function ensureDirectoryExists(): void * * @return string */ - protected function getOutputFilepathByModule(array $class): string + protected function getOutputFilepath(array $class): string { - $namespace = explode('\\', $class[static::NAMESPACE_KEY]); - $moduleNamePattern = $namespace[0] . $namespace[1] . $namespace[2]; return sprintf( - static::OUTPUT_FILE_PATH_PLACEHOLDER_GLOBAL, + static::OUTPUT_FILE_PATH_PLACEHOLDER, $this->config->getOutputDir(), - static::GLOBAL_HOOK_FILE_NAME, + str_replace('\\', '-', $class[static::NAMESPACE_KEY]), + $class[static::CLASS_NAME_KEY], ); } }