簡體   English   中英

ReflectionException:升級 Symfony 后類不存在

[英]ReflectionException: Class does not exist after upgrading Symfony

將我的 php 版本從 5.6 升級到 7.3 並將 Symfony 從 3.4 升級到 4.4 后,每次我嘗試在本地主機上訪問我的應用程序時都會收到一個 ReflectionException。

    ReflectionException:
    Class WaiverBundle\File does not exist

      at /srv/http/sp7/vendor/jms/metadata/src/MetadataFactory.php:170
      at ReflectionClass->__construct('WaiverBundle\\File')
         (/srv/http/sp7/vendor/jms/metadata/src/MetadataFactory.php:170)
      at Metadata\MetadataFactory->getClassHierarchy('WaiverBundle\\File')
         (/srv/http/sp7/vendor/jms/metadata/src/MetadataFactory.php:76)
      at Metadata\MetadataFactory->getMetadataForClass('WaiverBundle\\File')
         (/srv/http/sp7/vendor/vich/uploader-bundle/src/Metadata/MetadataReader.php:85)
      at Vich\UploaderBundle\Metadata\MetadataReader->getUploadableFields('WaiverBundle\\File')
         (/srv/http/sp7/vendor/vich/uploader-bundle/src/DataCollector/MappingCollector.php:27)
      at Vich\UploaderBundle\DataCollector\MappingCollector->collect(object(Request), object(Response), object(ReflectionException))
         (/srv/http/sp7/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Profiler/Profiler.php:178)
      at Symfony\Component\HttpKernel\Profiler\Profiler->collect(object(Request), object(Response), object(ReflectionException))
         (/srv/http/sp7/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/EventListener/ProfilerListener.php:90)
      at Symfony\Component\HttpKernel\EventListener\ProfilerListener->onKernelResponse(object(ResponseEvent), 'kernel.response', object(TraceableEventDispatcher))
         (/srv/http/sp7/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/Debug/WrappedListener.php:126)
      at Symfony\Component\EventDispatcher\Debug\WrappedListener->__invoke(object(ResponseEvent), 'kernel.response', object(TraceableEventDispatcher))
         (/srv/http/sp7/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/EventDispatcher.php:264)
      at Symfony\Component\EventDispatcher\EventDispatcher->doDispatch(array(object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener)), 'kernel.response', object(ResponseEvent))
         (/srv/http/sp7/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/EventDispatcher.php:239)
      at Symfony\Component\EventDispatcher\EventDispatcher->callListeners(array(object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener)), 'kernel.response', object(ResponseEvent))
         (/srv/http/sp7/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/EventDispatcher.php:73)
      at Symfony\Component\EventDispatcher\EventDispatcher->dispatch(object(ResponseEvent), 'kernel.response')
         (/srv/http/sp7/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/Debug/TraceableEventDispatcher.php:168)
      at Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher->dispatch(object(ResponseEvent), 'kernel.response')
         (/srv/http/sp7/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php:179)
      at Symfony\Component\HttpKernel\HttpKernel->filterResponse(object(Response), object(Request), 2)
         (/srv/http/sp7/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php:167)
      at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), 2)
         (/srv/http/sp7/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php:68)
      at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), 2, false)
         (/srv/http/sp7/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/EventListener/ExceptionListener.php:61)
      at Symfony\Component\HttpKernel\EventListener\ExceptionListener->onKernelException(object(ExceptionEvent), 'kernel.exception', object(TraceableEventDispatcher))
         (/srv/http/sp7/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/Debug/WrappedListener.php:126)
      at Symfony\Component\EventDispatcher\Debug\WrappedListener->__invoke(object(ExceptionEvent), 'kernel.exception', object(TraceableEventDispatcher))
         (/srv/http/sp7/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/EventDispatcher.php:264)
      at Symfony\Component\EventDispatcher\EventDispatcher->doDispatch(array(object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener)), 'kernel.exception', object(ExceptionEvent))
         (/srv/http/sp7/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/EventDispatcher.php:239)
      at Symfony\Component\EventDispatcher\EventDispatcher->callListeners(array(object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener)), 'kernel.exception', object(ExceptionEvent))
         (/srv/http/sp7/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/EventDispatcher.php:73)
      at Symfony\Component\EventDispatcher\EventDispatcher->dispatch(object(ExceptionEvent), 'kernel.exception')
         (/srv/http/sp7/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/Debug/TraceableEventDispatcher.php:168)
      at Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher->dispatch(object(ExceptionEvent), 'kernel.exception')
         (/srv/http/sp7/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php:207)
      at Symfony\Component\HttpKernel\HttpKernel->handleThrowable(object(ReflectionException), object(Request), 1)
         (/srv/http/sp7/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php:100)
      at Symfony\Component\HttpKernel\HttpKernel->terminateWithException(object(ReflectionException), object(Request))
         (/srv/http/sp7/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/EventListener/DebugHandlersListener.php:116)
      at Symfony\Component\HttpKernel\EventListener\DebugHandlersListener::Symfony\Component\HttpKernel\EventListener\{closure}(object(ReflectionException))
         (/srv/http/sp7/vendor/symfony/symfony/src/Symfony/Component/ErrorHandler/ErrorHandler.php:592)
      at Symfony\Component\ErrorHandler\ErrorHandler->handleException(object(ReflectionException))                

