Ale*_*rez 1 php doctrine symfony doctrine-orm
当我发现此错误时,我只是尝试创建一个新服务。当我尝试列出可用的学说命令时,它显示下一个错误:
\nDoctrine\\ORM\\Mapping\\OneToMany::__construct() 必须是数组类型或 null,给定字符串,在 /var/www/html/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/ 中调用文档解析器.php
\n我尝试重置负责它的实体,但没有结果。这是所有跟踪:
\nTypeError {#478\n#message: "Argument 3 passed to Doctrine\\ORM\\Mapping\\OneToMany::__construct() must be of the type array or null, string given, called in /var/www/html/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/DocParser.php on line 971"\n #code: 0\n #file: "./vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/OneToMany.php"\n #line: 44\n trace: {\n ./vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/OneToMany.php:44 { \xe2\x80\xa6}\n ./vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/DocParser.php:971 { \xe2\x80\xa6}\n ./vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/DocParser.php:719 { \xe2\x80\xa6}\n ./vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/DocParser.php:376 { \xe2\x80\xa6}\n ./vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationReader.php:178 { \xe2\x80\xa6}\n ./vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/PsrCachedReader.php:155 { \xe2\x80\xa6}\n ./vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/PsrCachedReader.php:88 { \xe2\x80\xa6}\n ./vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/PsrCachedReader.php:98 { \xe2\x80\xa6}\n ./vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php:331 { \xe2\x80\xa6}\n ./vendor/doctrine/persistence/lib/Doctrine/Persistence/Mapping/Driver/MappingDriverChain.php:79 { \xe2\x80\xa6}\n ./vendor/doctrine/doctrine-bundle/Mapping/MappingDriver.php:45 { \xe2\x80\xa6}\n ./vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php:134 { \xe2\x80\xa6}\n ./vendor/doctrine/doctrine-bundle/Mapping/ClassMetadataFactory.php:19 { \xe2\x80\xa6}\n ./vendor/doctrine/persistence/lib/Doctrine/Persistence/Mapping/AbstractClassMetadataFactory.php:382 { \xe2\x80\xa6}\n ./vendor/doctrine/persistence/lib/Doctrine/Persistence/Mapping/AbstractClassMetadataFactory.php:251 { \xe2\x80\xa6}\n ./vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php:303 { \xe2\x80\xa6}\n ./var/cache/dev/ContainerX9n3NQZ/EntityManager_9a5be93.php:94 {\n ContainerX9n3NQZ\\EntityManager_9a5be93->getClassMetadata($className)^\n \xe2\x80\xba \n \xe2\x80\xba return $this->valueHolderda610->getClassMetadata($className);\n \xe2\x80\xba }\n arguments: {\n $className: "App\\Entity\\App\\City"\n }\n }\n ./vendor/doctrine/doctrine-bundle/Repository/ServiceEntityRepository.php:45 { \xe2\x80\xa6}\n ./src/Repository/App/CityRepository.php:26 { \xe2\x80\xa6}\n ./var/cache/dev/ContainerX9n3NQZ/getCityRepositoryService.php:27 { \xe2\x80\xa6}\n ./var/cache/dev/ContainerX9n3NQZ/App_KernelDevDebugContainer.php:525 { \xe2\x80\xa6}\n ./var/cache/dev/ContainerX9n3NQZ/getCityServiceService.php:23 { \xe2\x80\xa6}\n ./var/cache/dev/ContainerX9n3NQZ/App_KernelDevDebugContainer.php:525 { \xe2\x80\xa6}\n ./var/cache/dev/ContainerX9n3NQZ/getDoctrine_FixturesLoadCommandService.php:43 { \xe2\x80\xa6}\n ./var/cache/dev/ContainerX9n3NQZ/App_KernelDevDebugContainer.php:525 { \xe2\x80\xa6}\n ./vendor/symfony/dependency-injection/Container.php:422 { \xe2\x80\xa6}\n ./vendor/symfony/dependency-injection/Argument/ServiceLocator.php:42 { \xe2\x80\xa6}\n ./vendor/symfony/console/CommandLoader/ContainerCommandLoader.php:45 { \xe2\x80\xa6}\n ./vendor/symfony/console/Application.php:551 { \xe2\x80\xa6}\n ./vendor/symfony/console/Application.php:519 { \xe2\x80\xa6}\n ./vendor/symfony/framework-bundle/Console/Application.php:126 { \xe2\x80\xa6}\n ./vendor/symfony/console/Application.php:664 { \xe2\x80\xa6}\n Symfony\\Component\\Console\\Application->Symfony\\Component\\Console\\{closure}() {}\n ./vendor/symfony/console/Application.php:665 { \xe2\x80\xa6}\n ./vendor/symfony/framework-bundle/Console/Application.php:116 { \xe2\x80\xa6}\n ./vendor/symfony/console/Application.php:254 { \xe2\x80\xa6}\n ./vendor/symfony/framework-bundle/Console/Application.php:82 { \xe2\x80\xa6}\n ./vendor/symfony/console/Application.php:166 { \xe2\x80\xa6}\n ./bin/console:43 { \xe2\x80\xa6}\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n这是城市实体:
\n<?php\n\nnamespace App\\Entity\\App;\n\nuse App\\DBAL\\Types\\Geolocation\\Point;\nuse App\\Entity\\App\\Graveyard;\nuse App\\Repository\\App\\CityRepository;\nuse Doctrine\\ORM\\Mapping as ORM;\nuse Doctrine\\Common\\Collections\\ArrayCollection;\nuse Doctrine\\Common\\Collections\\Collection;\n\n/**\n * @ORM\\Entity(repositoryClass=CityRepository::class)\n * @ORM\\Table (name="location", schema="app")\n */\nclass City\n{\n /**\n * @ORM\\Id\n * @ORM\\GeneratedValue\n * @ORM\\Column (type="integer")\n */\n private $id;\n\n /**\n * @ORM\\Column(type="string", length=255, nullable=false)\n */\n private $name;\n\n /**\n * @ORM\\Column(type="string", length=255, nullable=true)\n */\n private $country;\n\n /**\n * @ORM\\OneToMany(targetEntity=Company::class, mappedBy="city", cascade="persist")\n */\n private $companies;\n\n /**\n * @ORM\\OneToMany(targetEntity=Graveyard::class, mappedBy="city", cascade="persist")\n */\n private $graveyards;\n\n /**\n * @ORM\\OneToMany(targetEntity=FuneralParlor::class, mappedBy="city", cascade="persist")\n */\n private $funeralParlors;\n\n /**\n * @ORM\\OneToMany(targetEntity=AdvertisementTransfer::class, mappedBy="city")\n */\n private $advertisementTransfers;\n\n /**\n * @ORM\\OneToMany(targetEntity=Crematorium::class, mappedBy="city")\n */\n private $crematoria;\n\n /**\n * @ORM\\Column(type="point")\n */\n private $coordinate;\n\n /**\n * @ORM\\Column(type="string", length=255, nullable=true, options={"default" : null})\n */\n private $province;\n\n public function __construct()\n {\n $this->companies = new ArrayCollection();\n $this->graveyards = new ArrayCollection();\n $this->funeralParlors = new ArrayCollection();\n $this->advertisementTransfers = new ArrayCollection();\n $this->crematoria = new ArrayCollection();\n }\n\n public function getId(): ?int\n {\n return $this->id;\n }\n\n public function getName(): ?string\n {\n return $this->name;\n }\n\n public function setName(string $name): self\n {\n $this->name = $name;\n\n return $this;\n }\n\n public function getCountry(): ?string\n {\n return $this->country;\n }\n\n public function setCountry(?string $country): self\n {\n $this->country = $country;\n\n return $this;\n }\n\n /**\n * @return Collection|Company[]\n */\n public function getCompanies(): Collection\n {\n return $this->companies;\n }\n\n public function addCompany(Company $company): self\n {\n if (!$this->companies->contains($company)) {\n $this->companies[] = $company;\n $company->setCity($this);\n }\n\n return $this;\n }\n\n public function removeCompany(Company $company): self\n {\n if ($this->companies->removeElement($company)) {\n // set the owning side to null (unless already changed)\n if ($company->getCity() === $this) {\n $company->setCity(null);\n }\n }\n\n return $this;\n }\n\n /**\n * @return Collection|Graveyard[]\n */\n public function getGraveyards(): Collection\n {\n return $this->graveyards;\n }\n\n public function addGraveyard(Graveyard $graveyard): self\n {\n if (!$this->graveyards->contains($graveyard)) {\n $this->graveyards[] = $graveyard;\n $graveyard->setCity($this);\n }\n\n return $this;\n }\n\n public function removeGraveyard(Graveyard $graveyard): self\n {\n if ($this->graveyards->removeElement($graveyard)) {\n // set the owning side to null (unless already changed)\n if ($graveyard->getCity() === $this) {\n $graveyard->setCity(null);\n }\n }\n\n return $this;\n }\n\n /**\n * @return Collection|FuneralParlor[]\n */\n public function getFuneralParlors(): Collection\n {\n return $this->funeralParlors;\n }\n\n public function addFuneralParlor(FuneralParlor $funeralParlor): self\n {\n if (!$this->funeralParlors->contains($funeralParlor)) {\n $this->funeralParlors[] = $funeralParlor;\n $funeralParlor->setCity($this);\n }\n\n return $this;\n }\n\n public function removeFuneralParlor(FuneralParlor $funeralParlor): self\n {\n if ($this->funeralParlors->removeElement($funeralParlor)) {\n // set the owning side to null (unless already changed)\n if ($funeralParlor->getCity() === $this) {\n $funeralParlor->setCity(null);\n }\n }\n\n return $this;\n }\n\n /**\n * @return Collection|AdvertisementTransfer[]\n */\n public function getAdvertisementTransfers(): Collection\n {\n return $this->advertisementTransfers;\n }\n\n public function addAdvertisementTransfer(AdvertisementTransfer $advertisementTransfer): self\n {\n if (!$this->advertisementTransfers->contains($advertisementTransfer)) {\n $this->advertisementTransfers[] = $advertisementTransfer;\n $advertisementTransfer->setCity($this);\n }\n\n return $this;\n }\n\n public function removeAdvertisementTransfer(AdvertisementTransfer $advertisementTransfer): self\n {\n if ($this->advertisementTransfers->removeElement($advertisementTransfer)) {\n // set the owning side to null (unless already changed)\n if ($advertisementTransfer->getCity() === $this) {\n $advertisementTransfer->setCity(null);\n }\n }\n\n return $this;\n }\n\n /**\n * @return Collection|Crematorium[]\n */\n public function getCrematoria(): Collection\n {\n return $this->crematoria;\n }\n\n public function addCrematorium(Crematorium $crematorium): self\n {\n if (!$this->crematoria->contains($crematorium)) {\n $this->crematoria[] = $crematorium;\n $crematorium->setCity($this);\n }\n\n return $this;\n }\n\n public function removeCrematorium(Crematorium $crematorium): self\n {\n if ($this->crematoria->removeElement($crematorium)) {\n // set the owning side to null (unless already changed)\n if ($crematorium->getCity() === $this) {\n $crematorium->setCity(null);\n }\n }\n\n return $this;\n }\n\n public function getCoordinate(): Point\n {\n return $this->coordinate;\n }\n\n public function setCoordinate($coordinate): self\n {\n $this->coordinate = $coordinate;\n\n return $this;\n }\n\n public function toJsonArray(): array\n {\n $coordinate = $this->getCoordinate();\n return [\n "id" => $this->getId(),\n "name" => $this->getName(),\n "country" => $this->getCountry(),\n "coordinate" => $coordinate->toJsonArray()\n ];\n }\n\n public function getProvince(): ?string\n {\n return $this->province;\n }\n\n public function setProvince(?string $province): self\n {\n $this->province = $province;\n\n return $this;\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n城市存储库:
\n<?php\n\nnamespace App\\Repository\\App;\n\nuse App\\DBAL\\Types\\Geolocation\\Point;\nuse App\\Entity\\App\\City;\nuse App\\Exception\\City\\CityAlreadyExistException;\nuse Doctrine\\Bundle\\DoctrineBundle\\Repository\\ServiceEntityRepository;\nuse Doctrine\\DBAL\\FetchMode;\nuse Doctrine\\ORM\\AbstractQuery;\nuse Doctrine\\ORM\\OptimisticLockException;\nuse Doctrine\\ORM\\ORMException;\nuse Doctrine\\ORM\\Query\\ResultSetMapping;\nuse Doctrine\\Persistence\\ManagerRegistry;\n\n/**\n * @method City|null find($id, $lockMode = null, $lockVersion = null)\n * @method City|null findOneBy(array $criteria, array $orderBy = null)\n * @method City[] findAll()\n * @method City[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)\n */\nclass CityRepository extends ServiceEntityRepository\n{\n public function __construct(ManagerRegistry $registry)\n {\n parent::__construct($registry, City::class);\n }\n\n /**\n * Get all cities on DDBB\n * @return int|mixed|string\n */\n public function getAllCities() {\n return $this->createQueryBuilder("c")->where('')->orderBy('name')->getQuery()->getResult();\n }\n\n public function getCityById(int $id): City {\n return $this->createQueryBuilder('c')->where('id = :id')->setParameter('id', $id)->getQuery()->getResult();\n }\n\n public function getCityByName(string $name): ?City\n {\n $city = $this->createQueryBuilder('c')->where('name = :name')->setParameter('name', $name)->getQuery()->getResult();\n return $city === null ? null : $city;\n }\n\n /**\n * @throws CityAlreadyExistException\n */\n public function createCity(City $city): ?City\n {\n try {\n $entityManager = $this->getEntityManager();\n $entityManager->persist($city);\n $entityManager->flush();\n return $city;\n } catch (ORMException $e) {\n throw new CityAlreadyExistException(sprintf("City %s already exist", $city->getName()));\n }\n }\n\n public function calculateDistance(City $city, $lat, $lon)\n {\n\n $SQL = "\n SELECT (ST_Distance(ST_MakePoint({$lat}, {$lon})::geography, ST_MakePoint(coordinate[0], coordinate[1])::geography) / 1000) as distance\n FROM app.location\n WHERE id = {$city->getId()}\n ";\n\n return $this->executeSQL($SQL);\n }\n\n public function calculateDistanceBetweenPointInKm(Point $origin, Point $destiny)\n {\n $SQL = "\n SELECT (ST_DISTANCE\n (\n ST_MakePoint({$origin->getLongitude()}, {$origin->getLatitude()})::geography,\n ST_MakePoint({$destiny->getLongitude()}, {$destiny->getLatitude()})::geography\n ) / 1000) as distance\n ";\n\n return $this->executeSQL($SQL)[0];\n }\n\n private function executeSQL(string $SQL)\n {\n $em = $this->getEntityManager();\n $stmt = $em->getConnection()->prepare($SQL);\n $stmt->execute();\n return $stmt->fetchAll(FetchMode::COLUMN);\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n服务实体存储库(默认情况下来自原则和 symfony):
\nclass ServiceEntityRepository extends EntityRepository implements ServiceEntityRepositoryInterface\n{\n /**\n * @param string $entityClass The class name of the entity this repository manages\n * @psalm-param class-string<T> $entityClass\n */\n public function __construct(ManagerRegistry $registry, string $entityClass)\n {\n $manager = $registry->getManagerForClass($entityClass);\n\n if ($manager === null) {\n throw new LogicException(sprintf(\n 'Could not find the entity manager for class "%s". Check your Doctrine configuration to make sure it is configured to load this entity\xe2\x80\x99s metadata.',\n $entityClass\n ));\n }\n\n parent::__construct($manager, $manager->getClassMetadata($entityClass));\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n
已解决 - 经过时间和耐心的搜索,我发现了 ORM 表示法的错误。作曲家 json 文件由队友更新,并且使用新的 versi\xc3\xb3n 级联必须带有括号,在一个地方它是打开的但不是关闭的。
\n| 归档时间: |
|
| 查看次数: |
3626 次 |
| 最近记录: |