phpsymfonydoctrine-ormdoctrine

Doctrine Using short namespace alias "App:MyEntity" Problem: Feature deprecated in doctrine/persistence 2.x and is not supported by persistence:3.x


I am updating and developing a CLI function in my sf 6.4 project, and it returns :

In NotSupported.php line 31:
                                                                                                                          
  Context: Using short namespace alias "App:SampleNature" when calling Doctrine\ORM\EntityManager::getRepository          
  Problem: Feature was deprecated in doctrine/persistence 2.x and is not supported by installed doctrine/persistence:3.x  
  Solution: See the doctrine/deprecations logs for new alternative approaches.

Here are command code with line that call entityManager :

<?php

namespace App\Command;

use App\Entity\SampleNature;
…
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
…

#[AsCommand(name: 'app:migrate-samples-results')]
class MigrateResultsCommand extends Command
{
    private $entityManager;

    public function __construct(EntityManagerInterface $entityManager)
    {
        $this->entityManager = $entityManager;
        parent::__construct();
    }

    public function getCursorResult(SymfonyStyle $terminal, $fp_recept, $fp_result) {
         … 
         // LINE BELOW THAT MAKE THIS ISSUE
         $nature = $this->entityManager->getRepository('App:SampleNature')->findOneBy($nature_ech);
         …
     }
     …
}

doctrine version :

composer show -i | grep doctrine
You are using the deprecated option "installed". Only installed packages are shown by default now. The --all option can be used to show all packages.
doctrine/annotations                2.0.1   Docblock Annotations Parser
doctrine/cache                      2.2.0   PHP Doctrine Cache library is a popular cache implementation that supports many different drivers such as redis, memcache, apc, mongodb and others.
doctrine/collections                2.2.2   PHP Doctrine Collections library that adds additional functionality on top of PHP arrays.
doctrine/common                     3.4.4   PHP Doctrine Common project is a library that provides additional functionality that other Doctrine projects depend on such as better reflection support, proxie...
doctrine/dbal                       3.9.0   Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection and management.
doctrine/deprecations               1.1.3   A small layer on top of trigger_error(E_USER_DEPRECATED) or PSR-3 logging with options to disable all deprecations or selectively for packages.
doctrine/doctrine-bundle            2.12.0  Symfony DoctrineBundle
doctrine/doctrine-migrations-bundle 3.3.1   Symfony DoctrineMigrationsBundle
doctrine/event-manager              2.0.1   The Doctrine Event Manager is a simple PHP event system that was built to be used with the various Doctrine projects.
doctrine/inflector                  2.0.10  PHP Doctrine Inflector is a small library that can perform string manipulations with regard to upper/lowercase and singular/plural forms of words.
doctrine/instantiator               2.0.0   A small, lightweight utility to instantiate objects in PHP without invoking their constructors
doctrine/lexer                      3.0.1   PHP Doctrine Lexer parser library that can be used in Top-Down, Recursive Descent Parsers.
doctrine/migrations                 3.8.0   PHP Doctrine Migrations project offer additional functionality on top of the database abstraction layer (DBAL) for versioning your database schema and easily de...
doctrine/orm                        2.19.6  Object-Relational-Mapper for PHP
doctrine/persistence                3.3.3   The Doctrine Persistence project is a set of shared interfaces and functionality that the different Doctrine object mappers share.
doctrine/sql-formatter              1.4.1   a PHP SQL highlighting library
symfony/doctrine-bridge             v6.4.10 Provides integration for Doctrine with various Symfony components
symfony/doctrine-messenger          v6.4.9  Symfony Doctrine Messenger Bridge

is a little bit confuse… if I understand correctly, I have doctrine orm 2.19, but persistence 3.3 !

Where can I find "doctrine/deprecations logs for new alternative approaches" ?

similar to https://github.com/symfony/symfony/issues/50481#issuecomment-1903987846_


Solution

  • After many researches, I first try to change :

      $nature = $this->entityManager->getRepository('App:SampleNature')->findOneBy($nature_ech);
    

    by

      $nature = $this->entityManager->getRepository('App\Entity\SampleNature')->findOneBy($nature_ech);
    

    an It works …

    EDIT : but the more common writing is as @ozahorulia suggest :

      $nature = $this->entityManager->getRepository(SampleNature::class)->findOneBy($nature_ech);
    

    without forget to remove quotation marks !-)