-
-
Notifications
You must be signed in to change notification settings - Fork 415
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue with doctrine/orm 2.12.x #1090
Comments
I transferred the issue to MakerBundle, which is the proper place to report that. |
Doctrine ORM 2.12.x is released and this issue persists. |
The issue stems from maker-bundle/src/Doctrine/DoctrineHelper.php Lines 180 to 187 in c557553
I am not sure whats going on here. The So we are mixing types in here. Why one is from ORM, one is from Persistance? the fix for my specific case is to simply swap $classNames = (new \ReflectionClass(AnnotationDriver::class))->getProperty('classNames'); for $classNames = (new \ReflectionClass(\Doctrine\ORM\Mapping\Driver\AttributeDriver::class))->getProperty('classNames'); But I doubt this will be the generic solution we are looking for. |
FYI there was Doctrine/Persistance 3.0 released, which might be the real cause of the issue, since doctrine/orm 2.12.x uses it |
Any workaround for this? |
found the same problem today "symfony/maker-bundle": "^1.38" symfony console make:entity In DoctrineHelper.php line 187: |
"symfony/maker-bundle": "1.28.0" |
I have just solved this issue by modifying "doctrine/annotations "version in composer.json after checking which versions are allowed in composer.lock "conflict" |
Hi @Bechir-Marco , |
{
"type": "project",
"license": "proprietary",
"require": {
"php": ">=7.4",
"ext-ctype": "*",
"ext-iconv": "*",
"doctrine/annotations": "1.12.1",
"doctrine/doctrine-bundle": "^2.2",
"doctrine/doctrine-migrations-bundle": "^3.0",
"doctrine/orm": "2.8",
"gesdinet/jwt-refresh-token-bundle": "^1.1",
"phpdocumentor/reflection-docblock": "^5.3",
"sensio/framework-extra-bundle": "^6.2",
"stof/doctrine-extensions-bundle": "^1.7",
"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/process": "4.4.*",
"symfony/property-access": "4.4.*",
"symfony/property-info": "4.4.*",
"symfony/proxy-manager-bridge": "4.4.*",
"symfony/security-bundle": "4.4",
"symfony/serializer": "4.4.*",
"symfony/translation": "4.4.*",
"symfony/twig-bundle": "4.4.*",
"symfony/validator": "4.4.*",
"symfony/web-link": "4.4.*",
"symfony/web-server-bundle": "4.4.*",
"symfony/yaml": "4.4.*",
"symfonycasts/verify-email-bundle": "^1.10",
"twig/extra-bundle": "^2.12|^3.0",
"twig/twig": "^2.12|^3.0",
"vich/uploader-bundle": "1.19.0"
},
"require-dev": {
"phpunit/phpunit": "^9.5",
"symfony/browser-kit": "4.4.*",
"symfony/css-selector": "4.4.*",
"symfony/debug-bundle": "4.4.*",
"symfony/maker-bundle": "v1.30.1",
"symfony/phpunit-bridge": "^6.0",
"symfony/stopwatch": "4.4.*",
"symfony/web-profiler-bundle": "4.4.*"
},
"config": {
"allow-plugins": {
"composer/package-versions-deprecated": true,
"symfony/flex": true
},
"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.*"
}
}
} |
same problem on a brand new project symfony 6.0 |
Same issue |
Thank you @Bechir-Marco , {
"type": "project",
"license": "proprietary",
"minimum-stability": "stable",
"prefer-stable": true,
"require": {
"php": ">=8.0.2",
"ext-ctype": "*",
"ext-iconv": "*",
"doctrine/doctrine-bundle": "^2.5",
"doctrine/doctrine-migrations-bundle": "^3.2",
"doctrine/orm": "^2.11",
"symfony/console": "6.0.*",
"symfony/dotenv": "6.0.*",
"symfony/flex": "^2",
"symfony/framework-bundle": "6.0.*",
"symfony/proxy-manager-bridge": "6.0.*",
"symfony/runtime": "6.0.*",
"symfony/yaml": "6.0.*"
},
"config": {
"allow-plugins": {
"composer/package-versions-deprecated": true,
"symfony/flex": true,
"symfony/runtime": true
},
"optimize-autoloader": true,
"preferred-install": {
"*": "dist"
},
"sort-packages": true,
"platform": {
"php": "8.1"
}
},
"conflict": {
"symfony/symfony": "*"
},
"extra": {
"symfony": {
"allow-contrib": false,
"require": "6.0.*"
}
},
"require-dev": {
"symfony/maker-bundle": "^1.38",
"symfony/web-profiler-bundle": "6.0.*"
}
}
|
Temporary workaround Composer.json - change:
to:
add (to prevent 2.12 being installed):
|
Même problème que Tireur d'Elite. Dans DoctrineHelper.php ligne 187 : Impossible d'accéder à la propriété protégée Doctrine\ORM\Mapping\Driver\AnnotationDriver::$classNames mais l'a crée malgrés tout...?! |
tu as fait un composer update après la modification du composer.json ? Pour moi ça a bien contourné le problème. |
bin/console make:entity Car
created: src/Entity/Car.php
created: src/Repository/CarRepository.php
In DoctrineHelper.php line 187:
Cannot access protected property Doctrine\ORM\Mapping\Driver\AnnotationDriver::$classNames
But if you don't provide entity name, it can't ask you question, so it doesn't create anything stack trace of the actual error Error {#255
#message: "Cannot access protected property Doctrine\ORM\Mapping\Driver\AnnotationDriver::$classNames"
#code: 0
#file: "./vendor/symfony/maker-bundle/src/Doctrine/DoctrineHelper.php"
#line: 187
trace: {
./vendor/symfony/maker-bundle/src/Doctrine/DoctrineHelper.php:189 { …}
./vendor/symfony/maker-bundle/src/Doctrine/DoctrineHelper.php:163 { …}
./vendor/symfony/maker-bundle/src/Maker/MakeEntity.php:515 { …}
./vendor/symfony/maker-bundle/src/Maker/MakeEntity.php:116 { …}
./vendor/symfony/maker-bundle/src/Command/MakerCommand.php:99 { …}
./vendor/symfony/console/Command/Command.php:283 { …}
./vendor/symfony/console/Application.php:1033 { …}
./vendor/symfony/framework-bundle/Console/Application.php:96 { …}
./vendor/symfony/console/Application.php:299 { …}
./vendor/symfony/framework-bundle/Console/Application.php:82 { …}
./vendor/symfony/console/Application.php:171 { …}
./vendor/symfony/runtime/Runner/Symfony/ConsoleApplicationRunner.php:54 { …}
./vendor/autoload_runtime.php:35 { …}
./bin/console:11 {
›
› require_once dirname(__DIR__).'/vendor/autoload_runtime.php';
› // ./vendor/symfony/maker-bundle/src/Doctrine/DoctrineHelper.php
public function getEntitiesForAutocomplete(): array
{
$entities = [];
if ($this->isDoctrineInstalled()) {
$allMetadata = $this->getMetadata(); // will generate the error |
adding a try-catch on line 187 get rid of the message, Entities AutoComplete still works in console. try{
$classNames->setValue($annotationDriver, null);
} catch(\Throwable $th){} maker-bundle/src/Doctrine/DoctrineHelper.php Lines 180 to 190 in c557553
I don't understand, on line 181 we set |
The diff --git a/src/Doctrine/DoctrineHelper.php b/src/Doctrine/DoctrineHelper.php
index 8c05db2..48cdad6 100644
--- a/src/Doctrine/DoctrineHelper.php
+++ b/src/Doctrine/DoctrineHelper.php
@@ -177,14 +177,17 @@ final class DoctrineHelper
*/
public function getMetadata(string $classOrNamespace = null, bool $disconnected = false)
{
- $classNames = (new \ReflectionClass(AnnotationDriver::class))->getProperty('classNames');
- $classNames->setAccessible(true);
-
// Invalidating the cached AnnotationDriver::$classNames to find new Entity classes
foreach ($this->mappingDriversByPrefix ?? [] as $managerName => $prefixes) {
foreach ($prefixes as [$prefix, $annotationDriver]) {
if (null !== $annotationDriver) {
- $classNames->setValue($annotationDriver, null);
+ $refl = new \ReflectionClass($annotationDriver);
+
+ if ($refl->hasProperty('classNames')) {
+ $classNames = (new \ReflectionClass($annotationDriver))->getProperty('classNames');
+ $classNames->setAccessible(true);
+ $classNames->setValue($annotationDriver, null);
+ }
}
}
}
@@ -218,7 +221,11 @@ final class DoctrineHelper
$metadataDriver = $em->getConfiguration()->getMetadataDriverImpl();
if ($this->isInstanceOf($metadataDriver, MappingDriverChain::class)) {
foreach ($metadataDriver->getDrivers() as $driver) {
- if ($this->isInstanceOf($driver, AnnotationDriver::class)) {
+ $refl = new \ReflectionClass($driver);
+
+ if ($refl->hasProperty('classNames')) {
+ $classNames = (new \ReflectionClass($driver))->getProperty('classNames');
+ $classNames->setAccessible(true);
$classNames->setValue($driver, null);
}
} |
This worked for me :
|
This worked for me: |
Merci/thanks. |
Oui cela fonctionne. Merci pour l'indication je suis une grande débutante... |
downgrade works fine, but I hope doctrine developers will release a new version soon. |
Well, the issue is not in doctrine but in MakerBundle. When you use Reflection to access internal parts of a class, you cannot expect it to be covered by BC. |
maker bundle was updated yesterday
but it still doesn't works !!!
|
Thanks, this work fine for me ! |
Well, the release of MakerBundle of yesterday fixes other things, but not that bug. Nobody has opened a PR with a fix yet. |
A fix is in the works for this in #1098 or possibly a subsequent PR |
While a proper fix is being worked on, maybe e hotfix release could be released with makerbundle's composer.json adding a conflict with doctrine/orm": "2.12.0" |
Symfony version(s) affected
5.4.7
Description
Symfony make entity command results in Exception
symfony console make:entity
[critical] Error thrown while running command "make:entity". Message: "Cannot access protected property Doctrine\ORM\Mapping\Driver\AttributeDriver::$classNames"
How to reproduce
Possible Solution
No response
Additional Context
No response
The text was updated successfully, but these errors were encountered: