FOSUserBundle generate:entities does not work, Access level of fields too high

∥☆過路亽.° 提交于 2020-01-07 02:01:07

问题


I have a problem with FOSUserBundle after I configured DoctrineExtensions, with StofDoctrineExtensionsBundle.

First of all, to install DoctrineExtensions I had to remove "auto_mapping: true" segment from app/config/config.yml file.

I found that if auto_mapping is not active I have to include FOSUserBundle: ~ in default:mappings segment.

But, when I try

php app/console doctrine:schema:update --force

or

php app/console doctrine:generate:entities FOS

I get:

PHP Deprecated:  Comments starting with '#' are deprecated in /etc/php5/cli/conf.d/ming.ini on line 1 in Unknown on line 0
Generating entities for namespace "FOS"
PHP Fatal error:  Access level to FOS\UserBundle\Entity\User::$username must be protected (as in class FOS\UserBundle\Model\User) or weaker in /var/www/rBay/vendor/friendsofsymfony/user-bundle/FOS/UserBundle/Entity/User.php on line 17
PHP Stack trace:
PHP   1. {main}() /var/www/rBay/app/console:0
PHP   2. Symfony\Component\Console\Application->run() /var/www/rBay/app/console:22
PHP   3. Symfony\Bundle\FrameworkBundle\Console\Application->doRun() /var/www/rBay/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:105
PHP   4. Symfony\Component\Console\Application->doRun() /var/www/rBay/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:78
PHP   5. Symfony\Component\Console\Command\Command->run() /var/www/rBay/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:192
PHP   6. Doctrine\Bundle\DoctrineBundle\Command\GenerateEntitiesDoctrineCommand->execute() /var/www/rBay/vendor/symfony/symfony/src/Symfony/Component/Console/Command/Command.php:238
PHP   7. Doctrine\Bundle\DoctrineBundle\Mapping\MetadataFactory->getNamespaceMetadata() /var/www/rBay/vendor/doctrine/doctrine-bundle/Doctrine/Bundle/DoctrineBundle/Command/GenerateEntitiesDoctrineCommand.php:109
PHP   8. Doctrine\Bundle\DoctrineBundle\Mapping\MetadataFactory->getMetadataForNamespace() /var/www/rBay/vendor/doctrine/doctrine-bundle/Doctrine/Bundle/DoctrineBundle/Mapping/MetadataFactory.php:97
PHP   9. Doctrine\Bundle\DoctrineBundle\Mapping\MetadataFactory->getAllMetadata() /var/www/rBay/vendor/doctrine/doctrine-bundle/Doctrine/Bundle/DoctrineBundle/Mapping/MetadataFactory.php:160
PHP  10. Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory->getAllMetadata() /var/www/rBay/vendor/doctrine/doctrine-bundle/Doctrine/Bundle/DoctrineBundle/Mapping/MetadataFactory.php:196
PHP  11. Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain->getAllClassNames() /var/www/rBay/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php:111
PHP  12. Doctrine\Common\Persistence\Mapping\Driver\AnnotationDriver->getAllClassNames() /var/www/rBay/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/Driver/MappingDriverChain.php:132
PHP  13. require_once() /var/www/rBay/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/Driver/AnnotationDriver.php:194
PHP  14. Symfony\Component\ClassLoader\DebugClassLoader->loadClass() /var/www/rBay/vendor/symfony/symfony/src/Symfony/Component/ClassLoader/DebugClassLoader.php:0
PHP  15. require() /var/www/rBay/vendor/symfony/symfony/src/Symfony/Component/ClassLoader/DebugClassLoader.php:82

Fatal error: Access level to FOS\UserBundle\Entity\User::$username must be protected (as in class FOS\UserBundle\Model\User) or weaker in /var/www/rBay/vendor/friendsofsymfony/user-bundle/FOS/UserBundle/Entity/User.php on line 17

