コード例 #1
0
ファイル: Paths.php プロジェクト: niieani/napkin
 public static function getFullPath($site)
 {
     $files = FileOperation::getAllFilesByExtension(Paths::$db, 'yml');
     $pathinfo = array();
     foreach ($files as $id => $file) {
         $pathinfo[$id] = FileOperation::pathinfo_utf($file);
         if ($pathinfo[$id]['filename'] == $site) {
             return $files[$id];
         }
     }
     return false;
 }
コード例 #2
0
ファイル: TemplatesDB.php プロジェクト: niieani/napkin
 public function AddFromFile($file, $scopeUser = false)
 {
     LogCLI::Message('Adding template file: ' . LogCLI::BLUE . $file . LogCLI::RESET, 4);
     try {
         $data = trim(file_get_contents($file));
         $scopeData = FileOperation::pathinfo_utf($file);
         $scopeName = $scopeUser === false ? $scopeData['filename'] : $scopeUser;
         $this->DB = ArrayTools::MergeArrays($this->DB, array($scopeName => $data));
         LogCLI::MessageResult('Templates DB updated with ' . LogCLI::BLUE . $scopeName . LogCLI::RESET . ' definition', 5, LogCLI::INFO);
         LogCLI::Result(LogCLI::OK, 4);
     } catch (Exception $e) {
         LogCLI::Result(LogCLI::FAIL);
         LogCLI::Fail($e->getMessage());
     }
 }
コード例 #3
0
ファイル: SettingsDB.php プロジェクト: niieani/napkin
 /**
  * @param string $file          path to a YAML file
  * @param string|bool $path     start the merge at designated settings path
  * @param bool $applyDefaults
  * @param bool $mergeDefaults
  * @param bool $createNewIfNonexistant
  * @param bool $addFilename
  * @return void
  */
 public function mergeFromYAML($file, $path = false, $applyDefaults = false, $mergeDefaults = true, $createNewIfNonexistant = false, $addFilename = false)
 {
     LogCLI::Message('Loading file: ' . LogCLI::BLUE . $file . LogCLI::RESET, 1);
     if (file_exists($file)) {
         LogCLI::Result(LogCLI::OK);
         LogCLI::Message('Parsing YAML file: ' . LogCLI::BLUE . $file . LogCLI::RESET, 1);
         try {
             //$config = YAML::load($file);
             $config = Yaml::parse($file);
             //                 if the file is empty create an empty array:
             //                    $config = array();
             if (!empty($config)) {
                 if ($path === false) {
                     $this->DB = ArrayTools::MergeArrays($this->DB, $config);
                     if ($mergeDefaults === true) {
                         $this->mergeDefinitionsDB($config, $this->defaultsDefinitions, $applyDefaults, 'defaults');
                     }
                 } else {
                     if ($addFilename === true) {
                         $fileInfo = FileOperation::pathinfo_utf($file);
                         $config['filename'] = $fileInfo['filename'];
                         //$config['filename'] = $file;
                     }
                     if (!isset($config['template']) && (!isset($config['disabled']) || $config['disabled'] == false)) {
                         $iteration = $this->mergeOneIterativeByPath($path, $config);
                         //var_dump($this->defaultsDefinitions);
                         /**
                          * applying parents as defaults
                          */
                         if (isset($config['parent'])) {
                             foreach ((array) $config['parent'] as $parentName) {
                                 if (is_array($parentFiles = FileOperation::findFile($parentName, Paths::$db))) {
                                     if (count($parentFiles) > 1) {
                                         LogCLI::MessageResult('You have to be more specific in the way you specify the parent, found more than one file under this name: ' . $parentName, 0, LogCLI::INFO);
                                     } else {
                                         $parentFile =& current($parentFiles);
                                         LogCLI::Message('Parent definition found: ' . LogCLI::BLUE . $parentFile . LogCLI::RESET . ', parsing and merging.', 2);
                                         if (!isset($this->parentDefinitions[$parentFile])) {
                                             $parentConfig = array('parent' => Yaml::parse($parentFile));
                                             $this->parentDefinitions[$parentFile] = array();
                                             $this->mergeDefinitionsDB($parentConfig, $this->parentDefinitions[$parentFile], false, 'parent');
                                         }
                                         $this->applyDefaults($this->DB, $this->parentDefinitions[$parentFile], $path . '/' . $iteration, 'parent', true, false);
                                         LogCLI::Result(LogCLI::OK);
                                     }
                                     //var_dump($this->parentDefinitions);
                                 }
                             }
                         }
                         if ($applyDefaults === true) {
                             $this->applyDefaults($this->DB, $this->defaultsDefinitions, $path . '/' . $iteration, 'defaults', false, false);
                         }
                     }
                 }
                 LogCLI::MessageResult('Settings DB populated with new data!', 5, LogCLI::INFO);
             } else {
                 LogCLI::MessageResult('File empty, ignoring', 5, LogCLI::INFO);
             }
             LogCLI::Result(LogCLI::OK);
         } catch (\Exception $e) {
             LogCLI::Result(LogCLI::FAIL);
             LogCLI::Fail($e->getMessage());
         }
     } else {
         LogCLI::Result(LogCLI::FAIL);
         LogCLI::Fail("No such file: {$file}");
         if ($createNewIfNonexistant === true) {
             LogCLI::Message('Creating a new empty file.', 0);
             try {
                 //fclose(fopen($file, 'x'));
                 FileOperation::CreateEmptyFile($file);
                 $this->mergeFromYAML($file, $path, $applyDefaults, $mergeDefaults, false);
                 LogCLI::Result(LogCLI::OK);
             } catch (\Exception $e) {
                 LogCLI::Result(LogCLI::FAIL);
                 LogCLI::Fail($e->getMessage());
             }
         }
     }
 }