Doctrinebundle: Twig dependency but not included in composer.json

Created on 18 Aug 2017  路  6Comments  路  Source: doctrine/DoctrineBundle

When installing symfony using flex, Twig is not present and adding doctrine orm/bundle causes errors to be thrown because this dependency is not present.

Generating autoload files
Executing script make cache-warmup [OK]
Executing script assets:install --symlink --relative public [KO]
 [KO]
Script assets:install --symlink --relative %PUBLIC_DIR% returned with error code 255
!!  PHP Fatal error:  Uncaught ReflectionException: Class Twig_Extension not found in /Users/arai/projects/api/vendor/doctrine/doctrine-bundle/Twig/DoctrineExtension.php:23
!!  Stack trace:
!!  #0 /Users/arai/projects/api/vendor/symfony/debug/DebugClassLoader.php(144): require_once('/Users/arai/pro...')
!!  #1 [internal function]: Symfony\Component\Debug\DebugClassLoader->loadClass('Doctrine\\Bundle...')
!!  #2 [internal function]: spl_autoload_call('Doctrine\\Bundle...')
!!  #3 /Users/arai/projects/api/vendor/symfony/config/Resource/ClassExistenceResource.php(78): class_exists('Doctrine\\Bundle...')
!!  #4 /Users/arai/projects/api/vendor/symfony/config/Resource/SelfCheckingResourceChecker.php(34): Symfony\Component\Config\Resource\ClassExistenceResource->isFresh(1503072746)
!!  #5 /Users/arai/projects/api/vendor/symfony/config/ResourceCheckerConfigCache.php(113): Symfony\Component\Config\Resource\SelfCheckingResourceChecker->isFresh(Object(Symfony\Component\Config\Resource\ClassExistenceResource), 1503072746)
!!  #6 /Users/arai/projects/api/vendor/symfony/confi in /Users/arai/projects/api/vendor/doctrine/doctrine-bundle/Twig/DoctrineExtension.php on line 23
!!  
!!  
!!  Fatal error: Uncaught ReflectionException: Class Twig_Extension not found in /Users/arai/projects/api/vendor/doctrine/doctrine-bundle/Twig/DoctrineExtension.php on line 23
!!  
!!  ReflectionException: Class Twig_Extension not found in /Users/arai/projects/api/vendor/doctrine/doctrine-bundle/Twig/DoctrineExtension.php on line 23
!!  
!!  Call Stack:
!!      0.0233    2181304   1. Symfony\Component\Debug\ErrorHandler->handleException() /Users/arai/projects/api/vendor/symfony/debug/ErrorHandler.php:0
!!  
!!  
!!  

Any thoughts on how to fix this? I don't want twig as a dependency.

Bug

Most helpful comment

Well, we register a Twig extension as a tagged private service, so Symfony will remove the service definition if it is unused, and it won't be used if TwigBundle is not here to use the tag.

The issue here was a bug in Symfony itself, which may not even have been avoided by a check (as the bug was precisely in the tracking of class existence to refresh the cache).

I suggest closing this issue.

All 6 comments

@sonu27 since this package uses it due to toolbar additions, it will be needed, and should probably be added to the bundle as a dependency.

@Ocramius But you can use this bundle without its debug toolbar (if you don't use the the debug toolbar in symfony) so this is an optional dependency. And since the WebProfilerBundle has a dependency on twig everything should work without problems.

@sonu27 the error you see is due to a bug in the symfony config component that throws and error when registering services with missing dependencies that will be fixed in the next symfony release.

@jvasseur Thanks, I thought it was related to flex. I'll try out the branch :)

and should probably be added to the bundle as a dependency

Please don't, if the bundle doesn't strictly require it, only provides additional functionality when it exists, it should go to suggests.
Hard requirement on twig would be a nightmare for any API end-users. :/

@Majkl578 optional deps are a pain anyway: if we don't have a hard dep on that bundle, then we should at least check if it exists before wiring with it.

Well, we register a Twig extension as a tagged private service, so Symfony will remove the service definition if it is unused, and it won't be used if TwigBundle is not here to use the tag.

The issue here was a bug in Symfony itself, which may not even have been avoided by a check (as the bug was precisely in the tracking of class existence to refresh the cache).

I suggest closing this issue.

Was this page helpful?
0 / 5 - 0 ratings