Call Stack:
0.0002     644752   1. {main}() /var/www/rBay/app/console:0
0.0132    3467080   2. Symfony\Component\Console\Application->run() /var/www/rBay/app/console:22
0.0155    3851816   3. Symfony\Bundle\FrameworkBundle\Console\Application->doRun() /var/www/rBay/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:105
2.3154   50066792   4. Symfony\Component\Console\Application->doRun() /var/www/rBay/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:78
2.3187   50066792   5. Symfony\Component\Console\Command\Command->run() /var/www/rBay/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:192
2.3192   50068328   6. Doctrine\Bundle\DoctrineBundle\Command\GenerateEntitiesDoctrineCommand->execute() /var/www/rBay/vendor/symfony/symfony/src/Symfony/Component/Console/Command/Command.php:238
2.3208   50178008   7. Doctrine\Bundle\DoctrineBundle\Mapping\MetadataFactory->getNamespaceMetadata() /var/www/rBay/vendor/doctrine/doctrine-bundle/Doctrine/Bundle/DoctrineBundle/Command/GenerateEntitiesDoctrineCommand.php:109
2.3208   50178008   8. Doctrine\Bundle\DoctrineBundle\Mapping\MetadataFactory->getMetadataForNamespace() /var/www/rBay/vendor/doctrine/doctrine-bundle/Doctrine/Bundle/DoctrineBundle/Mapping/MetadataFactory.php:97
2.3208   50178320   9. Doctrine\Bundle\DoctrineBundle\Mapping\MetadataFactory->getAllMetadata() /var/www/rBay/vendor/doctrine/doctrine-bundle/Doctrine/Bundle/DoctrineBundle/Mapping/MetadataFactory.php:160
2.3307   50203984  10. Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory->getAllMetadata() /var/www/rBay/vendor/doctrine/doctrine-bundle/Doctrine/Bundle/DoctrineBundle/Mapping/MetadataFactory.php:196
2.3308   50204456  11. Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain->getAllClassNames() /var/www/rBay/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php:111
2.3308   50205408  12. Doctrine\Common\Persistence\Mapping\Driver\AnnotationDriver->getAllClassNames() /var/www/rBay/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/Driver/MappingDriverChain.php:132
2.3428   52000872  13. require_once('/var/www/rBay/src/MSoft/UserBundle/Entity/User.php') /var/www/rBay/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/Driver/AnnotationDriver.php:194
2.3428   52001400  14. Symfony\Component\ClassLoader\DebugClassLoader->loadClass() /var/www/rBay/vendor/symfony/symfony/src/Symfony/Component/ClassLoader/DebugClassLoader.php:0
2.3431   52081336  15. require('/var/www/rBay/vendor/friendsofsymfony/user-bundle/FOS/UserBundle/Entity/User.php') /var/www/rBay/vendor/symfony/symfony/src/Symfony/Component/ClassLoader/DebugClassLoader.php:82

I'll attach related regions of my config file, as well, just in case...

doctrine:
dbal:
    driver:   %database_driver%
    host:     %database_host%
    port:     %database_port%
    dbname:   %database_name%
    user:     %database_user%
    password: %database_password%
    charset:  UTF8

orm:
    auto_generate_proxy_classes: %kernel.debug%
    entity_managers:
        default:
            connection: default
            mappings:
                gedmo_translatable:
                    type: annotation
                    prefix: Gedmo\Translatable\Entity
                    dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Translatable/Entity"
                    alias: GedmoTranslatable # this one is optional and will default to the name set for the mapping
                    is_bundle: false
                gedmo_translator:
                    type: annotation
                    prefix: Gedmo\Translator\Entity
                    dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Translator/Entity"
                    alias: GedmoTranslator # this one is optional and will default to the name set for the mapping
                    is_bundle: false
                gedmo_loggable:
                    type: annotation
                    prefix: Gedmo\Loggable\Entity
                    dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Loggable/Entity"
                    alias: GedmoLoggable # this one is optional and will default to the name set for the mapping
                    is_bundle: false
                gedmo_tree:
                    type: annotation
                    prefix: Gedmo\Tree\Entity
                    dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Tree/Entity"
                    alias: GedmoTree # this one is optional and will default to the name set for the mapping
                    is_bundle: false
                MSoftAdminBundle: ~
                MSoftUserBundle: ~
                FOSUserBundle: ~

# Fosuser Configuration
fos_user:
    db_driver: orm
    firewall_name: main
    user_class: MSoft\UserBundle\Entity\User

stof_doctrine_extensions:
    default_locale: en_US
    orm:
        default:
            tree: true
            sluggable: true

What am I doing wrong?


回答1:


Solved. Problem appeared when I ran

php app/console doctrine:generate:entities FOS

Than doctrine entity generator added properties that wasn't supposed to be there, and that made a problem. The point is that class FOS\UserBundle\Entity\User should have empty body, and generator created all the fields from FOS\UserBundle\Model\User in it, just with higher protection level ("private" instead of "protected").




回答2:


All properties of the User class should be protected, not public.



来源:https://stackoverflow.com/questions/13425544/fosuserbundle-generateentities-does-not-work-access-level-of-fields-too-high

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!