$stepClassName, 'stepVariableName' => lcfirst($stepClassName), 'stepFilePath' => $stepsFilePath . $stepClassName . '.php', 'stepUsingNamespace' => 'use ' . $payloadFullNamespace . '\\Step\\' . $stepClassName, ]; } ########## WRITE FILES ############### function writeToFile($path, $content) { echo 'Writing contents to file ' . $path . PHP_EOL; $directory = pathinfo($path, PATHINFO_DIRNAME); if (!is_dir($directory)) { mkdir($directory, 0755, true); } file_put_contents($path, $content); } $createNamespaceFiles = !file_exists($pipelineDirectoryPath); $stepsUsingNamespaces = []; $stepsDeclarations = []; $stepsAutoWirings = []; $stepsReferences = []; foreach ($steps as $step) { $stepClassName = $step['stepClassName']; $stepVariableName = $step['stepVariableName']; $stepFilePath = $step['stepFilePath']; $stepUsingNamespace = $step['stepUsingNamespace']; $stepsUsingNamespaces[] = $stepUsingNamespace . ';'; $stepsDeclarations[] = 'private readonly ' . $stepClassName . ' $' . $stepVariableName . ','; $stepsAutoWirings[] = $stepClassName . '::class => AutoWiringFactory::class,'; $stepsReferences[] = '$this->' . $stepVariableName . ','; $stepFileContent = "next()(\$payload, \$pipeline); } } "; writeToFile($stepFilePath, $stepFileContent); } $stepsUsingNamespace = implode(PHP_EOL, $stepsUsingNamespaces); $stepsDeclaration = implode(PHP_EOL . ' ', $stepsDeclarations); $stepsAutoWiring = implode(PHP_EOL . ' ', $stepsAutoWirings); $stepsReference = implode(PHP_EOL . ' ', $stepsReferences); $pipelineFileContent = " [ /// Pipeline // {$pipelineName} {$pipelineClassName}::class => AutoWiringFactory::class, {$stepsAutoWiring} ], ]; "; $serviceManagerFilePath = $pipelineDirectoryPath . 'config/service_manager.php'; writeToFile($serviceManagerFilePath, $serviceManagerFileContent); $configProviderFileContent = " require __DIR__ . './../config/service_manager.php', ]; } } "; $configProviderFilePath = $pipelineDirectoryPath . 'src/ConfigProvider.php'; writeToFile($configProviderFilePath, $configProviderFileContent); }