bpolaszek/webpush-bundle

The package does not work with Symfony 4.0

Opened this issue · 1 comments

When I upgraded to Symfony 4.0, I was met with an error:

PHP Fatal error: Uncaught Symfony\Component\Debug\Exception\UndefinedMethodException: Attempted to call an undefined method named "getRootNode" of class "Symfony\Component\Config\Definition\Builder\TreeBuilder". in /var/www/html/vendor/bentools/webpush-bundle/src/DependencyInjection/Configuration.php:18

I found out that in BenTools\WebPushBundle\DependencyInjection::getConfigTreeBuilder()

if (Kernel::MAJOR_VERSION < 4) {
    $treeBuilder = new TreeBuilder();
    $rootNode = $treeBuilder->root('bentools_webpush');
} else {
    $treeBuilder = new TreeBuilder('bentools_webpush');
    $rootNode = $treeBuilder->getRootNode();
}

I noticed that other packages that are not failing are basically checking if method exists before calling it (i.e doctrine):

$treeBuilder = new TreeBuilder('doctrine');

if (method_exists($treeBuilder, 'getRootNode')) {
    $rootNode = $treeBuilder->getRootNode();
} else {
    // BC layer for symfony/config 4.1 and older
    $rootNode = $treeBuilder->root('doctrine');
}

Notice the comment, seems thatgetRootNode method does not exist in <4.2. Could we add a support for it?

Hello there,

Thanks for your feedback.

Even though I'm not in favor of supporting old versions like this, feel free to submit a PR if this doesn't harm.

Thank you,
Ben