コード例 #1
0
ファイル: Ini.php プロジェクト: jasmun/Noco100
 /**
  * Root elements that are not assigned to any section needs to be
  * on the top of config.
  *
  * @see    http://framework.zend.com/issues/browse/ZF-6289
  * @param  IfwPsn_Vendor_Zend_Config
  * @return IfwPsn_Vendor_Zend_Config
  */
 protected function _sortRootElements(IfwPsn_Vendor_Zend_Config $config)
 {
     $configArray = $config->toArray();
     $sections = array();
     // remove sections from config array
     foreach ($configArray as $key => $value) {
         if (is_array($value)) {
             $sections[$key] = $value;
             unset($configArray[$key]);
         }
     }
     // readd sections to the end
     foreach ($sections as $key => $value) {
         $configArray[$key] = $value;
     }
     return new IfwPsn_Vendor_Zend_Config($configArray);
 }
コード例 #2
0
ファイル: Abstract.php プロジェクト: jasmun/Noco100
 /**
  * Set options from config object
  *
  * @param  IfwPsn_Vendor_Zend_Config $config
  * @return IfwPsn_Vendor_Zend_Form_Decorator_Abstract
  */
 public function setConfig(IfwPsn_Vendor_Zend_Config $config)
 {
     return $this->setOptions($config->toArray());
 }
コード例 #3
0
ファイル: Ini.php プロジェクト: jasmun/Noco100
 /**
  * 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 IfwPsn_Vendor_Zend_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
  * IfwPsn_Vendor_Zend_Config. If provided as an array, there are three configuration
  * directives that may be set. For example:
  *
  * $options = array(
  *     'allowModifications' => false,
  *     'nestSeparator'      => ':',
  *     'skipExtends'        => false,
  *      );
  *
  * @param  string        $filename
  * @param  mixed         $section
  * @param  boolean|array $options
  * @throws IfwPsn_Vendor_Zend_Config_Exception
  * @return void
  */
 public function __construct($filename, $section = null, $options = false)
 {
     if (empty($filename)) {
         /**
          * @see IfwPsn_Vendor_Zend_Config_Exception
          */
         require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Config/Exception.php';
         throw new IfwPsn_Vendor_Zend_Config_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 {
                 $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 IfwPsn_Vendor_Zend_Config_Exception
                  */
                 require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Config/Exception.php';
                 throw new IfwPsn_Vendor_Zend_Config_Exception("Section '{$sectionName}' cannot be found in {$filename}");
             }
             $dataArray = $this->_arrayMergeRecursive($this->_processSection($iniArray, $sectionName), $dataArray);
         }
         parent::__construct($dataArray, $allowModifications);
     }
     $this->_loadedSection = $section;
 }
コード例 #4
0
ファイル: Xml.php プロジェクト: jasmun/Noco100
 /**
  * Loads the section $section from the config file (or string $xml for
  * access facilitated by nested object properties.
  *
  * Sections are defined in the XML as children of the root element.
  *
  * In order to extend another section, a section defines the "extends"
  * attribute having a value of the section name from which the extending
  * section inherits values.
  *
  * Note that the keys in $section will override any keys of the same
  * name in the sections that have been included via "extends".
  * 
  * The $options parameter may be provided as either a boolean or an array.
  * If provided as a boolean, this sets the $allowModifications option of
  * IfwPsn_Vendor_Zend_Config. If provided as an array, there are two configuration
  * directives that may be set. For example:
  *
  * $options = array(
  *     'allowModifications' => false,
  *     'skipExtends'        => false
  *      );
  *
  * @param  string        $xml     XML file or string to process
  * @param  mixed         $section Section to process
  * @param  array|boolean $options 
  * @throws IfwPsn_Vendor_Zend_Config_Exception When xml is not set or cannot be loaded
  * @throws IfwPsn_Vendor_Zend_Config_Exception When section $sectionName cannot be found in $xml
  */
 public function __construct($xml, $section = null, $options = false)
 {
     if (empty($xml)) {
         require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Config/Exception.php';
         throw new IfwPsn_Vendor_Zend_Config_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['skipExtends'])) {
             $this->_skipExtends = (bool) $options['skipExtends'];
         }
     }
     set_error_handler(array($this, '_loadFileErrorHandler'));
     // Warnings and errors are suppressed
     if (strstr($xml, '<?xml')) {
         $config = IfwPsn_Vendor_Zend_Xml_Security::scan($xml);
     } else {
         try {
             if (!($config = IfwPsn_Vendor_Zend_Xml_Security::scanFile($xml))) {
                 require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Config/Exception.php';
                 throw new IfwPsn_Vendor_Zend_Config_Exception("Error failed to load {$xml} file");
             }
         } catch (IfwPsn_Vendor_Zend_Xml_Exception $e) {
             require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Config/Exception.php';
             throw new IfwPsn_Vendor_Zend_Config_Exception($e->getMessage());
         }
     }
     restore_error_handler();
     // Check if there was a error while loading file
     if ($this->_loadFileErrorStr !== null) {
         require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Config/Exception.php';
         throw new IfwPsn_Vendor_Zend_Config_Exception($this->_loadFileErrorStr);
     }
     if ($section === null) {
         $dataArray = array();
         foreach ($config as $sectionName => $sectionData) {
             $dataArray[$sectionName] = $this->_processExtends($config, $sectionName);
         }
         parent::__construct($dataArray, $allowModifications);
     } else {
         if (is_array($section)) {
             $dataArray = array();
             foreach ($section as $sectionName) {
                 if (!isset($config->{$sectionName})) {
                     require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Config/Exception.php';
                     throw new IfwPsn_Vendor_Zend_Config_Exception("Section '{$sectionName}' cannot be found in {$xml}");
                 }
                 $dataArray = array_merge($this->_processExtends($config, $sectionName), $dataArray);
             }
             parent::__construct($dataArray, $allowModifications);
         } else {
             if (!isset($config->{$section})) {
                 require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Config/Exception.php';
                 throw new IfwPsn_Vendor_Zend_Config_Exception("Section '{$section}' cannot be found in {$xml}");
             }
             $dataArray = $this->_processExtends($config, $section);
             if (!is_array($dataArray)) {
                 // Section in the XML file contains just one top level string
                 $dataArray = array($section => $dataArray);
             }
             parent::__construct($dataArray, $allowModifications);
         }
     }
     $this->_loadedSection = $section;
 }
コード例 #5
0
ファイル: Core.php プロジェクト: jasmun/Noco100
 /**
  * Set options using an instance of type IfwPsn_Vendor_Zend_Config
  *
  * @param IfwPsn_Vendor_Zend_Config $config
  * @return IfwPsn_Vendor_Zend_Cache_Core
  */
 public function setConfig(IfwPsn_Vendor_Zend_Config $config)
 {
     $options = $config->toArray();
     while (list($name, $value) = each($options)) {
         $this->setOption($name, $value);
     }
     return $this;
 }
コード例 #6
0
ファイル: Json.php プロジェクト: jasmun/Noco100
 /**
  * Loads the section $section from the config file encoded as JSON
  *
  * Sections are defined as properties of the main object
  *
  * In order to extend another section, a section defines the "_extends"
  * property having a value of the section name from which the extending
  * section inherits values.
  *
  * Note that the keys in $section will override any keys of the same
  * name in the sections that have been included via "_extends".
  *
  * @param  string  $json     JSON file or string to process
  * @param  mixed   $section Section to process
  * @param  boolean $options Whether modifiacations are allowed at runtime
  * @throws IfwPsn_Vendor_Zend_Config_Exception When JSON text is not set or cannot be loaded
  * @throws IfwPsn_Vendor_Zend_Config_Exception When section $sectionName cannot be found in $json
  */
 public function __construct($json, $section = null, $options = false)
 {
     if (empty($json)) {
         require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Config/Exception.php';
         throw new IfwPsn_Vendor_Zend_Config_Exception('Filename is not set');
     }
     $allowModifications = false;
     if (is_bool($options)) {
         $allowModifications = $options;
     } elseif (is_array($options)) {
         foreach ($options as $key => $value) {
             switch (strtolower($key)) {
                 case 'allow_modifications':
                 case 'allowmodifications':
                     $allowModifications = (bool) $value;
                     break;
                 case 'skip_extends':
                 case 'skipextends':
                     $this->_skipExtends = (bool) $value;
                     break;
                 case 'ignore_constants':
                 case 'ignoreconstants':
                     $this->_ignoreConstants = (bool) $value;
                     break;
                 default:
                     break;
             }
         }
     }
     set_error_handler(array($this, '_loadFileErrorHandler'));
     // Warnings and errors are suppressed
     if ($json[0] != '{') {
         $json = file_get_contents($json);
     }
     restore_error_handler();
     // Check if there was a error while loading file
     if ($this->_loadFileErrorStr !== null) {
         require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Config/Exception.php';
         throw new IfwPsn_Vendor_Zend_Config_Exception($this->_loadFileErrorStr);
     }
     // Replace constants
     if (!$this->_ignoreConstants) {
         $json = $this->_replaceConstants($json);
     }
     // Parse/decode
     try {
         $config = IfwPsn_Vendor_Zend_Json::decode($json);
     } catch (IfwPsn_Vendor_Zend_Json_Exception $e) {
         // decode failed
         require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Config/Exception.php';
         throw new IfwPsn_Vendor_Zend_Config_Exception("Error parsing JSON data");
     }
     if ($section === null) {
         $dataArray = array();
         foreach ($config as $sectionName => $sectionData) {
             $dataArray[$sectionName] = $this->_processExtends($config, $sectionName);
         }
         parent::__construct($dataArray, $allowModifications);
     } elseif (is_array($section)) {
         $dataArray = array();
         foreach ($section as $sectionName) {
             if (!isset($config[$sectionName])) {
                 require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Config/Exception.php';
                 throw new IfwPsn_Vendor_Zend_Config_Exception(sprintf('Section "%s" cannot be found', $sectionName));
             }
             $dataArray = array_merge($this->_processExtends($config, $sectionName), $dataArray);
         }
         parent::__construct($dataArray, $allowModifications);
     } else {
         if (!isset($config[$section])) {
             require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Config/Exception.php';
             throw new IfwPsn_Vendor_Zend_Config_Exception(sprintf('Section "%s" cannot be found', $section));
         }
         $dataArray = $this->_processExtends($config, $section);
         if (!is_array($dataArray)) {
             // Section in the JSON data contains just one top level string
             $dataArray = array($section => $dataArray);
         }
         parent::__construct($dataArray, $allowModifications);
     }
     $this->_loadedSection = $section;
 }
コード例 #7
0
ファイル: Yaml.php プロジェクト: jasmun/Noco100
 /**
  * Loads the section $section from the config file encoded as YAML
  *
  * Sections are defined as properties of the main object
  *
  * In order to extend another section, a section defines the "_extends"
  * property having a value of the section name from which the extending
  * section inherits values.
  *
  * Note that the keys in $section will override any keys of the same
  * name in the sections that have been included via "_extends".
  *
  * Options may include:
  * - allow_modifications: whether or not the config object is mutable
  * - skip_extends: whether or not to skip processing of parent configuration
  * - yaml_decoder: a callback to use to decode the Yaml source
  *
  * @param  string        $yaml     YAML file to process
  * @param  mixed         $section  Section to process
  * @param  array|boolean $options
  */
 public function __construct($yaml, $section = null, $options = false)
 {
     if (empty($yaml)) {
         require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Config/Exception.php';
         throw new IfwPsn_Vendor_Zend_Config_Exception('Filename is not set');
     }
     $ignoreConstants = $staticIgnoreConstants = self::ignoreConstants();
     $allowModifications = false;
     if (is_bool($options)) {
         $allowModifications = $options;
     } elseif (is_array($options)) {
         foreach ($options as $key => $value) {
             switch (strtolower($key)) {
                 case 'allow_modifications':
                 case 'allowmodifications':
                     $allowModifications = (bool) $value;
                     break;
                 case 'skip_extends':
                 case 'skipextends':
                     $this->_skipExtends = (bool) $value;
                     break;
                 case 'ignore_constants':
                 case 'ignoreconstants':
                     $ignoreConstants = (bool) $value;
                     break;
                 case 'yaml_decoder':
                 case 'yamldecoder':
                     $this->setYamlDecoder($value);
                     break;
                 default:
                     break;
             }
         }
     }
     // Suppress warnings and errors while loading file
     set_error_handler(array($this, '_loadFileErrorHandler'));
     $yaml = file_get_contents($yaml);
     restore_error_handler();
     // Check if there was a error while loading file
     if ($this->_loadFileErrorStr !== null) {
         require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Config/Exception.php';
         throw new IfwPsn_Vendor_Zend_Config_Exception($this->_loadFileErrorStr);
     }
     // Override static value for ignore_constants if provided in $options
     self::setIgnoreConstants($ignoreConstants);
     // Parse YAML
     $config = call_user_func($this->getYamlDecoder(), $yaml);
     // Reset original static state of ignore_constants
     self::setIgnoreConstants($staticIgnoreConstants);
     if (null === $config) {
         // decode failed
         require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Config/Exception.php';
         throw new IfwPsn_Vendor_Zend_Config_Exception("Error parsing YAML data");
     }
     if (null === $section) {
         $dataArray = array();
         foreach ($config as $sectionName => $sectionData) {
             $dataArray[$sectionName] = $this->_processExtends($config, $sectionName);
         }
         parent::__construct($dataArray, $allowModifications);
     } elseif (is_array($section)) {
         $dataArray = array();
         foreach ($section as $sectionName) {
             if (!isset($config[$sectionName])) {
                 require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Config/Exception.php';
                 throw new IfwPsn_Vendor_Zend_Config_Exception(sprintf('Section "%s" cannot be found', implode(' ', (array) $section)));
             }
             $dataArray = array_merge($this->_processExtends($config, $sectionName), $dataArray);
         }
         parent::__construct($dataArray, $allowModifications);
     } else {
         if (!isset($config[$section])) {
             require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Config/Exception.php';
             throw new IfwPsn_Vendor_Zend_Config_Exception(sprintf('Section "%s" cannot be found', implode(' ', (array) $section)));
         }
         $dataArray = $this->_processExtends($config, $section);
         if (!is_array($dataArray)) {
             // Section in the yaml data contains just one top level string
             $dataArray = array($section => $dataArray);
         }
         parent::__construct($dataArray, $allowModifications);
     }
     $this->_loadedSection = $section;
 }