コード例 #1
0
ファイル: Ini.php プロジェクト: NareshChennuri/pyng
 /**
  * Loads the section $section from the config file $filename for
  * access facilitated by nested object properties.
  *
  * If the section name contains a ":" then the section name to the right
  * is loaded and included into the properties. Note that the keys in
  * this $section will override any keys of the same
  * name in the sections that have been included via ":".
  *
  * If the $section is null, then all sections in the ini file are loaded.
  *
  * If any key includes a ".", then this will act as a separator to
  * create a sub-property.
  *
  * example ini file:
  *      [all]
  *      db.connection = database
  *      hostname = live
  *
  *      [staging : all]
  *      hostname = staging
  *
  * after calling $data = new JO_Config_Ini($file, 'staging'); then
  *      $data->hostname === "staging"
  *      $data->db->connection === "database"
  *
  * The $options parameter may be provided as either a boolean or an array.
  * If provided as a boolean, this sets the $allowModifications option of
  * JO_Config. If provided as an array, there are two configuration
  * directives that may be set. For example:
  *
  * $options = array(
  *     'allowModifications' => false,
  *     'nestSeparator'      => '->'
  *      );
  *
  * @param  string        $filename
  * @param  string|null   $section
  * @param  boolean|array $options
  * @throws JO_Config_Exception
  * @return void
  */
 public function __construct($filename, $section = null, $options = false, $parse_key = false)
 {
     if (empty($filename)) {
         /**
          * @see JO_Config_Exception
          */
         require_once 'JO/Exception.php';
         throw new JO_Exception('Filename is not set');
     }
     $allowModifications = false;
     if (is_bool($options)) {
         $allowModifications = $options;
     } elseif (is_array($options)) {
         if (isset($options['allowModifications'])) {
             $allowModifications = (bool) $options['allowModifications'];
         }
         if (isset($options['nestSeparator'])) {
             $this->_nestSeparator = (string) $options['nestSeparator'];
         }
         if (isset($options['skipExtends'])) {
             $this->_skipExtends = (bool) $options['skipExtends'];
         }
     }
     $iniArray = $this->_loadIniFile($filename);
     if (null === $section) {
         // Load entire file
         $dataArray = array();
         foreach ($iniArray as $sectionName => $sectionData) {
             if (!is_array($sectionData)) {
                 $dataArray = $this->_arrayMergeRecursive($dataArray, $this->_processKey(array(), $sectionName, $sectionData));
             } else {
                 if ($parse_key) {
                     $dataArray = $this->_arrayMergeRecursive($dataArray, $this->_processKey(array(), $sectionName, $sectionData));
                 } else {
                     $dataArray[$sectionName] = $this->_processSection($iniArray, $sectionName);
                 }
             }
         }
         parent::__construct($dataArray, $allowModifications);
     } else {
         // Load one or more sections
         if (!is_array($section)) {
             $section = array($section);
         }
         $dataArray = array();
         foreach ($section as $sectionName) {
             if (!isset($iniArray[$sectionName])) {
                 /**
                  * @see JO_Config_Exception
                  */
                 require_once 'JO/Exception.php';
                 throw new JO_Exception("Section '{$sectionName}' cannot be found in {$filename}");
             }
             $dataArray = $this->_arrayMergeRecursive($this->_processSection($iniArray, $sectionName), $dataArray);
         }
         parent::__construct($dataArray, $allowModifications);
     }
     $this->_loadedSection = $section;
 }
コード例 #2
0
ファイル: Definition.php プロジェクト: NareshChennuri/pyng
 /**
  * setConfig()
  *
  * @param JO_Config $config
  * @return JO_Db_Table_Definition
  */
 public function setConfig(JO_Config $config)
 {
     $this->setOptions($config->toArray());
     return $this;
 }