parse the source of a configuration file manually.

@param string $contents the file-contents to parse
971173
function parse_contents($contents)
	{
		if($this->fix_newlines) {
			// fix mac/dos formatted newlines
			$contents = preg_replace('!\r\n?!', "\n", $contents);
		}

		$config_data = array();
		$config_data['sections'] = array();
		$config_data['vars'] = array();

		/* reference to fill with data */
		$vars =& $config_data['vars'];

		/* parse file line by line */
		preg_match_all('!^.*\r?\n?!m', $contents, $match);
		$lines = $match[0];
		for ($i=0, $count=count($lines); $i<$count; $i++) {
			$line = $lines[$i];
			if (empty($line)) continue;

			if ( substr($line, 0, 1) == '[' && preg_match('!^\[(.*?)\]!', $line, $match) ) {
				/* section found */
				if (substr($match[1], 0, 1) == '.') {
					/* hidden section */
					if ($this->read_hidden) {
						$section_name = substr($match[1], 1);
					} else {
						/* break reference to $vars to ignore hidden section */
						unset($vars);
						$vars = array();
						continue;
					}
				} else {
					$section_name = $match[1];
				}
				if (!isset($config_data['sections'][$section_name]))
				$config_data['sections'][$section_name] = array('vars' => array());
				$vars =& $config_data['sections'][$section_name]['vars'];
				continue;
			}

			if (preg_match('/^\s*(\.?\w+)\s*=\s*(.*)/s', $line, $match)) {
				/* variable found */
				$var_name = rtrim($match[1]);
				if (strpos($match[2], '"""') === 0) {
					/* handle multiline-value */
					$lines[$i] = substr($match[2], 3);
					$var_value = '';
					while ($i<$count) {
						if (($pos = strpos($lines[$i], '"""')) === false) {
							$var_value .= $lines[$i++];
						} else {
							/* end of multiline-value */
							$var_value .= substr($lines[$i], 0, $pos);
							break;
						}
					}
					$booleanize = false;

				} else {
					/* handle simple value */
					$var_value = preg_replace('/^([\'"])(.*)\1$/', '\2', rtrim($match[2]));
					$booleanize = $this->booleanize;

				}
				$this->_set_config_var($vars, $var_name, $var_value, $booleanize);
			}
			/* else unparsable line / means it is a comment / means ignore it */
		}
		return $config_data;
	}
1109804
protected function parseContent($content) {
        if(is_bool($content)) {
            $this->addLanguage($this->language, $content);
            return;
        }
        if (!$content) {
            return;
        }
        if (is_string($content)) {
            $this->addLanguage($this->language, $content);
            return;
        }
        foreach($content as $key => $data) {
            if (!empty($data[0]['sys']['linkType'])) {
                foreach($data as $link) {
                    $this->addLink($link['id'], $link['linkType'], $key);
                }
            } else {
                if (is_numeric($key)) {
                    $this->addLanguage($this->language, [$data]);
                } else {
                    $this->addLanguage($key, $data);
                }
            }
        }
    }
26420
private function parseConfigFile()
    {
        $activeConfig = $this->getOriginalConfig();
        $activeConfig = $this->beforeExplode($activeConfig);

        //convert into an array
        $activeConfig = explode("\n", $activeConfig);

        $this->activeConfig = $this->afterExplode($activeConfig);

        return !empty($this->activeConfig);
    }
1024567
private static function initializeConfigurations()
    {
        if (!is_readable(self::CONFIGURATION_PATH)) {
            throw new \RuntimeException("Cannot parse configurations file (config.ini)");
        }
        self::$configurationFile = new ConfigurationFile(self::CONFIGURATION_PATH);
    }
1372197
public function setContent(string $content): void {
		if ($this->compiled) {
			throw new ViewException("Attempt to alter view after compilation.", ViewException::AFTER_COMPILE_ALTERATION);
		}
		
		// like the header above, $content might be a file or the
		// actual content
		
		$this->content = is_file($content)
			? file_get_contents($content)
			: $content;
	}
554759
public function parseIncr($files)
    {
        foreach($files as $file)
        {
            if(isset($this->fileMap[$file]))
            {
                unset($this->fileMap[$file]);
            }
            if(!is_file($file))
            {
                continue;
            }
            $content = file_get_contents($file);
            if(preg_match('/namespace ([^;]+);/', $content, $matches) <= 0)
            {
                continue;
            }
            $namespace = trim($matches[1]);
            $className = $namespace . '\\' . basename($file, '.php');
            if(class_exists($className))
            {
                $this->parse($className);
            }
        }
    }
