[英]ReflectionException: Class does not exist after upgrading Symfony
After upgrading my php version from 5.6 to 7.3 and upgrading Symfony from 3.4 to 4.4 I get an ReflectionException everytime I try to access my application on my localhost.将我的 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 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 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;
}
}
composer.json作曲家.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.*"
}
}
}
I have not made any changes in the used files and WaiverBundle\\File still exists in the directory "WaiverBundle\\Entity\\File".我没有对使用过的文件进行任何更改,并且 WaiverBundle\\File 仍然存在于目录“WaiverBundle\\Entity\\File”中。 I have also deleted the cache and restarted the web server, but still receive the error message.
我也删除了缓存并重新启动了 Web 服务器,但仍然收到错误消息。 I suspect that it could have something to do with the VichUploaderBundle I use, but I did not make any changes to that in the uprading process.
我怀疑它可能与我使用的 VichUploaderBundle 有关,但我在升级过程中没有对其进行任何更改。
Does anyone have an idea how to get rid of this error?有谁知道如何摆脱这个错误?
You've answered your own question.你已经回答了你自己的问题。
[…] WaiverBundle\\File still exists in the directory "WaiverBundle\\Entity\\File".
[…] WaiverBundle\\File 仍然存在于目录“WaiverBundle\\Entity\\File”中。
Those are not the same thing, from the trace it looks like you have an annotation referring to WaiverBundle\\File
instead of WaiverBundle\\Entity\\File
.这些不是一回事,从跟踪来看,您似乎有一个引用
WaiverBundle\\File
而不是WaiverBundle\\Entity\\File
的注释。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.