Esempio n. 1
0
 public function set(array $params)
 {
     if (!empty($this->allSettings)) {
         $this->allSettings = System::MergeArrays($this->allSettings, $params);
     } else {
         $this->allSettings = $params;
     }
     //var_dump($params);
     foreach ($params as $setting => $value) {
         if (is_array($value)) {
             if (count($value) > 1) {
                 LogCLI::MessageResult('Setting: ' . LogCLI::GREEN . $setting . LogCLI::RESET . ' = ' . LogCLI::YELLOW . System::Dump($value, '  Subsetting: ') . LogCLI::RESET, 5, LogCLI::INFO);
                 /*
                 foreach($value as $subvalue)
                 {
                     
                     //LogCLI::MessageResult('Setting (multi): '.LogCLI::GREEN.$setting.LogCLI::RESET.' = '.LogCLI::YELLOW.$subvalue.LogCLI::RESET, 5, LogCLI::INFO);
                 }
                 */
                 //if(!(is_array($this->params[$setting])))
                 $this->params[$setting] = $value;
                 // this is currently setting too many settings than required
                 // which is not optimal, but works
             } else {
                 LogCLI::MessageResult('Setting (single from array): ' . LogCLI::GREEN . $setting . LogCLI::RESET . ' = ' . end($value) . LogCLI::RESET, 5, LogCLI::INFO);
                 $this->params[$setting] = end($value);
             }
         } else {
             LogCLI::MessageResult('Setting (single): ' . LogCLI::GREEN . $setting . LogCLI::RESET . ' = ' . LogCLI::YELLOW . $value . LogCLI::RESET, 5, LogCLI::INFO);
             $this->params[$setting] = $value;
         }
     }
 }
Esempio n. 2
0
 public function ParseFromYAMLs(array $files)
 {
     $this->SetAutomatedValues();
     //Stems::LoadDefinitions('nginx');
     $last = false;
     $total = count($files) - 1;
     $sites_defaults = array();
     foreach ($files as $i => $file) {
         if ($total == $i) {
             $last = true;
         }
         LogCLI::Message('Loading file: ' . LogCLI::BLUE . $file . LogCLI::RESET, 1);
         if (file_exists($file)) {
             LogCLI::Result(LogCLI::OK);
             LogCLI::Message('Parsing file: ' . LogCLI::BLUE . $file . LogCLI::RESET, 1);
             try {
                 $config = YAML::load($file);
                 LogCLI::Result(LogCLI::OK);
             } catch (Exception $e) {
                 LogCLI::Result(LogCLI::FAIL);
                 LogCLI::Fail($e->getMessage());
             }
             if (isset($config['nginx'])) {
                 // adding to main DB
                 $this->settingsDB = System::MergeArrays($this->settingsDB, $config);
                 foreach ($this->usableScopes as $arrayPath) {
                     //LogCLI::MessageResult($arrayPath);
                     //var_dump(self::getArrayElementByPath($config['nginx'], $arrayPath, 1));
                     /*
                     foreach(self::accessArrayElementByPath($config['nginx'], $arrayPath) as $scope => $scopeConfig)
                     {
                         echo("skope ".$scope.":\n");
                     }
                     */
                     //LogCLI::MessageResult('Path: '.LogCLI::BLUE.$arrayPath.LogCLI::RESET, 6, LogCLI::INFO);
                     foreach (self::getArrayElementByPath($config['nginx'], $arrayPath, true) as $scope => $scopeConfig) {
                         if ($scopeConfig !== false) {
                             //echo("skope ".$scope.":\n");
                             //var_dump($scopeConfig);
                             if (is_array($scopeConfig) && $scope != 'sites') {
                                 //LogCLI::MessageResult("Number of dimentions in scope [$scope]: ".self::array_dimen_count($scopeConfig), 3);
                                 //self::array_dimen_count($scopeConfig);
                                 //var_dump($scopeConfig);
                                 //LogCLI::MessageResult($scope);
                                 NginxConfig::setAll(self::accessArrayElementByPath($config['nginx'], $arrayPath), self::accessArrayElementByPath($this->nginx, $arrayPath));
                                 if ($last) {
                                     //LogCLI::MessageResult($scope);
                                     LogCLI::Message("Generating scope: [{$arrayPath}]", 3);
                                     NginxScope::addAllStems(self::accessArrayElementByPath($this->nginx, $arrayPath), $this->confScope);
                                     LogCLI::Result(LogCLI::INFO);
                                 }
                             }
                         }
                     }
                 }
                 // sites scopes
                 if (isset($config['nginx']['sites']['_defaults'])) {
                     $config['nginx']['sites']['_defaults'] = self::ConformizeConfigSite($config['nginx']['sites']['_defaults']);
                     $sites_defaults = System::MergeArrays($sites_defaults, $config['nginx']['sites']['_defaults']);
                 }
                 if (isset($config['nginx']['sites'])) {
                     foreach ($config['nginx']['sites'] as $key => $site) {
                         if ($key != '_defaults') {
                             $site = self::ConformizeConfigSite($site);
                             $siteScope[$key] = new NginxScope();
                             LogCLI::Message("Pushing defaults for subscope [server]: {$key}", 3);
                             NginxConfig::resetAll($this->nginx['sites']);
                             if (isset($sites_defaults)) {
                                 NginxConfig::setAll($sites_defaults, $this->nginx['sites']);
                             }
                             LogCLI::Result(LogCLI::INFO);
                             LogCLI::Message("Setting in subscope [server]: {$key}", 3);
                             //$siteScope[$key] = new NginxScope;
                             NginxConfig::setAll($site, $this->nginx['sites']);
                             LogCLI::Result(LogCLI::INFO);
                             LogCLI::Message("Adding subscope [server]: {$key}", 3);
                             NginxScope::addAllStems($this->nginx['sites'], $siteScope[$key]);
                             LogCLI::Result(LogCLI::INFO);
                         }
                     }
                 }
                 if (isset($siteScope)) {
                     foreach ($siteScope as $scope) {
                         LogCLI::Message("Adding scope: [server]", 3);
                         $this->confScope->addStem(array('scope' => 'http', 'output' => $scope->returnScopes(), 'level' => 1));
                         LogCLI::Result(LogCLI::INFO);
                     }
                 }
                 $this->confScope->orderScopes(array('_ROOT', 'events', 'http'));
             }
         } else {
             LogCLI::Result(LogCLI::FAIL);
             LogCLI::Fatal("No such file: {$file}");
         }
     }
     //return false;
 }