1080992
public function loadString($string)
    {
        $this->sourceString = $string;

        if ($this->config->allowPhpScripts === false) {
            $this->sourceString = preg_replace(
                '/<\\?.*(\\?>|$)/Us',
                '',
                str_replace('<?=', '<?php echo ', $this->sourceString)
            );
        }

        $this->sourceString = str_replace(
            [
                '__DIR__',
                '__FILE__',
            ],
            [
                "'" . $this->getSourceFileDirectory() . "'",
                "'" . $this->getSourceFilePath() . "'",
            ],
            $this->sourceString
        );

        return empty($this->sourceString);
    }
356338
protected function saveContents($contents)
    {
        $this->contents = $contents;

        try {
            $this->getFilesystem()->put($this->getFilepath(), json_encode($contents));
        } catch (Exception $e) {
            // ...
        }
    }
572786
protected function parse(/*# string */ $contents)/*# : array */
    {
        $result = [];
        $regex = sprintf(
            '/^\s*+(%s)\s*+=\s*+(%s)(?:#.*+)?\s*$/m',
            $this->name_pattern,
            $this->value_pattern
        );
        if (preg_match_all($regex, $contents, $matched, \PREG_SET_ORDER)) {
            foreach ($matched as $m) {
                $result[$m[1]] = trim($m[2]);
            }
        }
        return $result;
    }
837777
public function write($contents)
    {
        if (!is_string($contents)) {
            throw new Exception('$contents can only be of type string');
        }

        $this->body->write($contents);
        return $this;
    }
462082
protected function setLogHandler($contents)
    {
        $expression = "/'log'.*=>((?!env\('APP_LOG').)*'\b.+?\b'\)?/";
        $replacement = "'log' => env('APP_LOG', 'single')";

        $modified = preg_replace($expression, $replacement, $contents);

        if ($contents !== $modified)
        {
            $this->myCommand->info('Set the log handler in "config/app.php".');
        }

        return $modified;
    }
613071
public function parse($path)
    {
        $fullPath = strstr($path, '.config.php') ? $path : $path . '.config.php';
        if (!file_exists($fullPath))
        {
            throw new FileNotFoundException($fullPath);
        }

        return include($fullPath);
    }
551431
public function parseContent($content)
    {
        $cto = $this->getContentTypeObject();
        if (!empty($cto)) {
            return $cto->parseContent($content);
        } else {
            return $content;
        }
    }
1371809
private static function parseHeaderContent($content)
    {
        $parts = explode(';', $content);
        $headerValue = array_shift($parts);
        $options = array();
        // Parse options
        foreach ($parts as $part) {
            if (false === empty($part)) {
                $partSplit = explode('=', $part, 2);
                if (2 === count($partSplit)) {
                    list ($key, $value) = $partSplit;
                    if ('*' === substr($key, -1)) {
                        // RFC 5987
                        $key = substr($key, 0, -1);
                        if (preg_match(
                            "/(?P<charset>[\w!#$%&+^_`{}~-]+)'(?P<language>[\w-]*)'(?P<value>.*)$/",
                            $value,
                            $matches
                        )) {
                            $value = mb_convert_encoding(
                                rawurldecode($matches['value']),
                                'utf-8',
                                $matches['charset']
                            );
                        }
                    }
                    $options[trim($key)] = trim($value, ' "');
                } else {
                    // Bogus option
                    $options[$partSplit[0]] = '';
                }
            }
        }

        return array($headerValue, $options);
    }
811276
public static function parseFile($filename) {
    $source = @file_get_contents($filename);
    if ($source === FALSE) {
      return FALSE;
    }
    return self::parseSource($source, $filename);
  }
968466
protected function parse_file($file = null) {
        if (is_null($file)) {
            $file = $this->file;
        }

        if (empty($this->file_data)) {
            $this->load_data($file);
        }

        return !empty($this->file_data) ? $this->parse_string() : false;
    }
258904
public  function loadConfig($file){
		$config = include $file;
		$this->path = $config['path'];
		$this->compiled = $config['compiled'];
		$this->forceCompile = $config['forceCompile'];
		$this->skipCommentTags = $config['skipCommentTags'];
		$this->source_filename_extension = $config['source_filename_extension'];
		$this->dest_filename_extension = $config['dest_filename_extension'];
		if( !is_dir( $this->path )){
			mkdir( $this->path ,0777,true );
		}
		if( !is_dir( $this->compiled )){
			mkdir( $this->compiled ,0777,true );
		}
	}