AcMailer\Controller\ConfigMigrationController::parseConfigAction PHP Method

parseConfigAction() public method

public parseConfigAction ( )
    public function parseConfigAction()
    {
        /** @var Request $request */
        $request = $this->getRequest();
        $format = $request->getParam('format', 'php');
        $writer = $this->createWriter($format);
        $configKey = $request->getParam('configKey', 'mail_options');
        // Default to the old config key
        $outputFile = $request->getParam('outputFile');
        // Global configuration not found
        if (!isset($this->globalConfig[$configKey])) {
            $this->getConsole()->writeLine(sprintf('It wasn\'t possible to find the configuration key "%s"', $configKey), ColorInterface::RED);
            return PHP_EOL;
        }
        // Write new configuration to CLI
        $newConfig = $this->configMigrationService->parseConfig($this->globalConfig[$configKey]);
        if (!isset($outputFile)) {
            $this->getConsole()->writeLine('This is your new configuration for the AcMailer module:', ColorInterface::GREEN);
            $this->getConsole()->write($writer->toString($newConfig), ColorInterface::LIGHT_BLUE);
            return PHP_EOL;
        }
        // Write new configuration to file
        $writer->toFile($outputFile, $newConfig);
        $this->getConsole()->writeLine(sprintf('The new configuration for the AcMailer module has been written to "%s":', $outputFile), ColorInterface::GREEN);
        return PHP_EOL;
    }

Usage Example

 public function testOutputFile()
 {
     $this->initController(['mail_options' => []]);
     $expectedFile = __DIR__ . '/../attachments/mail_config.json';
     $this->setRequestParams(['format' => 'json', 'outputFile' => $expectedFile]);
     $this->controller->parseConfigAction();
     $this->assertTrue(file_exists($expectedFile));
     $this->assertEquals('{"acmailer_options":{"default":{"message_options":{"body":[]},' . '"smtp_options":{"connection_config":[]},"file_options":[]}}}', file_get_contents($expectedFile));
     unlink($expectedFile);
 }