public function __construct() { global $config; $filename = $config['sq_config_path'] . $config['sq_playback_file']; try { if (!is_readable($filename)) { throw new Exception('File not found'); } $luaconf = file_get_contents($filename); //Clean file $luaconf = str_replace(array("\r\n", "\n", "\r"), "", $luaconf); //reformat lua config with newlines $luaconf = str_replace(array("{", ","), array("{\n", ",\n"), $luaconf); $parser = new ConfigParser($luaconf); $c = $parser->toArray(); $this->playerName = $c['settings']['playerInit']['name']; $this->serverInfos['uuid'] = $c['settings']['serverUuid']; if (array_key_exists('mac', $c['settings']['serverInit'])) { $this->serverInfos['mac'] = $c['settings']['serverInit']['mac']; } $this->serverInfos['ip'] = $c['settings']['serverInit']['ip']; $this->serverInfos['name'] = $c['settings']['serverName']; } catch (Exception $e) { //Can't parse lua config, reset it @unlink($filename); $this->serverInfos['uuid'] = "Unknown"; $this->serverInfos['ip'] = "None"; $this->serverInfos['name'] = "None"; } //Write setupdone into lua config to tell squeezeplay setup is done and don't bother with that $filename = $config['sq_config_path'] . $config['sq_welcome_file']; $fp = fopen($filename, 'w'); fwrite($fp, 'settings = {setupDone=true,}'); fclose($fp); }
/** * @depends testInstancesCreation */ public function testConfigParser() { $configParser = new ConfigParser(); $config = $configParser->parse('200x300'); $this->assertInstanceOf('happyproff\\Kartinki\\Config', $config); $this->assertEquals(200, $config->getWidth()); $this->assertEquals(300, $config->getHeight()); $this->assertEquals(false, $config->isFit()); $config = $configParser->parse('0x1920:fit'); $this->assertInstanceOf('happyproff\\Kartinki\\Config', $config); $this->assertEquals(0, $config->getWidth()); $this->assertEquals(1920, $config->getHeight()); $this->assertEquals(true, $config->isFit()); $config = $configParser->parse('200x0,quality=60'); $this->assertInstanceOf('happyproff\\Kartinki\\Config', $config); $this->assertEquals(200, $config->getWidth()); $this->assertEquals(0, $config->getHeight()); $this->assertEquals(false, $config->isFit()); $this->assertEquals(60, $config->getQuality()); $config = $configParser->parse('300x250:fit,quality=99'); $this->assertInstanceOf('happyproff\\Kartinki\\Config', $config); $this->assertEquals(300, $config->getWidth()); $this->assertEquals(250, $config->getHeight()); $this->assertEquals(true, $config->isFit()); $this->assertEquals(99, $config->getQuality()); $config = $configParser->parse('300x250,quality=10,quality=20'); $this->assertInstanceOf('happyproff\\Kartinki\\Config', $config); $this->assertEquals(300, $config->getWidth()); $this->assertEquals(250, $config->getHeight()); $this->assertEquals(false, $config->isFit()); $this->assertEquals(20, $config->getQuality()); $config = null; try { $config = $configParser->parse(''); } catch (\Exception $e) { $this->assertInstanceOf('happyproff\\Kartinki\\Exceptions\\InvalidConfigException', $e); } $this->assertEquals(null, $config); try { $config = $configParser->parse('wrong'); } catch (\Exception $e) { $this->assertInstanceOf('happyproff\\Kartinki\\Exceptions\\InvalidConfigException', $e); } $this->assertEquals(null, $config); try { $config = $configParser->parse('200x300:fit,rotate'); } catch (\Exception $e) { $this->assertInstanceOf('happyproff\\Kartinki\\Exceptions\\InvalidConfigException', $e); } $this->assertEquals(null, $config); try { $config = $configParser->parse('200x300:fit,quality'); } catch (\Exception $e) { $this->assertInstanceOf('happyproff\\Kartinki\\Exceptions\\InvalidConfigException', $e); } $this->assertEquals(null, $config); }
/** * Load configuration data from a file. * The file is assumed to be formatted in php.ini style. * @return array the configuration data */ function &reloadData() { if (($configData =& ConfigParser::readConfig(Config::getConfigFileName())) === false) { fatalError(sprintf('Cannot read configuration file %s', Config::getConfigFileName())); } return $configData; }
function __construct($path) { $this->path = $path; $this->addValueParser(function ($value) { return ConfigParser::valueParserDBConn($value); }); }
/** * Load configuration data from a file. * The file is assumed to be formatted in php.ini style. * @return array the configuration data */ function &reloadData() { if (($configData =& ConfigParser::readConfig(CONFIG_FILE)) === false) { fatalError(sprintf('Cannot read configuration file %s', CONFIG_FILE)); } return $configData; }
/** * Create and test connection and existence of destination table (but not it structure) * * @param String $dest table name in MySQL db * @param \SULB_OAS\ConfigParser $config Configuration * @return boolean true * @throws Exception if connection error * @throws Exception if table does not exist */ public static function connect($dest, ConfigParser $config) { self::$connection = new \mysqli($config->getDbHost(), $config->getDbUser(), $config->getDbPassword(), $config->getDbName(), $config->getDbPort(), $config->getDbSocket()); if (self::$connection->connect_error) { throw new Exception('Connect Error (' . self::$connection->connect_errno . ') ' . self::$connection->connect_error); } self::$destination = $dest; if ($res = self::$connection->query('show tables like ' . self::$destination) && $res->num_rows != 1) { throw new Exception('Table ' . self::$destination . ' is missing in DB ' . $config->getDbName()); } return true; }
/** * Loads information from a config file * * $config_name maps to TO_ROOT/configs/models/{class_name}_{config_name}.ini by default * * @param string $config_name * @param boolean $use_class_name selects if the class_name prefix should be added. */ public function loadConfig($config_name = 'default', $use_class_name = true, $vars = array()) { $DbConnection = DbConnection::getInstance(); if ($use_class_name) { $prefix = strtolower(get_class($this->_Row)); $file_name = TO_ROOT . "/configs/models/{$prefix}_{$config_name}.yaml"; } else { $file_name = TO_ROOT . "/configs/models/{$config_name}.yaml"; } if (!file_exists($file_name)) { Logger::log("Couldn't find config file", $file_name, LOGGER_ERROR); return false; } $config = @ConfigParser::parsea_mesta($file_name, $vars); //echo "<pre>Processed:\n".print_r($config,1)."</pre>"; if (isset($config['__general']['form_id'])) { $this->setFormId($config['__general']['form_id']); } if (isset($config['__general']['action'])) { $this->setAction($config['__general']['action']); } if (isset($config['__general']['type'])) { $this->setType($config['__general']['type']); } if (isset($config['__general']['method'])) { $this->setMethod($config['__general']['method']); } unset($config['__general']); if (isset($config['__pattern']['add'])) { if ($this->_Row->getId() == 0) { foreach ($config['__pattern']['add'] as $field => $value) { $this->setPatternVariable($field, $value); } } } if (isset($config['__pattern']['edit'])) { if ($this->_Row->getId() != 0) { foreach ($config['__pattern']['edit'] as $field => $value) { $this->setPatternVariable($field, $value); } } } unset($config['__pattern']); $commands = $config['__commands']; unset($config['__commands']); if (isset($config['__generalAction'])) { $new = $this->_Row->getId() == 0 ? true : false; foreach ($config['__generalAction'] as $action => $properties) { $appears_in = isset($properties['appears_in']) ? $properties['appears_in'] : 'both'; if ($appears_in == 'both' || $new && $appears_in == 'add' || !$new && $appears_in == 'edit') { $this->AddGeneralAction($action, $properties['action'], $properties['title'], $properties['icon'], $properties['ajax']); } } } unset($config['__generalAction']); foreach ($config as $field => $properties) { if (strpos($field, ':') !== false) { list($field, $action) = explode(':', $field); if ($action == 'parameters') { foreach ($properties as $parameter => $value) { $this->setFieldParameter($field, $parameter, $value); } } else { if ($action == 'input_parameters') { foreach ($properties as $parameter => $value) { $this->setFieldInputParameter($field, $parameter, $value); } } else { if ($action == 'action') { $this->addAction($field, $properties['action'], $properties['title'], $properties['icon'], $properties['ajax']); } else { if ($action == 'splitter') { $id = empty($properties['id']) ? $field : $properties['id']; $position = empty($properties['position']) ? 'before' : $properties['position']; $this->insertSplitter($field, $properties['content'], $position, $id); } else { if ($action == 'linked') { $this->setAsLinked($field, $properties['table_name'], $DbConnection, $properties['table_id'], $properties['name_field'], $properties['condition']); } else { if ($action == 'dependent') { $this->setFieldDependents($field, $properties['condition'], $properties['value'], $properties['dependants']); } else { if ($action == 'add') { $data = array('label' => ucwords(str_replace('_', ' ', $field)), 'type' => 'text', 'input_parameters' => array('maxlength' => 45)); $this->insertField($field, $data, $properties['target'], $properties['position']); } else { if ($action == 'move') { $this->moveField($field, $properties['position'], $properties['target']); } } } } } } } } } else { if (is_array($properties)) { foreach ($properties as $property => $value) { $this->setFieldProperty($field, $property, $value); } } } } if (isset($commands['delete'])) { foreach ($commands['delete'] as $delete) { $this->deleteField($delete); } } if (isset($commands['hide'])) { foreach ($commands['hide'] as $hide) { $this->hideField($hide); } } if (isset($commands['disable'])) { foreach ($commands['disable'] as $disable) { $this->disableField($disable); } } return true; }
} return $result; } /** * current ini line * @param $line */ private function createDetermArray($line) { if (!empty($line)) { $values = explode('=', $line); $key = trim($values[0]); $value = trim($values[1]); $this->determArray[$key] = $value; } } /** * @usage simple file parsing */ public function parseToArray() { $f = fopen($this->fileName, "r"); while (!feof($f)) { $this->createDetermArray(fgets($f)); } fclose($f); } } $tt = new ConfigParser('pars_task.ini'); print_r($tt->getResultArray()); //print_r($tt->getDetermArray());
# We use ON/OFF for bools which map to numeric. $t_type = CONFIG_TYPE_COMPLEX; } } } } else { $t_type = $f_type; } # Parse the value # - Strings are returned as-is # - Empty values are typecast as appropriate $t_value = $f_value; if ($t_type != CONFIG_TYPE_STRING) { try { if (!empty($f_value)) { $t_parser = new ConfigParser($f_value); $t_value = $t_parser->parse(ConfigParser::EXTRA_TOKENS_IGNORE); } switch ($t_type) { case CONFIG_TYPE_INT: $t_value = (int) $t_value; break; case CONFIG_TYPE_FLOAT: $t_value = (double) $t_value; break; } } catch (Exception $e) { error_parameters($f_config_option, $e->getMessage()); trigger_error(ERROR_CONFIG_OPT_BAD_SYNTAX, ERROR); } }
/** * Save modified system configuration settings. */ function saveSystemConfig() { $this->validate(); $this->setupTemplate(true); $configData =& Config::getData(); // Update configuration based on user-supplied data foreach ($configData as $sectionName => $sectionData) { $newData = Request::getUserVar($sectionName); foreach ($sectionData as $settingName => $settingValue) { if (isset($newData[$settingName])) { $newValue = $newData[$settingName]; if (strtolower($newValue) == "true" || strtolower($newValue) == "on") { $newValue = "On"; } else { if (strtolower($newValue) == "false" || strtolower($newValue) == "off") { $newValue = "Off"; } } $configData[$sectionName][$settingName] = $newValue; } } } $templateMgr =& TemplateManager::getManager(); // Update contents of configuration file $configParser = new ConfigParser(); if (!$configParser->updateConfig(Config::getConfigFileName(), $configData)) { // Error reading config file (this should never happen) $templateMgr->assign('errorMsg', 'admin.systemConfigFileReadError'); $templateMgr->assign('backLink', Request::url(null, null, null, null, 'systemInfo')); $templateMgr->assign('backLinkLabel', 'admin.systemInformation'); $templateMgr->display('common/error.tpl'); } else { $writeConfigFailed = false; $displayConfigContents = Request::getUserVar('display') == null ? false : true; $configFileContents = $configParser->getFileContents(); if (!$displayConfigContents) { if (!$configParser->writeConfig(Config::getConfigFileName())) { $writeConfigFailed = true; } } // Display confirmation $templateMgr->assign('writeConfigFailed', $writeConfigFailed); $templateMgr->assign('displayConfigContents', $displayConfigContents); $templateMgr->assign('configFileContents', $configFileContents); $templateMgr->assign('helpTopicId', 'site.administrativeFunctions'); $templateMgr->display('admin/systemConfigUpdated.tpl'); } }
/** * Update the specified configuration parameters. * @param $configParams arrays * @return boolean */ function updateConfig($configParams) { // Update config file $configParser = new ConfigParser(); if (!$configParser->updateConfig(Config::getConfigFileName(), $configParams)) { // Error reading config file $this->setError(INSTALLER_ERROR_GENERAL, 'installer.configFileError'); return false; } $this->configContents = $configParser->getFileContents(); if (!$configParser->writeConfig(Config::getConfigFileName())) { $this->wroteConfig = false; } return true; }
/** * Loads information from a config file * * $config_name maps to TO_ROOT/configs/models/{class_name}_{config_name}.ini by default * * @param string $config_name * @param boolean $use_class_name selects if the class_name prefix should be added. */ public function loadConfig($config_name = 'default', $vars = array()) { $DbConnection = DbConnection::getInstance(); $file_name = TO_ROOT . "/configs/models/{$config_name}_list.yaml"; if (!file_exists($file_name)) { Logger::log("Couldn't find config file", $file_name, LOGGER_ERROR); return false; } $config = ConfigParser::parsea_mesta($file_name, $vars); if (isset($config['__general']['page_name'])) { $this->setPageName($config['__general']['page_name']); } unset($config['__general']); if (isset($config['__row_id'])) { $this->setRowId($config['__row_id']['prefix'], $config['__row_id']['field']); } unset($config['__row_id']); if (isset($config['__links'])) { foreach ($config['__links'] as $field => $properties) { $this->addLink($field, $properties['value'], $properties['action'], $properties['title']); } } unset($config['__links']); if (isset($config['__filters'])) { foreach ($config['__filters'] as $field => $properties) { if ($properties['delete'] != true) { if ($properties['type'] == 'hidden') { $this->addHiddenFilter($field, $properties['value'], $properties['condition']); } else { if (isset($properties['prefix'])) { $this->addFilter($field, $properties['label'], $properties['type'], array('prefix' => $properties['prefix'])); } else { $this->addFilter($field, $properties['label'], $properties['type']); } if ($properties['add_all']) { $this->addFilterOption($field, 'all', 'All', false, '1'); } if (isset($properties['default'])) { $this->setFilterDefault($field, $properties['default']); } if ($properties['type'] == 'active' && $properties['type'] == 'yes_no') { } else { if ($properties['type'] == 'custom') { if (isset($properties['options_query'])) { $DbConnection == DbConnection::getInstance(); $options = $DbConnection->getArrayPair($properties['options_query']); $this->addFilterOptions($field, $options, $properties['condition']); } else { if (isset($properties['options'])) { $this->addFilterOptions($field, $properties['options'], $properties['condition']); } } } } } } } } unset($config['__filters']); if (isset($config['__commands']['order_by'])) { $this->orderBy($config['__commands']['order_by']); } if (isset($config['__query']['sql'])) { $paginate = isset($config['__query']['paginate']) ? $config['__query']['paginate'] : false; $this->setQuery($config['__query']['sql'], DbConnection::getInstance(), $paginate); } unset($config['__query']); if (isset($config['__pattern'])) { foreach ($config['__pattern'] as $field => $value) { $this->setPatternVariable($field, $value); } } unset($config['__pattern']); if (isset($config['__commands']['hide'])) { foreach ($config['__commands']['hide'] as $hide) { $this->hideField($hide); } } unset($config['__commands']); if (isset($config['__generalAction'])) { foreach ($config['__generalAction'] as $properties) { $this->AddGeneralAction($properties['action'], $properties['title'], $properties['icon'], $properties['ajax'], $properties['show_in'], $properties['keybinding']); } } unset($config['__generalAction']); if (isset($config['__action'])) { foreach ($config['__action'] as $properties) { $this->addAction($properties['value'], $properties['action'], $properties['title'], $properties['icon'], $properties['ajax']); } } unset($config['__action']); foreach ($config as $field => $properties) { if (is_array($properties)) { foreach ($properties as $property => $value) { if ($property == 'format') { $this->setFormat($field, $value); } else { if ($property == 'name') { $this->setName($field, $value); } else { if ($property == 'class') { $this->setClass($field, $value); } } } } } } return true; }
private function __construct($sConfig = null) { $cp = new ConfigParser($sConfig); $this->aConfig = $cp->parse(); }
public function getProductsFileUri($products_id, $purpose) { $where = array('product_id' => $products_id, 'purpose' => $purpose); $column = array('product_id', 'filename'); $result = $this->product_file_db->selectRows($where, $column); $static_server_uri = ConfigParser::get('system', 'static_server_uri'); foreach ($result as $row) { $data[$row['product_id']] = $static_server_uri . $row['filename']; } return $data; }
<?php include "ConfigParser.php"; $StrConfigName = 'test'; $StrConfigValue = \ConfigParser::ParseConfig($StrConfigName); echo $StrConfigValue;
private function mockGetFolderConfigWithBrokenSetup($folder, $configName, $config, $configItems, $level, $exception) { $this->configParser->expects($this->any())->method('getFolderConfig')->with($folder, $configName, $config, $configItems, $level)->willThrowException($exception); }
/** * Parse a YAML or INI file * * Performs variable replacing in the string taking them from the * $vars parameter and replacing in the strings where {key_name} is found. * @param string $file File to be parsed * @param array $vars Prefilled variables */ public static function parsea_mesta($file, $vars = array()) { $extension = pathinfo($file, PATHINFO_EXTENSION); if (!is_array($vars)) { throw new InvalidArgumentException("Function expected Array " . gettype($vars) . " received instead"); } self::$__vars = $vars; switch ($extension) { case 'yaml': self::parse_yaml_adv($file); $a =& self::$__vars; break; case 'ini': default: $a = self::parse_ini_adv($file); break; } $m = count($a); if (!$a || !is_array($a) || $m == 0) { return false; } foreach ($a as $key => &$value) { if (!is_array($value) && (is_string($value) || is_integer($value))) { self::$__stringvars[$key] = $value; self::$__keys[] = "{" . $key . "}"; } } switch ($extension) { case 'yaml': array_walk_recursive(self::$__vars, 'ConfigParser::remplaza_mesta'); array_walk(self::$__vars, "ConfigParser::reduce_mesta"); $vars = self::$__vars; self::$__imports = array(); self::$__vars = array(); self::$__keys = array(); self::$__stringvars = array(); return self::limpia_mesta($vars); case 'ini': array_walk_recursive($a, 'ConfigParser::remplaza_mesta'); /*self::$__imports = array(); self::$__vars = array(); self::$__keys = array(); self::$__stringvars = array();*/ return self::limpia_mesta($a); } }
<?php namespace ConfigParser; include 'ConfigParser.php'; /** * pars_task.ini This configuration file */ $tt = new ConfigParser('pars_task.ini'); $resultArray = $tt->getResultArray(); /** * Parsed array| */ print_r($resultArray);
} } private function optionsMenu() { print "Press 1: Convert To: can be csv,xml,json\nPress 2:OutputFile: path to output file\nPress 3: Input file format: Can be csv, xml, js\nPress 4 : path to Input file\nType convert: To convert.. "; } } spl_autoload_register(function ($i) { require_once $i . ".php"; }, true); if (PHP_SAPI) { if (count($argv) < 2) { print "Usage : php Parser.php inputFile {ConvertTO:[xml|json|csv]} {InputFileFormat:[csv|js|xml]} {OutputFile:outfile}\nAny option inside {} this is optional.\nOption can be any order except first one has to be input file.\nkey : value this is how the options should be provided without curly braces. \nFirst is the key and second is the value.\nEnetring command line mode now!!"; $p = new Parser(); $p->interactivemode = true; $p->startIntercativeMode(); exit; } $ifile = $argv[1]; if (file_exists($ifile)) { array_splice($argv, 0, 2); $p = new Parser(); $p->setInputFileAndParseIT($ifile); $p->createConfig(ConfigParser::parseConfigArray($argv)); $p->parserHandler(); } else { print "Input file {$ifile} doesn't exists."; } } else { print "Only command line access is allowed."; }