InfyOm\Generator\Common\GeneratorConfig::overrideOptionsFromJsonFile PHP Method

overrideOptionsFromJsonFile() public method

public overrideOptionsFromJsonFile ( $jsonData )
    public function overrideOptionsFromJsonFile($jsonData)
    {
        $options = self::$availableOptions;
        foreach ($options as $option) {
            if (isset($jsonData['options'][$option])) {
                $this->setOption($option, $jsonData['options'][$option]);
            }
        }
        $addOns = ['swagger', 'tests', 'datatables'];
        foreach ($addOns as $addOn) {
            if (isset($jsonData['addOns'][$addOn])) {
                $this->addOns[$addOn] = $jsonData['addOns'][$addOn];
            }
        }
    }

Usage Example

 private function getInputFromFileOrJson()
 {
     // fieldsFile option will get high priority than json option if both options are passed
     try {
         if ($this->getOption('fieldsFile')) {
             if (file_exists($this->getOption('fieldsFile'))) {
                 $filePath = $this->getOption('fieldsFile');
             } else {
                 $filePath = base_path($this->getOption('fieldsFile'));
             }
             if (!file_exists($filePath)) {
                 $this->commandError('Fields file not found');
                 exit;
             }
             $fileContents = file_get_contents($filePath);
             $jsonData = json_decode($fileContents, true);
             $this->inputFields = array_merge($this->inputFields, GeneratorFieldsInputUtil::validateFieldsFile($jsonData));
         } else {
             $fileContents = $this->getOption('jsonFromGUI');
             $jsonData = json_decode($fileContents, true);
             $this->inputFields = array_merge($this->inputFields, GeneratorFieldsInputUtil::validateFieldsFile($jsonData['fields']));
             $this->config->overrideOptionsFromJsonFile($jsonData);
             if (isset($jsonData['migrate'])) {
                 $this->config->forceMigrate = $jsonData['migrate'];
             }
         }
         $this->checkForDiffPrimaryKey();
     } catch (Exception $e) {
         $this->commandError($e->getMessage());
         exit;
     }
 }