JonathanTorres\Construct\Configuration::getSettings PHP Method

getSettings() public static method

Get settings derived from the configuration file.
public static getSettings ( string $configurationFile, string $projectName, string $keywords, Filesystem $filesystemHelper ) : Settings
$configurationFile string Path to the configuration file.
$projectName string Name of the project.
$keywords string Composer keywords.
$filesystemHelper JonathanTorres\Construct\Helpers\Filesystem
return Settings
    public static function getSettings($configurationFile, $projectName, $keywords, $filesystemHelper)
    {
        if (!$filesystemHelper->isFile($configurationFile)) {
            $exceptionMessage = "Configuration file '{$configurationFile}' is not existent.";
            throw new \RuntimeException($exceptionMessage);
        }
        if (!$filesystemHelper->isReadable($configurationFile)) {
            $exceptionMessage = "Configuration file '{$configurationFile}' is not readable.";
            throw new \RuntimeException($exceptionMessage);
        }
        $configuration = Yaml::parse($filesystemHelper->get($configurationFile));
        $defaults = new Defaults();
        if (isset($configuration['construct-with'])) {
            $configuration['construct-with'] = array_flip($configuration['construct-with']);
        }
        if (isset($configuration['construct-with']['github'])) {
            $configuration['construct-with']['github-templates'] = true;
            $configuration['construct-with']['github-docs'] = true;
        }
        return new Settings($projectName, isset($configuration['test-framework']) ? $configuration['test-framework'] : $defaults->testingFrameworks[0], isset($configuration['license']) ? $configuration['license'] : $defaults->licenses[0], isset($configuration['namespace']) ? $configuration['namespace'] : null, isset($configuration['construct-with']['git']) ? true : false, isset($configuration['construct-with']['phpcs']) ? true : false, $keywords, isset($configuration['construct-with']['vagrant']) ? true : false, isset($configuration['construct-with']['editor-config']) ? true : false, isset($configuration['php']) ? (string) $configuration['php'] : PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION, isset($configuration['construct-with']['env']) ? true : false, isset($configuration['construct-with']['lgtm']) ? true : false, isset($configuration['construct-with']['github-templates']) ? true : false, isset($configuration['construct-with']['code-of-conduct']) ? true : false, isset($configuration['construct-with']['github-docs']) ? true : false);
    }

Usage Example

 /**
  * Execute command.
  *
  * @param \Symfony\Component\Console\Input\InputInterface   $input
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  *
  * @return void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $projectName = $input->getArgument('name');
     $testFramework = $input->getOption('test');
     $testingFramework = $input->getOption('test-framework');
     if ($testingFramework !== Defaults::TEST_FRAMEWORK) {
         $testFramework = $testingFramework;
     }
     $license = $input->getOption('license');
     $namespace = $input->getOption('namespace');
     $git = $input->getOption('git');
     $phpcs = $input->getOption('phpcs');
     $keywords = $input->getOption('keywords');
     $vagrant = $input->getOption('vagrant');
     $editorConfig = $input->getOption('editor-config');
     $phpVersion = $input->getOption('php');
     $environment = $input->getOption('env');
     $lgtm = $input->getOption('lgtm');
     $githubTemplates = $input->getOption('github-templates');
     $githubDocs = $input->getOption('github-docs');
     $github = $input->getOption('github');
     $codeOfConduct = $input->getOption('code-of-conduct');
     $ignoreDefaultConfiguration = $input->getOption('ignore-default-config');
     $configuration = $input->getOption('config');
     if ($this->isConfigurationApplicable($configuration) && $ignoreDefaultConfiguration === false) {
         $this->settings = Configuration::getSettings($configuration, $projectName, $keywords, $this->filesystem);
     } else {
         if ($github) {
             $githubTemplates = $githubDocs = true;
         }
         $this->settings = new Settings($projectName, $testFramework, $license, $namespace, $git, $phpcs, $keywords, $vagrant, $editorConfig, $phpVersion, $environment, $lgtm, $githubTemplates, $codeOfConduct, $githubDocs);
     }
     if (!$this->str->isValid($projectName)) {
         $warningMessage = '<error>Warning: "' . $projectName . '" is not ' . 'a valid project name, please use "vendor/project"</error>';
         $output->writeln($warningMessage);
         return false;
     }
     $this->warnAndOverwriteInvalidSettingsWithDefaults($output);
     $this->construct->generate($this->settings, new Git(), new Script());
     $this->initializedGitMessage($output);
     $this->bootstrappedCodeceptionMessage($testFramework, $output);
     $this->initializedBehatMessage($testFramework, $output);
     $output->writeln('<info>Project "' . $projectName . '" constructed.</info>');
 }
Configuration