WaiverBundle\\Entity\\File.php


    <?php

namespace WaiverBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use AppBundle\Entity\File as BaseFile;

/**
 * This class extends the base file class. Only the mapped entity and table name are different.
 *
 * @ORM\HasLifecycleCallbacks()
 * @ORM\Table(name="waiver_file")
 * @ORM\Entity
 */
class File extends BaseFile {
    /**
     * @ORM\ManyToOne(targetEntity="WaiverBundle\Entity\Waiver", inversedBy="file")
     * @ORM\JoinColumn(name="entity", referencedColumnName="id", nullable=true)
     * @var \WaiverBundle\Entity\Waiver
     **/
    protected $entity;
}
*emphasized text*

AppBundle\\Entity\\File.php

<?php

namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;

/**
 * This class defines attachments throughout the application.
 *
 * @ORM\MappedSuperclass
 * @ORM\HasLifecycleCallbacks()
 */
class File {

    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * NOTE: This is not a mapped field of entity metadata, just a simple property.
     * It is required for VichUploaderBundle and holds the actual file.
     * DO NOT rename this property since its name is hardcoded in several files.
     *
     * @var Symfony\Component\HttpFoundation\File\File
     * @Assert\File()
     */
    private $attachment;

    /**
     * @var string
     * @ORM\Column(type="string", nullable=false)
     */
    private $filename;

    /**
     * @var DateTime
     * @ORM\Column(type="datetime")
     */
    private $timestamp;

    /**
     * @ORM\ManyToOne(targetEntity="\UserBundle\Entity\User")
     * @ORM\JoinColumn(name="uploader", referencedColumnName="id")
     * @var \UserBundle\Entity\User
     */
    private $uploader;

    // GETTERS/SETTERS ETC.

    /**
     * @ORM\PrePersist
     */
    public function prePersist() {
        // set the timestamp for last update
        date_default_timezone_set('UTC');
        $this->timestamp = new \DateTime("now");
    }

    /**
     * If manually uploading a file (i.e. not using Symfony Form) ensure an instance
     * of 'UploadedFile' is injected into this setter to trigger the  update. If this
     * bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
     * must be able to accept an instance of 'File' as the bundle will inject one here
     * during Doctrine hydration.
     *
     * @param \Symfony\Component\HttpFoundation\File\File|\Symfony\Component\HttpFoundation\File\UploadedFile $file
     *
     * @return File
     */
    public function setAttachment(\Symfony\Component\HttpFoundation\File\File $file = null)
    {
        // store file in file system
        $this->attachment = $file;

        if ($file) {
            // It is required that at least one field changes if you are using doctrine
            // otherwise the event listeners won't be called and the file is lost
            date_default_timezone_set('UTC');
            $this->timestamp = new \DateTime("now");
        }

        return $this;
    }

    /**
     * @return Symfony\Component\HttpFoundation\File\File|null
     */
    public function getAttachment()
    {
        return $this->attachment;
    }

    /**
     * NOTE: This is not a Doctrine getter. It is just a workaround to get the original file name (see issue #319)
     * Cut off filename up to and including the first underscore
     *
     * @return string
     */
    public function getOriginalFilename()
    {
        return substr($this->filename, strpos($this->filename, '_') + 1);
    }

    /**
     * Get id
     *
     * @return integer
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set filename
     *
     * @param string $filename
     *
     * @return File
     */
    public function setFilename($filename)
    {
        $this->filename = $filename;

        return $this;
    }

    /**
     * Get filename
     *
     * @return string
     */
    public function getFilename()
    {
        return $this->filename;
    }

    /**
     * Set timestamp
     *
     * @param \DateTime $timestamp
     *
     * @return File
     */
    public function setTimestamp($timestamp)
    {
        $this->timestamp = $timestamp;

        return $this;
    }

