sonata-project / SonataMediaBundle

Symfony SonataMediaBundle
https://docs.sonata-project.org/projects/SonataMediaBundle
MIT License
449 stars 496 forks source link

PHPCR classes generated with SonataEasyExtendsBundle break debug:autowire #1576

Closed quisse closed 4 years ago

quisse commented 5 years ago

Environment

Sonata packages

$ composer show --latest 'sonata-project/*'
sonata-project/admin-bundle              3.47.0          3.47.0             The missing Symfony Admin Generator
sonata-project/block-bundle              3.15.0          3.15.0             Symfony SonataBlockBundle
sonata-project/cache                     2.0.1           2.0.1              Cache library
sonata-project/classification-bundle     3.8.0           3.8.0              Symfony SonataClassificationBundle
sonata-project/comment-bundle            3.1.1           3.1.1              Integrate the FOSCommentBundle in the Sonata Project
sonata-project/core-bundle               3.16.1          3.16.2             Symfony SonataCoreBundle
sonata-project/datagrid-bundle           2.5.0           2.5.0              Symfony SonataDatagridBundle
sonata-project/doctrine-extensions       1.1.5           1.2.0              Doctrine2 behavioral extensions
sonata-project/doctrine-orm-admin-bundle 3.8.3           3.8.3              Symfony Sonata / Integrate Doctrine ORM into the SonataAdminBundle
sonata-project/easy-extends-bundle       2.5.0           2.5.0              Symfony SonataEasyExtendsBundle
sonata-project/ecommerce                 2.x-dev 9dbff3e dev-master 8cb8813 E-Commerce solution provided by Sonata
sonata-project/exporter                  1.11.0          1.11.0             Lightweight Exporter library
sonata-project/formatter-bundle          4.0.0           4.1.2              Symfony SonataFormatterBundle
sonata-project/intl-bundle               2.5.0           2.5.0              Symfony SonataIntlBundle
sonata-project/media-bundle              3.19.1          3.19.1             Symfony SonataMediaBundle
sonata-project/notification-bundle       3.6.0           3.6.1              Symfony SonataNotificationBundle
sonata-project/seo-bundle                2.7.0           2.7.0              Symfony SonataSeoBundle
sonata-project/translation-bundle        2.4.0           2.4.1              SonataTranslationBundle
sonata-project/user-bundle               4.3.0           4.3.0              Symfony SonataUserBundle

Symfony packages

