public function saveConfig($password, Config $cfg) { if ($cfg->isValid()) { $asArray = $cfg->asArray(); $asArray['loaded'] = 'yes'; $json = JSON::encode($asArray); $ciphertext = Encryption::encrypt($password, $json); file_put_contents(self::$CONFIG_DECRYPTED, $json); file_put_contents(self::$CONFIG, $ciphertext); if (file_exists('/tmp_disk/price.json')) { unlink('/tmp_disk/price.json'); } } else { throw new SetupMachineException("Configuration was invalid or incomplete"); } }
public static function denormalize(Config $cfg) { $denormalized = ['selector' => '', 'sources' => [], 'staticPrice' => '', 'modifierEnabled' => [], 'modifier' => [], 'wallet' => ['id' => '', 'mainPass' => '', 'secondPass' => '', 'fromAddress' => ''], 'email' => ['username' => '', 'password' => ''], 'contact' => ['information' => ''], 'transaction-cron' => false, 'transactions' => [], 'coinee' => ['email' => '', 'apiKey' => '', 'bitstampId' => '']]; $cfgData = $cfg->asArray(); if (isset($cfgData['transactions']['maximum'])) { $denormalized['transactions']['maximum'] = $cfgData['transactions']['maximum']; } if (!empty($cfgData['transaction-cron'])) { $denormalized['transaction-cron'] = $cfgData['transaction-cron']; } $denormalized['wallet'] = $cfgData['walletProvider']; unset($denormalized['wallet']['provider']); $denormalized['email'] = $cfgData['email']; if (empty($denormalized['email']['machine'])) { $denormalized['email']['machine'] = 'Project Skyhook 00'; } if (!empty($cfgData['coinee'])) { $denormalized['coinee'] = $cfgData['coinee']; } $denormalized['contact']['information'] = @$cfgData['contact']['information']; $denormalized['selector'] = 'single'; $pp = $cfg->getPricingProvider(); if (!empty($pp)) { Config::walkPricingProviders($cfg->getPricingProvider(), function ($p) use(&$denormalized) { $name = get_class($p); if ($p instanceof PricingProxy) { if ($p instanceof PriceModifier) { $denormalized['modifierEnabled'][$name] = true; $denormalized['modifier'][$name] = strval($p->getValue()); } else { $denormalized['selector'] = $name; } } else { $denormalized['sources'][] = $name; if (preg_match('#.*StaticPrice$#', $name)) { $denormalized['staticPrice'] = strval($p->getPrice()); } } }); } $denormalized['sources'] = implode(',', $denormalized['sources']); return $denormalized; }