    /**
     * Get timestamp
     *
     * @return \DateTime
     */
    public function getTimestamp()
    {
        return $this->timestamp;
    }

    /**
     * Set uploader
     *
     * @param \UserBundle\Entity\User $uploader
     *
     * @return File
     */
    public function setUploader(\UserBundle\Entity\User $uploader = null)
    {
        $this->uploader = $uploader;

        return $this;
    }

    /**
     * Get uploader
     *
     * @return \UserBundle\Entity\User
     */
    public function getUploader()
    {
        return $this->uploader;
    }

    /**
     * Set entity
     *
     * @param \AppBundle\Entity\FileAwareEntity $entity
     *
     * @return File
     */
    public function setEntity(\AppBundle\Entity\FileAwareEntity $entity = null)
    {
        $this->entity = $entity;

        return $this;
    }

    /**
     * Get entity
     *
     * @return \AppBundle\Entity\FileAwareEntity
     */
    public function getEntity()
    {
        return $this->entity;
    }
}

作曲家.json

{
    "name": "stefan/sp28",
    "license": "proprietary",
    "type": "project",
    "autoload": {
        "psr-4": {
            "": "src/",
            "AppBundle\\": "src/AppBundle",
            "WaiverBundle\\": "src/WaiverBundle",
            "Mindpool\\LogBundle\\": "vendor/mindpool/logbundle"
        },
        "classmap": [
            "app/AppKernel.php",
            "app/AppCache.php"
        ]
    },
    "require": {
        "php": ">=7.1.3",
        "symfony/symfony": "^4.4.0",
        "doctrine/orm": "^2.7",
        "doctrine/doctrine-bundle": "~1.4",
        "symfony/swiftmailer-bundle": "~3.4",
        "symfony/monolog-bundle": "~3.1",
        "incenteev/composer-parameter-handler": "~2.0",
        "friendsofsymfony/user-bundle": "^2.1.2",
        "twig/twig": "^2.9",
        "salavert/time-ago-in-words": "^1.7.1",

        "stof/doctrine-extensions-bundle": "^1.2",
        "vich/uploader-bundle": "~1.12.1",
        "knplabs/knp-paginator-bundle": "^5.0",
        "mgilet/notification-bundle": "^3.1",

        "php-translation/symfony-bundle": "^0.6.1",
        "friendsofsymfony/elastica-bundle": "5.1",
        "ruflin/elastica": "^6",
        "friendsofsymfony/ckeditor-bundle": "^1.1",
        "paragonie/random_compat": "~2.0.18",
        "pagerfanta/pagerfanta": "^1.1",
        "harvesthq/chosen": "^1.8",

        "symfony/cache": "^4.0",
        "symfony/config": "^4.0",
        "symfony/console": "^4.0",
        "symfony/debug": "^4.0",
        "symfony/dependency-injection": "^4.0",
        "symfony/dotenv": "^4.0",
        "doctrine/annotations": "^1.8",
        "twig/extensions": "^1.5",
        "sensio/framework-extra-bundle": "^5.5",
        "jms/metadata": "^2.1"
    },
    "require-dev": {
        "symfony/phpunit-bridge": "^3.0"
    },
    "scripts": {
        "post-install-cmd": [
            "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget"
        ],
        "post-update-cmd": [
            "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget"
        ],
        "reset-bootstrap-cmd": [
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap"
            ]
    },
    "config": {
        "bin-dir": "bin",
        "platform": {
            "php": "7.3"
        }
    },
    "extra": {
        "symfony-app-dir": "app",
        "symfony-web-dir": "web",
        "symfony-assets-install": "relative",
        "incenteev-parameters": {
            "file": "app/config/parameters.yml"
        },
        "symfony": {
            "allow-contrib": false,
            "require": "4.4.*"
        }
    }
}

我沒有對使用過的文件進行任何更改,並且 WaiverBundle\\File 仍然存在於目錄“WaiverBundle\\Entity\\File”中。 我也刪除了緩存並重新啟動了 Web 服務器,但仍然收到錯誤消息。 我懷疑它可能與我使用的 VichUploaderBundle 有關,但我在升級過程中沒有對其進行任何更改。

有誰知道如何擺脫這個錯誤?

你已經回答了你自己的問題。

[…] WaiverBundle\\File 仍然存在於目錄“WaiverBundle\\Entity\\File”中。

這些不是一回事,從跟蹤來看,您似乎有一個引用WaiverBundle\\File而不是WaiverBundle\\Entity\\File的注釋。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM