From 4c0ad55b321c234380be242b57eb9cd24c61d215 Mon Sep 17 00:00:00 2001 From: gechetspr Date: Sun, 8 Dec 2024 20:28:47 +0200 Subject: [PATCH 1/3] Changed autoload for generated hooks --- otel-autoload-example.php | 18 ---------- .../SprykerInstrumentationBootstrap.php | 17 +++++++++- .../Business/Generator/HookGenerator.php | 34 +++++++++++++++++-- 3 files changed, 47 insertions(+), 22 deletions(-) delete mode 100644 otel-autoload-example.php 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); } /** @@ -130,4 +143,19 @@ protected function getOutputFilepathByModule(array $class): string static::GLOBAL_HOOK_FILE_NAME, ); } + + /** + * @param array $class + * + * @return string + */ + protected function getOutputFilepath(array $class): string + { + return sprintf( + static::OUTPUT_FILE_PATH_PLACEHOLDER, + $this->config->getOutputDir(), + str_replace('\\', '-', $class[static::NAMESPACE_KEY]), + $class[static::CLASS_NAME_KEY], + ); + } } From ac45d33046762c8a2f81c2d4e8ce6533f32fbea0 Mon Sep 17 00:00:00 2001 From: gechetspr Date: Mon, 9 Dec 2024 13:14:32 +0200 Subject: [PATCH 2/3] CS fixes --- .../Business/Generator/HookGenerator.php | 26 +++---------------- 1 file changed, 3 insertions(+), 23 deletions(-) diff --git a/src/Spryker/Zed/Opentelemetry/Business/Generator/HookGenerator.php b/src/Spryker/Zed/Opentelemetry/Business/Generator/HookGenerator.php index f53620a..bac9f53 100644 --- a/src/Spryker/Zed/Opentelemetry/Business/Generator/HookGenerator.php +++ b/src/Spryker/Zed/Opentelemetry/Business/Generator/HookGenerator.php @@ -15,11 +15,6 @@ class HookGenerator implements HookGeneratorInterface { - /** - * @var string - */ - public const GLOBAL_HOOK_FILE_NAME = 'GlobalHook'; - /** * @var int */ @@ -28,10 +23,11 @@ class HookGenerator implements HookGeneratorInterface /** * @var string */ - protected const OUTPUT_FILE_PATH_PLACEHOLDER_GLOBAL = '%s/%s.php'; - protected const OUTPUT_FILE_PATH_PLACEHOLDER = '%s%s-%sHook.php'; + /** + * @var string + */ protected const CLASSMAP_FILE_NAME_PATTERN = '%sclassmap.php'; /** @@ -128,22 +124,6 @@ protected function ensureDirectoryExists(): void $this->fileSystem->mkdir($this->config->getOutputDir(), static::DIRECTORY_PERMISSIONS); } - /** - * @param array $class - * - * @return string - */ - protected function getOutputFilepathByModule(array $class): string - { - $namespace = explode('\\', $class[static::NAMESPACE_KEY]); - $moduleNamePattern = $namespace[0] . $namespace[1] . $namespace[2]; - return sprintf( - static::OUTPUT_FILE_PATH_PLACEHOLDER_GLOBAL, - $this->config->getOutputDir(), - static::GLOBAL_HOOK_FILE_NAME, - ); - } - /** * @param array $class * From 61a4595d3daa1440d160069a9a30957cae2d6cb3 Mon Sep 17 00:00:00 2001 From: gechetspr Date: Mon, 9 Dec 2024 13:30:41 +0200 Subject: [PATCH 3/3] CS fixes --- .../Zed/Opentelemetry/Business/Generator/HookGenerator.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Spryker/Zed/Opentelemetry/Business/Generator/HookGenerator.php b/src/Spryker/Zed/Opentelemetry/Business/Generator/HookGenerator.php index bac9f53..86fea17 100644 --- a/src/Spryker/Zed/Opentelemetry/Business/Generator/HookGenerator.php +++ b/src/Spryker/Zed/Opentelemetry/Business/Generator/HookGenerator.php @@ -7,7 +7,6 @@ namespace Spryker\Zed\Opentelemetry\Business\Generator; -use PHPUnit\Event\Runtime\PHP; use Spryker\Zed\Opentelemetry\Business\Generator\Collector\ClassCollectorInterface; use Spryker\Zed\Opentelemetry\Business\Generator\ContentCreator\HookContentCreatorInterface; use Spryker\Zed\Opentelemetry\Dependency\External\OpentelemetryToFilesystemInterface;