Symfony 4.4 Error on FOSUserBundle : UserManager

I had a bug with symfony, I had to reinstall my vendor folder and since then I have a bug that I cannot fix.

Argument 3 passed to FOSUserBundleDoctrineUserManager::__construct() must be an instance of DoctrineCommonPersistenceObjectManager, instance of DoctrineORMEntityManager given, called in C:wamp64wwwbrouwersvarcachedevContainerMmxuCtrsrcApp_KernelDevDebugContainer.php on line 1664

Error on my browser

I have try to add : "doctrine/common":"^2.13" on my composer.json

The bug is still here …

I don’t know how to fix this.

Someone can help me ?

My composer.json

{
"type": "project",
"license": "proprietary",
"require": {
    "php": "^7.1.3",
    "ext-ctype": "*",
    "ext-iconv": "*",
    "friendsofsymfony/user-bundle": "^2.1",
    "a2lix/translation-form-bundle": "^3.0",
    "excelwebzone/recaptcha-bundle": "^1.5",
    "doctrine/common":"^2.13",
    "karser/karser-recaptcha3-bundle": "^0.1.8",
    "knplabs/doctrine-behaviors": "^2.0",
    "knplabs/knp-paginator-bundle": "^5.2",
    "sensio/framework-extra-bundle": "^5.1",
    "stof/doctrine-extensions-bundle": "^1.4",
    "symfony/apache-pack": "^1.0",
    "symfony/asset": "4.4.*",
    "symfony/console": "4.4.*",
    "symfony/dotenv": "4.4.*",
    "symfony/expression-language": "4.4.*",
    "symfony/flex": "^1.3.1",
    "symfony/form": "4.4.*",
    "symfony/framework-bundle": "4.4.*",
    "symfony/http-client": "4.4.*",
    "symfony/intl": "4.4.*",
    "symfony/mailer": "4.4.*",
    "symfony/monolog-bundle": "^3.1",
    "symfony/orm-pack": "*",
    "symfony/process": "4.4.*",
    "symfony/security-bundle": "4.4.*",
    "symfony/serializer-pack": "*",
    "symfony/swiftmailer-bundle": "^3.4",
    "symfony/translation": "4.4.*",
    "symfony/twig-pack": "*",
    "symfony/validator": "4.4.*",
    "symfony/web-link": "4.4.*",
    "symfony/webpack-encore-bundle": "^1.7",
    "symfony/yaml": "4.4.*",
    "twig/extensions": "^1.5",
    "twig/extra-bundle": "^3.0",
    "twig/twig": "^2.0"
},
"require-dev": {
    "symfony/debug-pack": "*",
    "symfony/maker-bundle": "^1.0",
    "symfony/profiler-pack": "*",
    "symfony/test-pack": "*"
},
"config": {
    "preferred-install": {
        "*": "dist"
    },
    "sort-packages": true
},
"autoload": {
    "psr-4": {
        "App": "src/"
    }
},
"autoload-dev": {
    "psr-4": {
        "AppTests": "tests/"
    }
},
"replace": {
    "paragonie/random_compat": "2.*",
    "symfony/polyfill-ctype": "*",
    "symfony/polyfill-iconv": "*",
    "symfony/polyfill-php71": "*",
    "symfony/polyfill-php70": "*",
    "symfony/polyfill-php56": "*"
},
"scripts": {
    "auto-scripts": {
        "cache:clear": "symfony-cmd",
        "assets:install %PUBLIC_DIR%": "symfony-cmd"
    },
    "post-install-cmd": [
        "@auto-scripts"
    ],
    "post-update-cmd": [
        "@auto-scripts"
    ]
},
"conflict": {
    "symfony/symfony": "*"
},
"extra": {
    "symfony": {
        "allow-contrib": false,
        "require": "4.4.*"
    }
}

}

Entity User :

