function entry(&$argv) { if (is_file($argv[0])) { if (0 === substr_compare($argv[0], '.class.php', -10)) { $uri = realpath($argv[0]); if (null === ($cl = \lang\ClassLoader::getDefault()->findUri($uri))) { throw new \Exception('Cannot load ' . $uri . ' - not in class path'); } return $cl->loadUri($uri)->literal(); } else { if (0 === substr_compare($argv[0], '.xar', -4)) { $cl = \lang\ClassLoader::registerPath($argv[0]); if (!$cl->providesResource('META-INF/manifest.ini')) { throw new \Exception($cl->toString() . ' does not provide a manifest'); } $manifest = parse_ini_string($cl->getResource('META-INF/manifest.ini')); return strtr($manifest['main-class'], '.', '\\'); } else { array_unshift($argv, 'eval'); return 'xp\\runtime\\Evaluate'; } } } else { return strtr($argv[0], '.', '\\'); } }
public function parse($ini, $file = false, $return = false) { // if $ini is a file.. if ($file) { // preserve the original $ini var for later $path = $ini; // check if $ini param contains the relative/absolute // path to the config file by seeing if it exists if (!file_exists($path)) { // if it doesn't prepend the default config path $path = $this->path . $path; // make sure the config file now exists if (!file_exists($path)) { // if not throw a Config exception throw new ConfigException('Config file doesn\'t exist: ' . $ini); } } } // if $file is true we need to parse $ini as $parsed = $file ? parse_ini_file($ini, true) : parse_ini_string($ini, true); // if the return param is set we want to return the parsed // INI file instead of adding to the properties array if ($return) { return $parsed; } // loop through the parsed array and add // each section to the properties array foreach ($parsed as $section => $properties) { $this->properties[$section] = $properties; } }
/** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ protected function setUp() { $iniFilename = 'rposwwebclient_test.ini'; $iniContent = file_get_contents($iniFilename, FILE_USE_INCLUDE_PATH); if (false === $iniContent) { throw new \Exception("Loading .ini file '{$iniFilename}' failed."); } // Parse ini content $this->ini = parse_ini_string($iniContent, true); if (false === $this->ini) { throw new \Exception('Parsing .ini file failed.'); } $this->aliceJID = "testalice@{$this->ini['testosw']['server']}"; $this->julietJID = "testjuliet@{$this->ini['testosw']['server']}"; $this->romeoJID = "testromeo@{$this->ini['testosw']['server']}"; $this->xmpp = new XMPP(); $this->xmpp->connect($this->ini['testosw']['server'], $this->ini['testosw']['port']); $this->xmpp->login($this->ini['testosw']['adminname'], $this->ini['testosw']['adminpassword'], $this->ini['testosw']['resource']); $this->xmpp->addUser("testalice@{$this->ini['testosw']['server']}", 'secretAlice'); $this->xmpp->addUser("testjuliet@{$this->ini['testosw']['server']}", 'secretJuliet'); $this->xmpp->addUser("testromeo@{$this->ini['testosw']['server']}", 'secretRomeo'); $this->xmpp->disconnect(); $this->juliet = new XMPP(); $this->juliet->connect($this->ini['testosw']['server'], $this->ini['testosw']['port']); $this->juliet->login('testjuliet', 'secretJuliet', $this->ini['testosw']['resource']); $this->romeo = new XMPP(); $this->romeo->connect($this->ini['testosw']['server'], $this->ini['testosw']['port']); $this->romeo->login('testromeo', 'secretRomeo', $this->ini['testosw']['resource']); $this->alice = new XMPP(); $this->alice->connect($this->ini['testosw']['server'], $this->ini['testosw']['port']); $this->alice->login('testalice', 'secretAlice', $this->ini['testosw']['resource']); }
/** * Use this to pass a bunch of data at once to the object * * @param $data , can be an array or a file of the types yaml, json or ini, PHP will be executed! * @param bool $override , by default all existing data are replaced */ public static function init($data, $override = true) { $settingsObj = self::getInstance(); if (is_string($data)) { ob_start(); include $data; switch (FsUtils::getFileExtension($data)) { case 'yaml': case 'yml': $data = Yaml::parse(ob_get_clean()); break; case 'json': $data = json_decode(ob_get_clean(), 1); break; case 'ini': $data = parse_ini_string(ob_get_clean()); break; } } if ($override) { $settingsObj->data = $data; } else { $settingsObj->data = ArrayUtils::arrayMergeRecursiveDistinct($settingsObj->data, $data); } }
public function checkUpdate() { $this->log('检查更新. . .'); $updateFile = $this->updateUrl . '/update.ini'; $update = @file_get_contents($updateFile); if ($update === false) { $this->log('无法获取更新文件 `' . $updateFile . '`!'); return false; } else { $versions = parse_ini_string($update, true); if (is_array($versions)) { $keyOld = 0; $latest = 0; $update = ''; foreach ($versions as $key => $version) { if ($key > $keyOld) { $keyOld = $key; $latest = $version['version']; $update = $version['url']; } } $this->log('发现新版本 `' . $latest . '`.'); $this->latestVersion = $keyOld; $this->latestVersionName = $latest; $this->latestUpdate = $update; return $keyOld; } else { $this->log('无法解压更新文件!'); return false; } } }
public function lang($file = 'lang.ini') { // check language default $file_lang = dirname(ROOT) . DS . 'data' . DS . 'languages.json'; if (file_exists($file_lang)) { $languages = json_decode(file_get_contents($file_lang)); if (count($languages)) { foreach ($languages as $language) { if (isset($language->default) && $language->default == 1) { if (file_exists(ROOT . DS . 'data' . DS . $language->file)) { $file = $language->file; } } } } } $file = ROOT . DS . 'data' . DS . $file; if (file_exists($file)) { $data = parse_ini_file($file); if ($data === false || $data == null) { $content = file_get_contents($file); $data = parse_ini_string($content); } return $data; } else { return false; } }
public function get_real_value($key) { $lang_format = $this->get_dir_format(); foreach ($this->_lang_order as $lang_key) { // Se não for definido o idioma, cria a variável if (!isset($this->_lang_dir[$lang_key])) { $this->_lang_dir[$lang_key] = null; } // Se for false, ignora rapidamente if ($this->_lang_dir[$lang_key] === false) { continue; } // Gera o diretório de busca $lang_path = sprintf($lang_format, $lang_key); // Se o diretório não existir, avança if (!is_file($lang_path)) { $this->_lang_dir[$lang_key] = false; continue; } // Se o arquivo não estiver sido carregado, o faz if ($this->_lang_dir[$lang_key] === null) { $this->_lang_dir[$lang_key] = parse_ini_string(utf8_decode(file_get_contents($lang_path)), false); } // Se a chave não existir, avança if (!isset($this->_lang_dir[$lang_key][$key])) { continue; } // Por fim, retorna a informação desejada return $this->_lang_dir[$lang_key][$key]; } // Em último caso, retorna null return null; }
/** * Parse a Jin string * * @acces public * @param string $jin_string The Jin string to parse * @param boolean $assoc Whether JSON objects should be associative arrays * @return array The parsed Jin string as an associative array */ public function parse($jin_string, $assoc = FALSE) { $collection = clone $this->collection; $jin_string = $this->removeWhitespace($jin_string); $jin_string = $this->removeNewLines($jin_string); $jin_string = trim($jin_string); foreach (parse_ini_string($jin_string, TRUE, INI_SCANNER_RAW) as $index => $values) { foreach ($values as $key => $value) { $leadch = strtolower($value[0]); $length = strlen($value); if (in_array($leadch, ['n', 't', 'f']) && in_array($length, [4, 5])) { if (strtolower($value) == 'null') { $values[$key] = NULL; } elseif (strtolower($value) == 'true') { $values[$key] = TRUE; } elseif (strtolower($value) == 'false') { $values[$key] = FALSE; } continue; } elseif (in_array($leadch, ['{', '['])) { $values[$key] = json_decode($value, $assoc); } elseif (is_numeric($value)) { $values[$key] = json_decode($value); } if ($values[$key] === NULL) { throw new Flourish\ProgrammerException('Error parsing JSON data: %s', $value); } } $collection->set($index, $values); } return $collection; }
public function testParseIniStringEmptySuccess() { $array = parse_ini_string('', true); $this->assertEquals(array(), $array, "Empty string should parse to empty array"); $array = parse_ini_string('foobar', true); $this->assertEquals(array(), $array, "Empty string should parse non ini string to array"); }
/** * extractDsn * * @param string $dsn * * @return array */ public static function extractDsn($dsn) { // Parse DSN to array $dsn = str_replace(';', "\n", $dsn); $dsn = parse_ini_string($dsn); return $dsn; }
/** * Job * * This function is called by the Autorun script. */ public function job() { $latest_version = parse_ini_string($this->CI->bw_curl->get_request('https://raw.github.com/Bit-Wasp/BitWasp/master/version.ini')); // Check the recent commits for an alert message $alert = $this->check_alerts(); if ($alert !== FALSE) { $this->CI->load->model('alerts_model'); // If the site has never seen this alert before, proceed: if ($this->CI->alerts_model->check($alert['message']) == FALSE) { // Log a message for the admin $log_message = "A serious alert has been trigged by the Bitwasp developers on " . $alert['date'] . ":<br />" . $alert['message'] . "<br />"; $this->CI->logs_model->add('BitWasp Developers', 'Please respond to serious alert', $log_message, 'Alert'); unset($alert['date']); // Record the alert. $this->CI->alerts_model->add($alert); // If the site is not in maintenance mode, put it there now. if ($this->CI->bw_config->maintenance_mode == FALSE) { $this->CI->load->model('admin_model'); $this->CI->admin_model->set_mode('maintenance'); } } } if ($latest_version !== FALSE && BITWASP_CREATED_TIME !== FALSE) { if ($latest_version['bitwasp_created_time'] > BITWASP_CREATED_TIME) { $this->CI->load->model('logs_model'); if ($this->CI->logs_model->add('Version Checker', 'New BitWasp code available', 'There is a new version of BitWasp available on GitHub. It is recommended that you download this new version (using ' . BITWASP_CREATED_TIME . ')', 'Info')) { return TRUE; } } } return TRUE; }
function main() { $path = __DIR__ . '/bad_ini_quotes.ini'; $x = file_get_contents($path); $y = parse_ini_string($x, true); var_dump($y); }
function get_fpm_memory_limit($fpmconf, $startsection = "global") { if (!is_readable($fpmconf)) { return array(); } $fpm = parse_ini_string("[{$startsection}]\n" . file_get_contents($fpmconf), true); // prepend section from parent so stuff is parsed correctly in includes that lack a leading section marker $retval = array(); foreach ($fpm as $section => $directives) { foreach ($directives as $key => $value) { if ($section == "www" && $key == "php_admin_value" && isset($value['memory_limit'])) { $retval['php_admin_value'] = $value['memory_limit']; } elseif ($section == "www" && $key == "php_value" && isset($value['memory_limit']) && !isset($retval['php_value'])) { // an existing value takes precedence // we can only emulate that for includes; within the same file, the INI parser overwrites earlier values :( $retval['php_value'] = $value['memory_limit']; } elseif ($key == "include") { // values from the include don't overwrite existing values $retval = array_merge(get_fpm_memory_limit($value, $section), $retval); } if (isset($retval['php_admin_value'])) { // done for good as nothing can change this anymore, bubble upwards return $retval; } } } return $retval; }
/** * Get the node settings from this form * @param boolean $updateValues set to true to get the submitted node settings, false to get the initial node settings * @return joppa\model\NodeSettings * @throws zibo\ZiboException when the form is not submitted and $updateValues is set to true * @throws zibo\library\validation\exception\ValidationException when the submitted settings are not valid and $updateValues is set to true */ public function getNodeSettings($updateValues = true) { if (!$updateValues) { return $this->nodeSettings; } if (!$this->isSubmitted()) { throw new ZiboException('Form not submitted'); } $settings = @parse_ini_string($this->getValue(self::FIELD_SETTINGS)); if ($settings === false) { $error = error_get_last(); $error = new ValidationError('error', '%error%', array('error' => $error['message'])); $exception = new ValidationException(); $exception->addErrors(self::FIELD_SETTINGS, array($error)); throw $exception; } $nodeSettings = new NodeSettings($this->nodeSettings->getNode(), $this->nodeSettings->getInheritedNodeSettings()); // set the values from the form $inheritPrefixLength = strlen(NodeSettings::INHERIT_PREFIX); foreach ($settings as $key => $value) { $inherit = false; if (strlen($key) > $inheritPrefixLength && strncmp($key, NodeSettings::INHERIT_PREFIX, $inheritPrefixLength) == 0) { $key = substr($key, $inheritPrefixLength); $inherit = true; } $nodeSettings->set($key, $value, $inherit); } return $nodeSettings; }
function update($new_instance, $old_instance) { $current_language = strtolower(get_bloginfo('language')); // network lang parameter only accept 2 letters language code (pt, es, en) $lng = substr($current_language, 0, 2); $instance = $old_instance; $instance['cluster'] = strip_tags($new_instance['cluster']); $instance['title'] = strip_tags($new_instance['title']); $instance['url'] = strip_tags($new_instance['url']); $instance['results'] = strip_tags($new_instance['results']); if (!empty($instance['url']) and strpos($instance['url'], '?') === false) { $instance['url'] = $instance['url'] . "?"; } $this->url = $instance['url']; $url_dia_ws = file_get_contents($instance['url'] . "&debug=true"); $url_dia_ws = explode("<br/><!DOCTYPE", $url_dia_ws); $url_dia_ws = $url_dia_ws[0]; $url_dia_ws = str_replace('<b>request:</b> ', '', $url_dia_ws); $url_dia_ws = trim($url_dia_ws); $instance['url_dia_ws'] = $url_dia_ws; $url = $instance['url_dia_ws']; $data = json_decode(file_get_contents($url), true); $instance['clusters'] = $data['diaServerResponse'][0]['facet_counts']['facet_fields']; $language_url = explode("/", $instance['url']); $language_url = str_replace(end($language_url), '', $instance['url']); $language_url .= "/locale/{$lng}/texts.ini"; $instance['language_url'] = $language_url; $instance['language_content'] = file_get_contents($instance['language_url']); $instance['language_content'] = parse_ini_string($instance['language_content'], true); return $instance; }
/** * @param string $filename * @return ManialiveConfig * @throws \InvalidArgumentException */ function get($filename) { if (!file_exists($this->directory . $filename . '.ini')) { throw new \InvalidArgumentException('File does not exists'); } $config = new ManialiveConfig(); $content = file_get_contents($this->directory . $filename . '.ini'); $content = preg_replace('/^\\s*\\[.+/msu', '', $content); $content = preg_replace('/^\\s*;.*$\\n?/mu', '', $content); $content = preg_replace('/;.+$/mu', '', $content); $content = preg_replace('/^$\\n/mu', '', $content); $assoc = parse_ini_string($content, true); foreach ($assoc as $key => $value) { $property = explode('.', $key, 2); if (count($property) < 2) { continue; } if ($property[0] == 'manialive') { if (isset($config->{$property[1]})) { $config->{$property[1]} = $value; } } elseif (isset($config->{$property[0]}) && isset($config->{$property[0]}->{$property[1]})) { $config->{$property[0]}->{$property[1]} = $value; } } $config->__other = preg_replace('/^\\s*(?:config|server|manialive|database|threading|wsapi)\\..+$\\n?/mu', '', $content); return $config; }
public static function deserialize($string) { $result = array(); try { $ini = parse_ini_string($string . "\n", true, INI_SCANNER_RAW); } catch (\Exception $e) { throw new TreeSerializerSyntaxException(sprintf('Unable to parse INI string (json: %s): %s.', json_encode($string), $e->getMessage())); } if ($ini === false || empty($ini) && strlen(trim($string)) > 0) { throw new TreeSerializerSyntaxException(sprintf('Unable to parse INI string (json: %s).', json_encode($string))); } foreach ($ini as $key => $value) { if (is_array($value)) { $namespace = explode(':', $key); $resultPtr =& $result; foreach ($namespace as $namespaceLevel) { if (!isset($resultPtr[$namespaceLevel])) { $resultPtr[$namespaceLevel] = array(); } $resultPtr =& $resultPtr[$namespaceLevel]; } if (!is_array($resultPtr)) { throw new TreeSerializerSyntaxException(sprintf('Namespace [%s] overlaps with value.', $key)); } foreach ($value as $nsKey => $nsValue) { $resultPtr[$nsKey] = $nsValue; } unset($resultPtr); continue; } $result[$key] = $value; } return $result; }
/** * Constructor */ public function __construct() { $this->setDefaultSettings(); if (file_exists($this->getIniFilePath())) { $this->settings = array_merge($this->settings, parse_ini_string($this->getApcCacheableIniFileContent())); } }
public function read($path, $options = 0) { try { $contents = $this->filesystem->read($path); } catch (FileNotFoundException $e) { throw new FileNotFound($path); } $fileType = $this->guessFileType($path, $contents); switch ($fileType) { case self::TYPE_INI: $withSections = $options === PhConf::INI_WITH_SECTIONS; $result = parse_ini_string($contents, $withSections); if ($result === false) { throw new ParseError("Error parsing {$path} as INI"); } return $result; case self::TYPE_JSON: $result = json_decode($contents, true); if ($result === null && json_last_error() !== JSON_ERROR_NONE) { throw new ParseError("Error parsing {$path} as JSON: " . json_last_error_msg()); } return $result ?: []; case self::TYPE_YML: try { return Yaml::parse($contents, true); } catch (ParseException $e) { throw new ParseError("Error parsing {$path} as YAML: " . $e->getMessage()); } } }
/** * parses an ini-style string into an array * * when entering data into ini-style input fields, make sure, that you comply with the following * rules (read up on http://php.net/parse_ini_string): * * There are reserved words which must not be used as keys for ini files. These include: * * `null`, `yes`, `no`, `true`, `false`, `on`, `off` and `none` * * Values `null`, `no` and `false` results in "", `yes` and `true` results in "1". * Characters ?{}|&~![()^" must not be used anywhere in the key and have a special meaning * in the value. So better not use them. * * @see http://php.net/parse_ini_string * @see lithium\util\Set::expand() * @param string|array $data the string to be parsed, or an array thereof * @param array $options an array of options currently supported are * - `default` : what to return, if nothing is found, defaults to an empty array * - `process_sections` : to enable process_sections, defaults to true * - `scanner_mode` : set scanner_mode to something different than INI_SCANNER_NORMAL * @return array an associative, eventually multidimensional array or the `default` option. */ public static function parse($data = null, array $options = array()) { $defaults = array('default' => array(), 'scanner_mode' => INI_SCANNER_NORMAL, 'process_sections' => true); $options += $defaults; if (empty($data)) { return $options['default']; } if (is_array($data)) { foreach ($data as $key => $value) { $data[$key] = static::parse($value, $options); } return $data; } $raw = parse_ini_string(static::filter($data), $options['process_sections'], $options['scanner_mode']); if (empty($raw)) { return $options['default']; } try { $result = Set::expand($raw); } catch (Exception $e) { $error = $e->getMessage(); $e = new IniFormatException(sprintf('IniFormat Error: %s', $error)); $e->setData(compact('data', 'raw', 'options')); throw $e; } return $result; }
/** * Method for parsing ini files * * @param string $filename Path and name of the ini file to parse * * @return array Array of strings found in the file, the array indices will be the keys. On failure an empty array will be returned * * @since 2.5 */ public static function parseFile($filename) { jimport('joomla.filesystem.file'); if (!JFile::exists($filename)) { return array(); } // Capture hidden PHP errors from the parsing $version = phpversion(); $php_errormsg = null; $track_errors = ini_get('track_errors'); ini_set('track_errors', true); if ($version >= '5.3.1') { $contents = file_get_contents($filename); $contents = str_replace('_QQ_', '"\\""', $contents); $strings = @parse_ini_string($contents); if ($strings === false) { return array(); } } else { $strings = @parse_ini_file($filename); if ($strings === false) { return array(); } if ($version == '5.3.0' && is_array($strings)) { foreach ($strings as $key => $string) { $strings[$key] = str_replace('_QQ_', '"', $string); } } } return $strings; }
function trx_parse($content, $parseProps = true) { $props = array(); $short = $full = $content; if ($parseProps) { $start = strpos($content, '---'); if ($start !== false) { $end = strpos($content, '---', $start + 3); } if ($start !== false && $end !== false) { $short = $full = substr($content, $end + 3); $props = parse_ini_string(substr($content, $start + 3, $end - 3)); } } // parse for short and full description parts by first <hr> $start = stripos($full, '<hr'); if ($start !== false) { $end = stripos($full, '>', $start); } if ($start !== false && $end !== false) { $short = substr($short, 0, $start); $full = substr($full, $end + 1); } return array($props, $short, $full); }
/** * Parses an INI-formatted string or file. Just an alias * for `parse_ini_file`/`parse_ini_string` that's here for * completeness and consistency. */ public static function parse($string, $sections = false, $scanner_mode = INI_SCANNER_NORMAL) { if (file_exists($string)) { return parse_ini_file($string, $sections, $scanner_mode); } return parse_ini_string($string, $sections, $scanner_mode); }
/** * Import templates from VISMA kml format * * @param string $kml Must be ISO-8859-1 charset * @return void */ public function import($kml) { $kml = iconv("ISO-8859-1", "UTF-8", $kml); $data = @parse_ini_string($kml, true, INI_SCANNER_RAW); foreach ($data as $values) { $id = isset($values['id']) ? $values['id'] : ''; $name = isset($values['namn']) ? $values['namn'] : ''; $text = isset($values['text']) ? $values['text'] : ''; $template = new Template(); $template->setId($id); $template->setName($name); $template->setText($text); $index = 0; while (true) { // Break when there are no more transactions if (!isset($values["Rad{$index}_konto"]) || !isset($values["Rad{$index}_belopp"])) { break; } // Add this transaction $template->addTransaction($values["Rad{$index}_konto"], $values["Rad{$index}_belopp"]); $index++; } $this->addTemplate($template); } }
/** * Parses supplied INI contents in to a PHP array. * @param string $contents INI contents to parse. * @return array */ public function parse($contents) { $contents = $this->parsePreProcess($contents); $contents = parse_ini_string($contents, true); $contents = $this->parsePostProcess($contents); return $contents; }
function loading_page_get_screen_list() { $dir = LOADING_PAGE_PLUGIN_DIR . '/loading-screens'; $screens = array(); if (file_exists($dir)) { $d = dir($dir); while (false !== ($entry = $d->read())) { if ($entry != '.' && $entry != '..' && is_dir($dir . '/' . $entry)) { $screen_dir = $dir . '/' . $entry . '/'; if (file_exists($screen_dir . 'config.ini')) { $c = parse_ini_file($screen_dir . 'config.ini', true); if (empty($c)) { $c = parse_ini_string(file_get_contents($screen_dir . 'config.ini'), true); } if (!empty($c) && !empty($c['script'])) { $c['script'] = LOADING_PAGE_PLUGIN_URL . '/loading-screens/' . $entry . '/' . $c['script']; } if (!empty($c) && !empty($c['adminscript'])) { $c['adminscript'] = LOADING_PAGE_PLUGIN_URL . '/loading-screens/' . $entry . '/' . $c['adminscript']; } if (!empty($c) && !empty($c['adminsection'])) { $c['adminsection'] = LOADING_PAGE_PLUGIN_DIR . '/loading-screens/' . $entry . '/' . $c['adminsection']; } if (!empty($c) && !empty($c['style'])) { $c['style'] = LOADING_PAGE_PLUGIN_URL . '/loading-screens/' . $entry . '/' . $c['style']; } $screens[] = $c; } } } $d->close(); } return $screens; }
public function readIni($fileName) { $file = $this->openFile($fileName); if ($file !== FALSE) { return parse_ini_string($file, TRUE); } }
/** * Alias for parse_ini_string * @see parse_ini_string * @param mixed $data * @return array */ function execute($data) { if (!is_string($data)) { $data = (string) $data; } return parse_ini_string($data, $this->process_sections, $this->scanner_mode); }
public function parse($config) { if (is_file($config)) { return parse_ini_file($config, true); } else { return parse_ini_string($config, true); } }
public function loadString($configurator) { $iniData = parse_ini_string($configurator, true); if (false === $iniData || count($iniData) == 0) { throw new Argument("Invalid configuration string"); } return $this->loadArray($iniData); }