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:
commit
26ef6d27ad
@ -37,9 +37,14 @@ class XmlUtils
|
|||||||
* @return \DOMDocument
|
* @return \DOMDocument
|
||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException When loading of XML file returns error
|
* @throws \InvalidArgumentException When loading of XML file returns error
|
||||||
|
* @throws \RuntimeException When DOM extension is missing
|
||||||
*/
|
*/
|
||||||
public static function loadFile($file, $schemaOrCallable = null)
|
public static function loadFile($file, $schemaOrCallable = null)
|
||||||
{
|
{
|
||||||
|
if (!extension_loaded('dom')) {
|
||||||
|
throw new \RuntimeException('Extension DOM is required.');
|
||||||
|
}
|
||||||
|
|
||||||
$content = @file_get_contents($file);
|
$content = @file_get_contents($file);
|
||||||
if ('' === trim($content)) {
|
if ('' === trim($content)) {
|
||||||
throw new \InvalidArgumentException(sprintf('File %s does not contain valid XML, it is empty.', $file));
|
throw new \InvalidArgumentException(sprintf('File %s does not contain valid XML, it is empty.', $file));
|
||||||
|
Reference in New Issue
Block a user