Esempio n. 1
0
 public static function LoadDefinitions($application)
 {
     foreach (glob(HC_DIR . '/stems/' . $application . "/*.php") as $filename) {
         try {
             LogCLI::Message("Loading definitions from file: {$filename}", 2);
             include $filename;
             LogCLI::Result(LogCLI::OK);
         } catch (Exception $e) {
             LogCLI::Result(LogCLI::FAIL);
             LogCLI::Fatal('Caught exception - ' . $e->getMessage());
         }
     }
     /*
     $file = HC_DIR.'/stems/'.$application.'/definitions.php';
     echo $file;
     if(file_exists($file))
     {
         try { 
             include_once($file);
         } catch (Exception $e) {
             echo 'Caught exception: ',  $e->getMessage(), "\n";
         }
     }
     */
 }
Esempio n. 2
0
 public function AddFromFiles(array $files)
 {
     foreach ($files as $file) {
         LogCLI::Message('Loading template file: ' . LogCLI::BLUE . $file . LogCLI::RESET, 2);
         if (file_exists($file)) {
             $this->AddFromFile($file);
             LogCLI::Result(LogCLI::OK);
         } else {
             LogCLI::Result(LogCLI::FAIL);
             LogCLI::Fatal("No such file: {$file}");
         }
     }
 }
Esempio n. 3
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;
 }