Ejemplo n.º 1
0
 /** Loads data from .cfg files into a directory, recursively.
  * This function loads configuration from all .ini files in the given folder. It also loads the configurations found in all sub-directories.
  * The files are proceeded as .ini files, but adds a useful feature to them : multi-level sections. Using the '.', users will be able to
  * define more than one level of configuration (useful for data ordering). It does not parses the UNIX hidden directories.
  * 
  * \param $dir The directory to analyze.
  * \return The configuration if it loaded successfully, FALSE otherwise.
  */
 public static function parseCFGDirRecursive($dir)
 {
     if (!($dirContent = scandir($dir))) {
         return FALSE;
     }
     $finalConfig = array();
     $cfgdata = '';
     foreach ($dirContent as $file) {
         if (is_file($dir . '/' . $file) && pathinfo($file, PATHINFO_EXTENSION) == 'cfg') {
             $cfgdata .= "\n" . file_get_contents($dir . '/' . $file);
         } elseif (is_dir($dir . '/' . $file) && !in_array($file, array('.', '..')) && $file[0] != '.') {
             if ($fileConf = Leelabot::parseCFGDirRecursive($dir . '/' . $file)) {
                 $finalConfig = array_merge($finalConfig, $fileConf);
             } else {
                 Leelabot::message('Parse error in $0 directory.', array($dir), E_WARNING);
                 return FALSE;
             }
         }
     }
     $finalConfig = array_merge($finalConfig, Leelabot::parseINIStringRecursive($cfgdata));
     return $finalConfig;
 }
Ejemplo n.º 2
0
<?php

/**
 * \file tests/config/parseconf.php
 * \author Yohann Lorant <*****@*****.**>
 * \version 0.5
 * \brief Config parser tests.
 *
 * \section LICENSE
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details at
 * http://www.gnu.org/copyleft/gpl.html
 *
 * \section DESCRIPTION
 *
 * This file tests the behavior of the config file parser (for INI-style files, but with a feature added) packed in Leelabot class.
 * This file will NOT be further documented.
 */
include '../../core/leelabot.class.php';
$leelabot = new Leelabot();
echo print_r($leelabot->parseCFGDirRecursive('conf'), TRUE);