<?php
// src/Entity/User.php
    
    namespace AppEntity;
    
    use DoctrineCommonCollectionsArrayCollection;
    use DoctrineCommonCollectionsCollection;
    use FOSUserBundleModelUser as BaseUser;
    use DoctrineORMMapping as ORM;
    use SymfonyComponentValidatorConstraints as Assert;
    use SymfonyComponentHttpFoundationFileUploadedFile;
    
    /**
     * @ORMEntity
     * @ORMTable(name="fos_user")
     */
    class User extends BaseUser
    {
        /**
         * @ORMId
         * @ORMColumn(type="integer")
         * @ORMGeneratedValue(strategy="AUTO")
         */
        protected $id;
    
        /**
         * @AssertFile(maxSize="2048k")
         * @AssertImage(mimeTypesMessage="Please upload a valid image.")
         */
        protected $profilePictureFile;
    
        // for temporary storage
        private $tempProfilePicturePath;
    
        /**
         * @ORMColumn(type="string", length=255, nullable=true)
         */
        protected $profilePicturePath;
    
    
        public function __construct()
        {
            parent::__construct();
            // your own logic
            $this->roles = array('ROLE_ADMIN');
            $this->enabled = true;
        }
    
        public function getId(): ?int
        {
            return $this->id;
        }
    
        /**
         * Asks whether the user is granted a particular role
         *
         * @return boolean
         */
        public function isGranted($role)
        {
            return in_array($role, $this->getRoles());
        }
    
        /**
         * Sets the file used for profile picture uploads
         *
         * @param UploadedFile $file
         * @return object
         */
        public function setProfilePictureFile(UploadedFile $file = null) {
            // set the value of the holder
            $this->profilePictureFile       =   $file;
            // check if we have an old image path
            if (isset($this->profilePicturePath)) {
                // store the old name to delete after the update
                $this->tempProfilePicturePath = $this->profilePicturePath;
                $this->profilePicturePath = null;
            } else {
                $this->profilePicturePath = 'initial';
            }
    
            return $this;
        }
    
        /**
         * Get the file used for profile picture uploads
         *
         * @return UploadedFile
         */
        public function getProfilePictureFile() {
    
            return $this->profilePictureFile;
        }
    
        /**
         * Set profilePicturePath
         *
         * @param string $profilePicturePath
         * @return User
         */
        public function setProfilePicturePath($profilePicturePath)
        {
            $this->profilePicturePath = $profilePicturePath;
    
            return $this;
        }
    
        /**
         * Get profilePicturePath
         *
         * @return string
         */
        public function getProfilePicturePath()
        {
            return $this->profilePicturePath;
        }
    
        /**
         * Get the absolute path of the profilePicturePath
         */
        public function getProfilePictureAbsolutePath() {
            return null === $this->profilePicturePath
                ? null
                : $this->getUploadRootDir().'/'.$this->profilePicturePath;
        }
    
        /**
         * Get root directory for file uploads
         *
         * @return string
         */
        protected function getUploadRootDir($type='profilePicture') {
            // the absolute directory path where uploaded
            // documents should be saved
            return __DIR__.'/../../public/images/'.$this->getUploadDir($type);
        }
    
        /**
         * Specifies where in the /web directory profile pic uploads are stored
         *
         * @return string
         */
        protected function getUploadDir($type='profilePicture') {
            // the type param is to change these methods at a later date for more file uploads
            // get rid of the __DIR__ so it doesn't screw up
            // when displaying uploaded doc/image in the view.
            return 'profilePicture';
        }
    
        /**
         * Get the web path for the user
         *
         * @return string
         */
        public function getWebProfilePicturePath() {
    
            return '/'.$this->getUploadDir().'/'.$this->getProfilePicturePath();
        }
    
        /**
         * @ORMPrePersist()
         * @ORMPreUpdate()
         */
        public function preUploadProfilePicture() {
            if (null !== $this->getProfilePictureFile()) {
                // a file was uploaded
                // generate a unique filename
                $filename = md5(random_bytes(10));
    
                $this->setProfilePicturePath($filename.'.'.$this->getProfilePictureFile()->guessExtension());
            }
        }
    
        /**
         * @ORMPostPersist()
         * @ORMPostUpdate()
         *
         * Upload the profile picture
         *
         * @return mixed
         */
        public function uploadProfilePicture() {
            // check there is a profile pic to upload
            if ($this->getProfilePictureFile() === null) {
                return;
            }
            // if there is an error when moving the file, an exception will
            // be automatically thrown by move(). This will properly prevent
            // the entity from being persisted to the database on error
            $this->getProfilePictureFile()->move($this->getUploadRootDir(), $this->getProfilePicturePath());
    
            // check if we have an old image
            if (isset($this->tempProfilePicturePath) && file_exists($this->getUploadRootDir().'/'.$this->tempProfilePicturePath)) {
                // delete the old image
                unlink($this->getUploadRootDir().'/'.$this->tempProfilePicturePath);
                // clear the temp image path
                $this->tempProfilePicturePath = null;
            }
            $this->profilePictureFile = null;
        }
    
        /**
         * @ORMPostRemove()
         */
        public function removeProfilePictureFile()
        {
            if ($file = $this->getProfilePictureAbsolutePath() && file_exists($this->getProfilePictureAbsolutePath())) {
                unlink($file);
            }
        }
    
    
    
    }

fos_user.yaml

fos_user:
  db_driver: orm # other valid values are 'mongodb' and 'couchdb'
  firewall_name: main
  user_class: AppEntityUser
  from_email:
      address: "[email protected]"
      sender_name: "[email protected]"

Tks a lot

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *