for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace mhndev\config\FileParser;
use mhndev\config\Exception\ParseException;
/**
* XML file parser
*
* @package Config
* @author Jesus A. Domingo <[email protected]>
* @author Hassan Khan <[email protected]>
* @link https://github.com/noodlehaus/config
* @license MIT
*/
class Xml implements FileParserInterface
{
* {@inheritDoc}
* Parses an XML file as an array
* @throws ParseException If there is an error parsing the XML file
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;
public static function getSupportedExtensions()
return array('xml');