Read XML Config File

example: readConfigFile('conf.d/usergroup.xml');

@param string $path
@return SimpleXMLElement
174639
public static function readConfigFile($path = '')
    {
        $path = str_replace('..', '', $path);
        $realPath = self::$configDir . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $path);
        $cachedFile = self::$cachePath . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $path).'.php';
        if (file_exists($cachedFile) && self::$config['cache'] === true) {
            $conf = require_once($cachedFile);
        } else {
            if (file_exists($realPath)) {
                switch (self::$configExt) {
                    case 'xml':
                        $objConfig = simplexml_load_file($realPath);
                        $conf = json_decode(json_encode($objConfig), true);
                        break;
                    case 'yaml':
                        $conf = Yaml::parse(file_get_contents($realPath));
                        break;
                    default:
                        $conf = require_once $realPath;
                        break;
                }
                if (self::$config['cache'] === true) {
                    touch($cachedFile);
                    $str = "<?php\nreturn ".var_export($conf, true).";\n";
                    file_put_contents($cachedFile, $str);
                }
            }
        }
        return $conf;
    }
298093
public function parse($path)
    {
        $parser = new Parser();
        $document = $parser->parse(file_get_contents($path));
        $properties = $document->getYAML();
        $properties['__content'] = $document->getContent();

        return $properties;
    }
130999
public function getXmlBase($path)
    {
        $returnValue = (string) '';

        
        if (!isset($this->xmlBase[$path])) {
        	throw new tao_helpers_translation_TranslationException('Missing xmlBase for file '.$path);
        }
        $returnValue = $this->xmlBase[$path]; 
        

        return (string) $returnValue;
    }
496730
protected function loadFiles($path): array
    {
        $config = [];

        if (!is_dir($path)) {
            throw new ConfigException("Configuration directory `$path` not found");
        }

        $iterator = new \GlobIterator(
            $path . '/*.php',
            \FilesystemIterator::KEY_AS_FILENAME | \FilesystemIterator::CURRENT_AS_PATHNAME
        );

        foreach ($iterator as $name => $file) {
            $name = substr($name, 0, -4);
            $config[$name] = $this->loadFile($file);
        }
        return $config;
    }
781209
public function parse($path)
    {
        libxml_use_internal_errors(true);

        $data = simplexml_load_file($path, null, LIBXML_NOERROR);

        if ($data === false) {
            $errors      = libxml_get_errors();
            $latestError = array_pop($errors);
            $error       = array(
                'message' => $latestError->message,
                'type'    => $latestError->level,
                'code'    => $latestError->code,
                'file'    => $latestError->file,
                'line'    => $latestError->line,
            );
            throw new ParseException($error);
        }

        $data = json_decode(json_encode($data), true);

        return $data;
    }
736624
private function loadFile(string $path)
    {
        if (!file_exists($path)) {
            throw new Exception('Configuration file "' . $path . '" is not found');
        }

        if (!is_readable($path)) {
            throw new Exception('Configuration file "' . $path . '" is not readable');
        }

        // Include file
        $content = include $path;

        if (!\is_array($content)) {
            throw new Exception("Passed file \"$path\" is not array");
        }

        return $content;
    }
690712
public function readConfig($path)
    {
        $jsonFile = new JsonFile($path);
        $config = $jsonFile->exists() ? $jsonFile->read() : [];
        foreach ($this->dependencies as $key) {
            if (!isset($config[$key])) {
                $config[$key] = [];
            }
        }
        return $config;
    }
752423
public function parse(string $path): ?ViewPath
    {
        $this->validatePath($path);

        //Cutting extra symbols (see Twig)
        $filename = preg_replace(
            '#/{2,}#',
            '/',
            str_replace('\\', '/', (string)$path)
        );

        $namespace = $this->defaultNamespace;
        if (strpos($filename, '.') === false) {
            //Force default extension
            $filename .= '.' . $this->extension;
        } elseif (!$this->match($filename)) {
            return null;
        }

        if (strpos($filename, LoaderInterface::NS_SEPARATOR) !== false) {
            list($namespace, $filename) = explode(LoaderInterface::NS_SEPARATOR, $filename);
        }

        //Twig like namespaces
        if (isset($filename[0]) && $filename[0] == '@') {
            $separator = strpos($filename, '/');
            if ($separator === false) {
                throw new PathException(sprintf('Malformed view path"%s" (expecting "@namespace/name").', $path));
            }

            $namespace = substr($filename, 1, $separator - 1);
            $filename = substr($filename, $separator + 1);
        }

        return new ViewPath(
            $namespace,
            $this->fetchName($filename),
            $filename
        );
    }
