FOSUserBundle 上的 Symfony 4.4 错误:UserManager

Symfony 4.4 Error on FOSUserBundle : UserManager

我有一个 symfony 错误,我不得不重新安装我的供应商文件夹,从那以后我有一个我无法修复的错误。

Argument 3 passed to FOS\UserBundle\Doctrine\UserManager::__construct() must be an instance of Doctrine\Common\Persistence\ObjectManager, instance of Doctrine\ORM\EntityManager given, called in C:\wamp64\www\brouwers\var\cache\dev\ContainerMmxuCtr\srcApp_KernelDevDebugContainer.php on line 1664

Error on my browser

我尝试在 composer.json

上添加:“doctrine/common”:“^2.13”

错误仍然存​​在...

我不知道如何解决这个问题。

有人可以帮助我吗?

我的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": {
        "App\Tests\": "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.*"
    }
}

}

实体用户:

<?php
// src/Entity/User.php
    
    namespace App\Entity;
    
    use Doctrine\Common\Collections\ArrayCollection;
    use Doctrine\Common\Collections\Collection;
    use FOS\UserBundle\Model\User as BaseUser;
    use Doctrine\ORM\Mapping as ORM;
    use Symfony\Component\Validator\Constraints as Assert;
    use Symfony\Component\HttpFoundation\File\UploadedFile;
    
    /**
     * @ORM\Entity
     * @ORM\Table(name="fos_user")
     */
    class User extends BaseUser
    {
        /**
         * @ORM\Id
         * @ORM\Column(type="integer")
         * @ORM\GeneratedValue(strategy="AUTO")
         */
        protected $id;
    
        /**
         * @Assert\File(maxSize="2048k")
         * @Assert\Image(mimeTypesMessage="Please upload a valid image.")
         */
        protected $profilePictureFile;
    
        // for temporary storage
        private $tempProfilePicturePath;
    
        /**
         * @ORM\Column(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();
        }
    
        /**
         * @ORM\PrePersist()
         * @ORM\PreUpdate()
         */
        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());
            }
        }
    
        /**
         * @ORM\PostPersist()
         * @ORM\PostUpdate()
         *
         * 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;
        }
    
        /**
         * @ORM\PostRemove()
         */
        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: App\Entity\User
  from_email:
      address: "bastien@no.com"
      sender_name: "bastien@no.com"

非常感谢

从 1 月 5 日到今天,FOSUserBundle 还没有任何贡献。我们把它丢在了我们公司,因为它给 Symfony 4 带来了很多麻烦,因为它似乎与 Symfony 4 不兼容。

Symfony 的文档涵盖了您需要知道和做的一切,所以我将从那里开始并自己实施身份验证。 Symfony 4 几乎内置了您需要的一切。

这是官方文档的 link:https://symfony.com/doc/4.4/security/form_login_setup.html

另一种方法是搜索与 Symfony 4 兼容的包的分支并使用分支或自己创建一个。