/** * @return array * * @throws ParsingException */ public function parse() { try { $parser = new \Zend_Config_Yaml($this->getFile()); } catch (\Zend_Config_Exception $e) { throw new ParsingException("Cannot parse this file: " . $e->getMessage(), 0, $e); } return $parser->toArray(); }
protected function _processFile($globalFile, $localFile = null) { if (!file_exists($globalFile)) { throw new Mage_Core_Exception("Cannot find global configuration YAML file."); } // Decode the YAML File $globalClass = new Zend_Config_Yaml($globalFile, NULL, array('ignore_constants' => true)); $globalArray = $globalClass->toArray(); return $globalArray; }
protected function _processFile($globalFile, $localFile = null) { if (!file_exists($globalFile)) { $this->log("No configuration component found in: " . $globalFile); $this->log("Skipping"); throw new Mage_Core_Exception("Cannot find global configuration YAML file."); } // Decode the YAML File $globalClass = new Zend_Config_Yaml($globalFile, NULL, array('ignore_constants' => true)); $globalArray = $globalClass->toArray(); $localArray = array(); if (file_exists($localFile)) { // Decode the YAML File $localClass = new Zend_Config_Yaml($localFile, NULL, array('ignore_constants' => true)); $localArray = $localClass->toArray(); } $data = array_merge_recursive($globalArray, $localArray); return $data; }
/** * 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 * @param array|boolean $constants Local constants */ public function __construct($yaml, $section = null, $options = false) { //if ($constants) //self::setLocalConstants($constants); if (is_array($options)) { foreach ($options as $key => $value) { switch (strtolower($key)) { case 'constants': $this->setLocalConstants($value); break; default: break; } } } parent::__construct($yaml, $section, $options); }
/** * Indicate whether parser should ignore constants or not * * @param bool $flag * @return void */ public static function setIgnoreConstants($flag) { self::$_ignoreConstants = (bool) $flag; }
public function testHonorsOptionsProvidedToConstructor() { $config = new Zend_Config_Yaml($this->_iniFileAllSectionsConfig, 'debug', array('allow_modifications' => true, 'skip_extends' => true, 'yaml_decoder' => array($this, 'yamlDecoder'), 'foo' => 'bar')); $this->assertNull($config->name); // verifies extends were skipped $config->foo = 'bar'; $this->assertEquals('bar', $config->foo); // verifies allows modifications $this->assertEquals(array($this, 'yamlDecoder'), $config->getYamlDecoder()); }
/** * Check for missing files. * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content */ public function missingFiles() { $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content'); $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)->setTitle('Missing Files : ')->setMessage('Looks Great.'); $filePath = Mage::getModuleDir('etc', Dotdigitalgroup_Email_Helper_Config::MODULE_NAME) . DS . 'files.yaml'; $config = Zend_Config_Yaml::decode(file_get_contents($filePath)); /** * Code dirs. */ $etcDir = Mage::getModuleDir('etc', Dotdigitalgroup_Email_Helper_Config::MODULE_NAME); $controllerDir = Mage::getModuleDir('controllers', Dotdigitalgroup_Email_Helper_Config::MODULE_NAME); $sqlDir = Mage::getModuleDir('sql', Dotdigitalgroup_Email_Helper_Config::MODULE_NAME); $localeDir = Mage::getBaseDir('locale'); $rootDir = Mage::getModuleDir('', Dotdigitalgroup_Email_Helper_Config::MODULE_NAME); $blockDir = $rootDir . DS . 'Block'; $helperDir = $rootDir . DS . 'Helper'; $modelDir = $rootDir . DS . 'Model'; /** * Design dir. */ $designDir = Mage::getBaseDir('design'); /** * Skin dir. */ $skinDir = Mage::getBaseDir('skin'); /** * Js dir */ $jsDir = Mage::getBaseDir('base') . DS . 'js'; /** * lib dir */ $libDir = Mage::getBaseDir('lib'); $filesToCheck = array($config['etc'], $config['controllers'], $config['sql'], $config['locale'], $config['block'], $config['helper'], $config['model'], $config['design'], $config['skin'], $config['lib'], $config['js']); $pathToCheck = array($etcDir, $controllerDir, $sqlDir, $localeDir, $blockDir, $helperDir, $modelDir, $designDir, $skinDir, $libDir, $jsDir); foreach ($filesToCheck as $subdir) { foreach ($subdir as $path) { $file = $pathToCheck[0] . DS . str_replace('#', DS, $path); if (!file_exists($file)) { $resultContent->setStyle(self::CONNECTOR_DASHBOARD_FAILED)->setMessage('')->setHowto('File not found : ' . $file); } } array_shift($pathToCheck); } return $resultContent; }
public function testWriteAndReadOriginalFile() { $config = new Zend_Config_Yaml(dirname(__FILE__) . '/files/allsections.yaml', null, array('skip_extends' => true)); $writer = new Zend_Config_Writer_Yaml(array('config' => $config, 'filename' => $this->_tempName)); $writer->write(); $config = new Zend_Config_Yaml($this->_tempName, null); $this->assertEquals('multi', $config->staging->one->two->three, var_export($config->toArray(), 1)); $config = new Zend_Config_Yaml($this->_tempName, null, array('skip_extends' => true)); $this->assertFalse(isset($config->staging->one)); }