Example #1
0
 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' => []];
     $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';
     }
     $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;
 }