1369037
public function reads( $path )
	{
		try {
			$content = $this->fs->get( $path );
		} catch( \Exception $e ) {
			throw new Exception( $e->getMessage(), 0, $e );
		}

		if( ( $stream = tmpfile() ) === false ) {
			throw new Exception( 'Couldn\'t create temporary file' );
		}

		if( fwrite( $stream, $content ) === false ) {
			throw new Exception( 'Couldn\'t write to temporary file' );
		}

		if( rewind( $stream ) === false ) {
			throw new Exception( 'Couldn\'t rewind temporary file' );
		}

		return $stream;
	}
62792
public static function readFile($dir, $path)
    {
        if (!pathinfo($path, PATHINFO_EXTENSION)) {
            $path .= '.json';
        }

        if ($path[0] != '/') {
            $path = $dir.DIRECTORY_SEPARATOR.$path;
        }

        if (!is_file($path) || !is_readable($path)) {
            throw new \RuntimeException(sprintf('Unable to load configuration from "%s".', $path));
        }

        $data = json_decode(file_get_contents($path), true);
        if (json_last_error() !== JSON_ERROR_NONE) {
            throw new \RuntimeException('Configuration JSON format is invalid.');
        }

        if (isset($data['$extends']) && is_string($data['$extends'])) {
            $extends = static::readFile($dir, $data['$extends']);
            $data = array_replace_recursive($extends, $data);
            unset($data['$extends']);
        }

        return $data;
    }
1137969
public function loadConfiguration($path = self::CONFIG_DEFAULT_FILE)
    {
        if (!is_file($path)) {
            return false;
        }

        $this->configuration = include $path;

        if (!is_array($this->configuration)) {
            throw new ConfigurationException('Configuration file ' . $path . ' must return an array');
        }

        $filesystem = new Filesystem();

        if ($filesystem->isAbsolutePath($this->configuration['web-dir'])) {
            $this->setDocumentRoot($this->configuration['web-dir']);
        } else {
            $this->setDocumentRoot($this->getRoot() . '/' . $this->configuration['web-dir']);
        }

        if (!is_dir($_SERVER['DOCUMENT_ROOT'])) {
            return false;
        }

        return true;
    }
841659
public function getDom($path)
    {
        $dom = new \DOMDocument('1.0', 'utf8');
        if (($content = $this->getContent($path)) && $dom->loadHTML($content)) {
            return $dom;
        } else {
            return;
        }
    }
972792
public function loadSetupFile($path)
	{
		$result = false;

		if ($path)
		{
			if (!file_exists($path))
			{
				return $result;
			}

			$xml = simplexml_load_file($path);

			if ($params = $xml->params)
			{
				foreach ($params as $param)
				{
					$this->setXML($param);
					$result = true;
				}
			}
		}
		else
		{
			$result = true;
		}

		return $result;
	}
712620
public function getElement($path)
    {
        $found = null;

        foreach ($this->getElements() as $element) {
            if ($element instanceof ElementsInterface) {
                if (! is_null($found = $element->getElement($path))) {
                    return $found;
                }
            }

            if ($element instanceof NamedFormElement && $element->getPath() == $path) {
                return $element;
            }
        }
    }
116702
public function parse($path)
    {
        $rawDocument = $this->loadDocument($path);
        list($rawMetadata, $rawContent) = $this->splitDocument($rawDocument);
        return $this->createDocument($rawDocument, $rawMetadata, $rawContent);
    }
829548
public function loadFile($path) {
        $config = null;
        $mode = defined('INI_SCANNER_TYPED') ? INI_SCANNER_TYPED : INI_SCANNER_NORMAL;

        try {
            $config = parse_ini_file($path, true, $mode);
        } catch (Exception $ex) {}

        if ( ! is_array($config)) {
            throw new InvalidConfigFormatException(
                s('IniConfigDriver expects config at path %s to be a valid ini file.', $path)
            );
        }

        return $config;
    }
264905
public function read(string $path): string
    {
        $path = $this->normalizePath($path);
        $this->assertPresent($path);

        return $this->getAdapter()->read($path);
    }