$ composer show --latest 'symfony/*'
symfony/acl-bundle            v1.0.0                            v1.0.0                            Symfony AclBundle
symfony/apache-pack           v1.0.1                            v1.0.1                            A pack for Apache support in Symfony
symfony/asset                 v4.2.1                            v4.2.4                            Symfony Asset Component
symfony/browser-kit           v4.2.1                            v4.2.4                            Symfony BrowserKit Component
symfony/cache                 v4.2.1                            v4.2.4                            Symfony Cache component with PSR-6, PSR-16, and tags
symfony/config                v4.2.4                            v4.2.4                            Symfony Config Component
symfony/console               v4.2.1                            v4.2.4                            Symfony Console Component
symfony/contracts             v1.0.2                            v1.0.2                            A set of abstractions extracted out of the Symfony components
symfony/css-selector          v4.2.1                            v4.2.4                            Symfony CssSelector Component
symfony/debug                 v4.2.4                            v4.2.4                            Symfony Debug Component
symfony/debug-bundle          v4.2.1                            v4.2.4                            Symfony DebugBundle
symfony/debug-pack            v1.0.7                            v1.0.7                            A debug pack for Symfony projects
symfony/dependency-injection  v4.2.4                            v4.2.4                            Symfony DependencyInjection Component
symfony/doctrine-bridge       v4.2.4                            v4.2.4                            Symfony Doctrine Bridge
symfony/dom-crawler           v4.2.1                            v4.2.4                            Symfony DomCrawler Component
symfony/dotenv                v4.2.2                            v4.2.4                            Registers environment variables from a .env file
symfony/event-dispatcher      v4.2.4                            v4.2.4                            Symfony EventDispatcher Component
symfony/expression-language   v4.2.1                            v4.2.4                            Symfony ExpressionLanguage Component
symfony/filesystem            v4.2.4                            v4.2.4                            Symfony Filesystem Component
symfony/finder                v4.2.4                            v4.2.4                            Symfony Finder Component
symfony/flex                  v1.1.8                            v1.2.0                            Composer plugin for Symfony
symfony/form                  v4.2.1                            v4.2.4                            Symfony Form Component
symfony/framework-bundle      v4.2.1                            v4.2.4                            Symfony FrameworkBundle
symfony/http-foundation       v4.2.4                            v4.2.4                            Symfony HttpFoundation Component
symfony/http-kernel           v4.2.4                            v4.2.4                            Symfony HttpKernel Component
symfony/inflector             v4.2.4                            v4.2.4                            Symfony Inflector Component
symfony/intl                  v4.2.4                            v4.2.4                            A PHP replacement layer for the C intl extension that includes additional data from the ICU library.
symfony/maker-bundle          dev-fix-regenerate-option cd4ff36 dev-fix-regenerate-option cd4ff36 Symfony Maker helps you create empty commands, controllers, form classes, tests and more so you can forget about writing boilerplate code.
symfony/monolog-bridge        v4.2.1                            v4.2.4                            Symfony Monolog Bridge
symfony/monolog-bundle        v3.3.1                            v3.3.1                            Symfony MonologBundle
symfony/options-resolver      v4.2.4                            v4.2.4                            Symfony OptionsResolver Component
symfony/orm-pack              v1.0.5                            v1.0.6                            A pack for the Doctrine ORM
symfony/panther               v0.2.0                            v0.3.0                            A browser testing and web scraping library for PHP and Symfony.
symfony/phpunit-bridge        v4.2.1                            v4.2.4                            Symfony PHPUnit Bridge
symfony/polyfill-intl-icu     v1.10.0                           v1.10.0                           Symfony polyfill for intl's ICU-related data and classes
symfony/polyfill-mbstring     v1.10.0                           v1.10.0                           Symfony polyfill for the Mbstring extension
symfony/polyfill-php72        v1.10.0                           v1.10.0                           Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions
symfony/process               v4.2.1                            v4.2.4                            Symfony Process Component
symfony/profiler-pack         v1.0.4                            v1.0.4                            A pack for the Symfony web profiler
symfony/property-access       v4.2.4                            v4.2.4                            Symfony PropertyAccess Component
symfony/property-info         v4.2.1                            v4.2.4                            Symfony Property Info Component
symfony/routing               v4.2.4                            v4.2.4                            Symfony Routing Component
symfony/security              v4.2.4                            v4.2.4                            Symfony Security Component
symfony/security-acl          dev-master 22928f6                dev-master 22928f6                Symfony Security Component - ACL (Access Control List)
symfony/security-bundle       v4.2.1                            v4.2.4                            Symfony SecurityBundle
symfony/serializer            v4.2.1                            v4.2.4                            Symfony Serializer Component
symfony/serializer-pack       v1.0.2                            v1.0.2                            A pack for the Symfony serializer
symfony/stopwatch             v4.2.1                            v4.2.4                            Symfony Stopwatch Component
symfony/swiftmailer-bundle    v3.2.4                            v3.2.5                            Symfony SwiftmailerBundle
symfony/templating            v4.2.4                            v4.2.4                            Symfony Templating Component
symfony/test-pack             v1.0.5                            v1.0.5                            A pack for functional and end-to-end testing within a Symfony app
symfony/translation           v4.2.1                            v4.2.4                            Symfony Translation Component
symfony/twig-bridge           v4.2.2                            v4.2.4                            Symfony Twig Bridge
symfony/twig-bundle           v4.2.1                            v4.2.4                            Symfony TwigBundle
symfony/validator             v4.2.1                            v4.2.4                            Symfony Validator Component
symfony/var-dumper            v4.2.1                            v4.2.4                            Symfony mechanism for exploring and dumping PHP variables
symfony/var-exporter          v4.2.1                            v4.2.4                            A blend of var_export() + serialize() to turn any serializable data structure to plain PHP code
symfony/web-link              v4.2.1                            v4.2.4                            Symfony WebLink Component
symfony/web-profiler-bundle   v4.2.1                            v4.2.4                            Symfony WebProfilerBundle
symfony/web-server-bundle     v4.2.1                            v4.2.4                            Symfony WebServerBundle
symfony/webpack-encore-bundle v1.0.0                            v1.2.2                            Integration with your Symfony app & Webpack Encore!
symfony/yaml                  v4.2.1                            v4.2.4                            Symfony Yaml Component

PHP version

$ php -v
PHP 7.1.25 (cli) (built: Dec  7 2018 08:20:45) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.1.25, Copyright (c) 1999-2018, by Zend Technologies
    with Xdebug v2.6.0, Copyright (c) 2002-2018, by Derick Rethans

Subject

When having extended SonataMediaBundle via SonataEasyExtendsBundle as described in docs, running php bin/console debug:autowire doesn't work because class BaseGalleryHasMediaRepository extends Doctrine\ODM\PHPCR\DocumentRepository and the doctrine/odm package isn't installed because unused.

Steps to reproduce

bin/console debug:autowiring with SonataMediaBundle extended

Expected results

Autowirable Types
=================

 The following classes & interfaces can be used as type-hints when autowiring:

 Interface for annotation readers.
 Doctrine\Common\Annotations\Reader (annotations.cached_reader)
--and so on--

Actual results

Autowirable Types
=================

 The following classes & interfaces can be used as type-hints when autowiring:
PHP Fatal error:  Class 'Doctrine\ODM\PHPCR\DocumentRepository' not found in /*********/vendor/sonata-project/media-bundle/src/PHPCR/BaseGalleryHasMediaRepository.php on line 19
PHP Stack trace:
PHP   1. {main}() /*********/bin/console:0
PHP   2. Symfony\Bundle\FrameworkBundle\Console\Application->run() /*********/bin/console:40
PHP   3. Symfony\Bundle\FrameworkBundle\Console\Application->doRun() /*********/vendor/symfony/console/Application.php:145
PHP   4. Symfony\Bundle\FrameworkBundle\Console\Application->doRun() /*********/vendor/symfony/framework-bundle/Console/Application.php:75
PHP   5. Symfony\Bundle\FrameworkBundle\Console\Application->doRunCommand() /*********/vendor/symfony/console/Application.php:262
PHP   6. Symfony\Bundle\FrameworkBundle\Console\Application->doRunCommand() /*********/vendor/symfony/framework-bundle/Console/Application.php:89
PHP   7. Symfony\Bundle\FrameworkBundle\Command\DebugAutowiringCommand->run() /*********/vendor/symfony/console/Application.php:919
PHP   8. Symfony\Bundle\FrameworkBundle\Command\DebugAutowiringCommand->execute() /*********/vendor/symfony/console/Command/Command.php:255
PHP   9. Symfony\Bundle\FrameworkBundle\Console\Descriptor\Descriptor::getClassDescription() /*********/vendor/symfony/framework-bundle/Command/DebugAutowiringCommand.php:96
PHP  10. ReflectionClass->__construct() /*********/vendor/symfony/framework-bundle/Console/Descriptor/Descriptor.php:302
PHP  11. spl_autoload_call() /*********/vendor/symfony/framework-bundle/Console/Descriptor/Descriptor.php:302
PHP  12. Symfony\Component\Debug\DebugClassLoader->loadClass() /*********/vendor/symfony/framework-bundle/Console/Descriptor/Descriptor.php:302
PHP  13. Composer\Autoload\ClassLoader->loadClass() /*********/vendor/symfony/debug/DebugClassLoader.php:162
PHP  14. Composer\Autoload\includeFile() /*********/vendor/composer/ClassLoader.php:322
PHP  15. include() /*********/vendor/composer/ClassLoader.php:444
PHP  16. spl_autoload_call() /*********/src/Application/Sonata/MediaBundle/PHPCR/GalleryHasMediaRepository.php:15
PHP  17. Symfony\Component\Debug\DebugClassLoader->loadClass() /*********/src/Application/Sonata/MediaBundle/PHPCR/GalleryHasMediaRepository.php:15
PHP  18. Composer\Autoload\ClassLoader->loadClass() /*********/vendor/symfony/debug/DebugClassLoader.php:162
PHP  19. Composer\Autoload\includeFile() /*********/vendor/composer/ClassLoader.php:322
PHP  20. include() /*********/vendor/composer/ClassLoader.php:444

