-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Added check for ext-dom to XmlUtil::loadFile #24047
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added check for ext-dom to XmlUtil::loadFile #24047
Conversation
3f45aee
to
f665f42
Compare
@@ -17,6 +17,7 @@ | |||
], | |||
"require": { | |||
"php": "^7.1.3", | |||
"ext-dom": "*", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
although DOM is installed together with php-xml
, it's still possible to disable xml extension
and enable dom extension
// test.php
<?php
use Symfony\Component\Config\Util\XmlUtils;
require_once 'vendor/autoload.php';
var_dump(XmlUtils::loadFile('test.xml'));
// test.xml
<?xml version="1.0" encoding="utf-8"?>
<root xmlns="http://example.com/schema"></root>
$ php -n -dextension=phar.so -dextension=json.so -dextension=iconv.so -dextension=xml.so test.php
Fatal error: Uncaught Error: Class 'DOMDocument' not found in /mnt/c/checkouts/symfony/src/Symfony/Component/Config/Util/XmlUtils.php:52
$ echo $? # => 255
$ php -n -dextension=phar.so -dextension=json.so -dextension=iconv.so -dextension=dom.so test.php
$ echo $? // => 0
It's perfectly valid to use the Config component without XML files. Thus I suggest to instead handle the missing XML extension case gracefully in the |
FrameworkBundle should have the requirement though, because it depends on XML support. |
the requirement should be |
Btw, this should be rebased on 2.7 and the target branch changed accordingly. |
@chalasr it's possible to disable xml and enable dom only, ref.: #24047 (comment), so changing FrameworkBundle requirements from I can put |
@oleg-andreyev the question is whether we need only ext-dom or also ext-xml. If we need ext-xml, the requirement should stay like that. But anyway, for the config component, it must stay an optional dependency (the component contains many other things not requiring XML) |
For Config we should deal with
Well, I don't have the code in mind, but if edit: let's let FrameworkBundle as is if |
@chalasr I don't see where sum up:
|
6e18095
to
8bde9e2
Compare
*/ | ||
public static function loadFile($file, $schemaOrCallable = null) | ||
{ | ||
if (!extension_loaded('dom')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you pointed out that dom
doesn't guarantee xml
. Should we put || !extension_loaded('xml')
since this is calling xml functions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, ext-dom
does not guarantee that ext-xml
is enabled, but php itself guarantees libxml
, so all libxml_*
will work, unless php is compiled from source with --disable-libxml
(which is probably where uncommon)
$ apt-cache depends php7.0-fpm
php7.0-fpm
Depends: libmagic1
Depends: mime-support
Depends: php7.0-cli
Depends: php7.0-common
Depends: php7.0-json
Depends: php7.0-opcache
Depends: tzdata
Depends: ucf
Depends: init-system-helpers
Depends: lsb-base
Depends: libapparmor1
Depends: libc6
Depends: libpcre3
Depends: libssl1.0.0
Depends: libsystemd0
Depends: libxml2
Depends: zlib1g
Conflicts: <php5-fpm>
Sugges
8000
ts: php-pear
$ apt-cache depends php7.0-cli
php7.0-cli
Depends: libedit2
Depends: libmagic1
Depends: mime-support
Depends: php7.0-common
Depends: php7.0-json
Depends: php7.0-opcache
Depends: php7.0-readline
Depends: tzdata
Depends: ucf
Depends: libc6
Depends: libpcre3
Depends: libssl1.0.0
Depends: libxml2
Depends: zlib1g
Breaks: <php5-cli>
Suggests: php-pear
Replaces: <php5-cli>
$ apt-cache depends php7.0-cgi
php7.0-cgi
Depends: libmagic1
Depends: mime-support
Depends: php7.0-cli
Depends: php7.0-common
Depends: php7.0-json
Depends: php7.0-opcache
Depends: tzdata
Depends: ucf
Depends: libc6
Depends: libpcre3
Depends: libssl1.0.0
Depends: libxml2
Depends: zlib1g
Conflicts: <php5-cgi>
Suggests: php-pear
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok then :)
The existing tests for this method should be updated to add |
@oleg-andreyev fair enough 😅 |
@oleg-andreyev Can you rebase your branch against 2.7 to see tests green? |
8bde9e2
to
2f292c2
Compare
Thank you @oleg-andreyev. |
…yev) 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 ------- 2f292c2 #24046 added check for ext-dom to XmlUtil::loadFile
ext-dom
if missing when trying to useXmlUtil::loadFile