minor #24047 Added check for ext-dom to XmlUtil::loadFile (oleg-andreyev)

This PR was merged into the 2.7 branch.

Discussion
----------

Added check for ext-dom to XmlUtil::loadFile

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | no, minor enhancement to gracefully suggest to install `ext-dom` if missing when trying to use `XmlUtil::loadFile`
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | ?
| Fixed tickets | #24046
| License       | MIT

Commits
-------

2f292c247e #24046 added check for ext-dom to XmlUtil::loadFile
This commit is contained in:
Maxime Steinhausser 2017-09-03 12:25:31 +02:00
commit 26ef6d27ad
1 changed files with 5 additions and 0 deletions

View File

@ -37,9 +37,14 @@ class XmlUtils
* @return \DOMDocument
*
* @throws \InvalidArgumentException When loading of XML file returns error
* @throws \RuntimeException When DOM extension is missing
*/
public static function loadFile($file, $schemaOrCallable = null)
{
if (!extension_loaded('dom')) {
throw new \RuntimeException('Extension DOM is required.');
}
$content = @file_get_contents($file);
if ('' === trim($content)) {
throw new \InvalidArgumentException(sprintf('File %s does not contain valid XML, it is empty.', $file));