Fatal error: Class 'Doctrine\ODM\PHPCR\DocumentRepository' not found in /*********/vendor/sonata-project/media-bundle/src/PHPCR/BaseGalleryHasMediaRepository.php on line 19

Call Stack:
    0.0005     364768   1. {main}() /*********/bin/console:0
    0.0379    2048744   2. Symfony\Bundle\FrameworkBundle\Console\Application->run() /*********/bin/console:40
    0.0543    2221184   3. Symfony\Bundle\FrameworkBundle\Console\Application->doRun() /*********/vendor/symfony/console/Application.php:145
    8.7402   62478272   4. Symfony\Bundle\FrameworkBundle\Console\Application->doRun() /*********/vendor/symfony/framework-bundle/Console/Application.php:75
    8.7411   62480208   5. Symfony\Bundle\FrameworkBundle\Console\Application->doRunCommand() /*********/vendor/symfony/console/Application.php:262
    8.7411   62480208   6. Symfony\Bundle\FrameworkBundle\Console\Application->doRunCommand() /*********/vendor/symfony/framework-bundle/Console/Application.php:89
    8.7476   62685048   7. Symfony\Bundle\FrameworkBundle\Command\DebugAutowiringCommand->run() /*********/vendor/symfony/console/Application.php:919
    8.7478   62686064   8. Symfony\Bundle\FrameworkBundle\Command\DebugAutowiringCommand->execute() /*********/vendor/symfony/console/Command/Command.php:255
    9.2666   60715032   9. Symfony\Bundle\FrameworkBundle\Console\Descriptor\Descriptor::getClassDescription() /*********/vendor/symfony/framework-bundle/Command/DebugAutowiringCommand.php:96
    9.2666   60715144  10. ReflectionClass->__construct() /*********/vendor/symfony/framework-bundle/Console/Descriptor/Descriptor.php:302
    9.2666   60715336  11. spl_autoload_call() /*********/vendor/symfony/framework-bundle/Console/Descriptor/Descriptor.php:302
    9.2666   60715432  12. Symfony\Component\Debug\DebugClassLoader->loadClass() /*********/vendor/symfony/framework-bundle/Console/Descriptor/Descriptor.php:302
    9.2666   60715432  13. Composer\Autoload\ClassLoader->loadClass() /*********/vendor/symfony/debug/DebugClassLoader.php:162
    9.2666   60715592  14. Composer\Autoload\includeFile() /*********/vendor/composer/ClassLoader.php:322
    9.2667   60716104  15. include('/*********/src/Application/Sonata/MediaBundle/PHPCR/GalleryHasMediaRepository.php') /*********/vendor/composer/ClassLoader.php:444
    9.2667   60716104  16. spl_autoload_call() /*********/src/Application/Sonata/MediaBundle/PHPCR/GalleryHasMediaRepository.php:15
    9.2667   60716184  17. Symfony\Component\Debug\DebugClassLoader->loadClass() /*********/src/Application/Sonata/MediaBundle/PHPCR/GalleryHasMediaRepository.php:15
    9.2667   60716184  18. Composer\Autoload\ClassLoader->loadClass() /*********/vendor/symfony/debug/DebugClassLoader.php:162
    9.2668   60716344  19. Composer\Autoload\includeFile() /*********/vendor/composer/ClassLoader.php:322
    9.2668   60717024  20. include('/*********/vendor/sonata-project/media-bundle/src/PHPCR/BaseGalleryHasMediaRepository.php') /*********/vendor/composer/ClassLoader.php:444

22:54:04 CRITICAL  [php] Fatal Error: Class 'Doctrine\ODM\PHPCR\DocumentRepository' not found ["exception" => Symfony\Component\Debug\Exception\FatalErrorException { …}]

In BaseGalleryHasMediaRepository.php line 19:

  Attempted to load class "DocumentRepository" from namespace "Doctrine\ODM\PHPCR".  
  Did you forget a "use" statement for another namespace? 
quisse commented 5 years ago

Willing to create a PR. Just not sure how to fix. (you can find me on the #symfony #sonata slack)

stale[bot] commented 4 years ago

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.