GithubHelp home page GithubHelp logo

doctrine / persistence Goto Github PK

View Code? Open in Web Editor NEW
3.9K 23.0 59.0 1.39 MB

The Doctrine Persistence project is a library that provides common abstractions for object mapper persistence.

Home Page: https://www.doctrine-project.org/projects/persistence.html

License: MIT License

PHP 100.00%
persistence hacktoberfest

persistence's Introduction

Doctrine Persistence

GitHub Actions Code Coverage

The Doctrine Persistence project is a library that provides common abstractions for object mapper persistence.

More resources:

persistence's People

Contributors

alcaeus avatar beberlei avatar derrabus avatar docteurklein avatar drupol avatar eduardosoliv avatar franmomu avatar greg0ire avatar gries avatar guilhermeblanco avatar jwage avatar lcobucci avatar lsmith77 avatar majkl578 avatar malarzm avatar mnapoli avatar nicolas-grekas avatar ocramius avatar ondrejmirtes avatar ostrolucky avatar phansys avatar ptlis avatar rdohms avatar romanb avatar schmittjoh avatar senseexception avatar stof avatar toby-griffiths avatar tofandel avatar vincentlanglet avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

persistence's Issues

Deprecation warnings for multiple classes in Doctrine\Common\*

I'm developing a Symfony 4.4 web app. After upgrading doctrine/persistence to 1.3.3, 10 deprecation warnings appeared on the Symfony Profiler. I couldn't figure out where they come from.

User Deprecated: The Doctrine\Common\Persistence\ObjectRepository class is deprecated since doctrine/persistence 1.3 and will be removed in 2.0. Use \Doctrine\Persistence\ObjectRepository instead.

User Deprecated: The Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory class is deprecated since doctrine/persistence 1.3 and will be removed in 2.0. Use \Doctrine\Persistence\Mapping\AbstractClassMetadataFactory instead.

User Deprecated: The Doctrine\Common\PropertyChangedListener class is deprecated since doctrine/persistence 1.3 and will be removed in 2.0. Use \Doctrine\Persistence\PropertyChangedListener instead.

User Deprecated: The Doctrine\Common\Persistence\Mapping\RuntimeReflectionService class is deprecated since doctrine/persistence 1.3 and will be removed in 2.0. Use \Doctrine\Persistence\Mapping\RuntimeReflectionService instead.

User Deprecated: The Doctrine\Common\Persistence\Proxy class is deprecated since doctrine/persistence 1.3 and will be removed in 2.0. Use \Doctrine\Persistence\Proxy instead.

User Deprecated: The Doctrine\Common\Persistence\Event\LoadClassMetadataEventArgs class is deprecated since doctrine/persistence 1.3 and will be removed in 2.0. Use \Doctrine\Persistence\Event\LoadClassMetadataEventArgs instead.

The Doctrine\Common\Persistence\ObjectRepository class is deprecated since doctrine/persistence 1.3 and will be removed in 2.0. Use \Doctrine\Persistence\ObjectRepository instead.

The Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory class is deprecated since doctrine/persistence 1.3 and will be removed in 2.0. Use \Doctrine\Persistence\Mapping\AbstractClassMetadataFactory instead.

The Doctrine\Common\PropertyChangedListener class is deprecated since doctrine/persistence 1.3 and will be removed in 2.0. Use \Doctrine\Persistence\PropertyChangedListener instead.

The Doctrine\Common\Persistence\Mapping\RuntimeReflectionService class is deprecated since doctrine/persistence 1.3 and will be removed in 2.0. Use \Doctrine\Persistence\Mapping\RuntimeReflectionService instead.

This is the context and trace of the first one (ObjectRepository):

[▼
  "exception" => ErrorException {#249 ▼
    #message: "User Deprecated: The Doctrine\Common\Persistence\ObjectRepository class is deprecated since doctrine/persistence 1.3 and will be removed in 2.0. Use \Doctrine\Persistence\ObjectRepository instead."
    #code: 0
    #file: "/var/www/html/kabum/vendor/doctrine/persistence/lib/Doctrine/Common/Persistence/ObjectRepository.php"
    #line: 16
    #severity: E_USER_DEPRECATED
    trace: {▼
      /var/www/html/kabum/vendor/doctrine/persistence/lib/Doctrine/Common/Persistence/ObjectRepository.php:16 {▶}
      /var/www/html/kabum/vendor/doctrine/orm/lib/Doctrine/ORM/EntityRepository.php:41 {▶}
      spl_autoload_call() {}
      /var/www/html/kabum/vendor/doctrine/orm/lib/Doctrine/ORM/Configuration.php:683 {▶}
      /var/www/html/kabum/var/cache/dev/Container7xVDri3/srcApp_KernelDevDebugContainer.php:933 {▼
        Container7xVDri3\srcApp_KernelDevDebugContainer->getDoctrine_Orm_DefaultEntityManagerService($lazyLoad = true) …
        › $a->setClassMetadataFactoryName('Doctrine\\ORM\\Mapping\\ClassMetadataFactory');
        › $a->setDefaultRepositoryClassName('Doctrine\\ORM\\EntityRepository');
        › $a->setNamingStrategy(new \Doctrine\ORM\Mapping\UnderscoreNamingStrategy(0, true));
      }
      /var/www/html/kabum/var/cache/dev/Container7xVDri3/srcApp_KernelDevDebugContainer.php:2269 {▶}
      /var/www/html/kabum/var/cache/dev/Container7xVDri3/srcApp_KernelDevDebugContainer.php:5124 {▶}
      /var/www/html/kabum/vendor/symfony/dependency-injection/Container.php:444 {▶}
      /var/www/html/kabum/vendor/symfony/dependency-injection/Argument/ServiceLocator.php:40 {▶}
      /var/www/html/kabum/vendor/symfony/security-bundle/Security/FirewallMap.php:80 {▶}
      /var/www/html/kabum/vendor/symfony/security-bundle/Security/FirewallMap.php:54 {▶}
      /var/www/html/kabum/vendor/symfony/security-bundle/EventListener/FirewallListener.php:50 {▶}
      /var/www/html/kabum/vendor/symfony/event-dispatcher/Debug/WrappedListener.php:126 {▶}
      /var/www/html/kabum/vendor/symfony/event-dispatcher/EventDispatcher.php:264 {▶}
      /var/www/html/kabum/vendor/symfony/event-dispatcher/EventDispatcher.php:239 {▶}
      /var/www/html/kabum/vendor/symfony/event-dispatcher/EventDispatcher.php:73 {▶}
      /var/www/html/kabum/vendor/symfony/event-dispatcher/Debug/TraceableEventDispatcher.php:168 {▶}
      /var/www/html/kabum/vendor/symfony/http-kernel/HttpKernel.php:122 {▶}
      /var/www/html/kabum/vendor/symfony/http-kernel/HttpKernel.php:68 {▶}
      /var/www/html/kabum/vendor/symfony/http-kernel/Kernel.php:201 {▶}
      /var/www/html/kabum/public/index.php:25 {▶}
    }
  }
]

Issue with PHP 7.4

Hello,

We're trying to migrate our project to PHP 7.4 and we face a issue

PHP Warning:  Invalid argument supplied for foreach() in /var/www/myproject/vendor/doctrine/persistence/lib/Doctrine/Persistence/Mapping/Driver/AnnotationDriver.php on line 179

I was able to create a test project which you can reproduce it. (Sorry, it's an old version of Symfony, I tried to keep same structure of our production project)

git clone [email protected]:AntoineLemaire/doctrine-annotation-issue.git
cd doctrine-annotation-issue
composer install --optimize-autoloader --no-progress --ansi --prefer-dist --no-suggest

Then, when you do several times app/console cache:warmup --no-interaction --env=dev --no-debug, after few tries you got this error

image

I tried with the exact same project & PHP 7.3, and I didn't had any issue.

Here the stack:

  • symfony/symfony 3.4.20 (we're stuck at this version at the moment)
  • PHP 7.4.13
  • Composer 1.10.8
  • doctrine/annotations 1.11.1

AnnotationDriver::isTransient() method exception with PHP8 attributes

With Doctrine ORM 2.9 released AnnotationDriver::isTransient() is throwing error in the following scenario:

  1. DoctrineBundle is updated to the latest dev because of this: doctrine/DoctrineBundle#1354
  2. attribute is set for entity mapping types
  3. Following indexes added to one of the entity classes:
    #[ORM\Index(fields: ["customer"])]
    #[ORM\Index(fields: ["addressTableId","addressRecordId","addressNumber"])]

Exception trace:

TypeError: get_class(): Argument #1 ($object) must be of type object, array given
  at /srv/www/vendor/doctrine/persistence/lib/Doctrine/Persistence/Mapping/Driver/AnnotationDriver.php:188
  at Doctrine\Persistence\Mapping\Driver\AnnotationDriver->isTransient()
     (/srv/www/vendor/doctrine/persistence/lib/Doctrine/Persistence/Mapping/Driver/MappingDriverChain.php:136)
  at Doctrine\Persistence\Mapping\Driver\MappingDriverChain->isTransient()
     (/srv/www/vendor/doctrine/doctrine-bundle/Mapping/MappingDriver.php:37)
  at Doctrine\Bundle\DoctrineBundle\Mapping\MappingDriver->isTransient()
     (/srv/www/vendor/doctrine/persistence/lib/Doctrine/Persistence/Mapping/AbstractClassMetadataFactory.php:462)
  at Doctrine\Persistence\Mapping\AbstractClassMetadataFactory->isTransient()
     (/srv/www/vendor/doctrine/persistence/lib/Doctrine/Persistence/AbstractManagerRegistry.php:182)
  at Doctrine\Persistence\AbstractManagerRegistry->getManagerForClass()
     (/srv/www/vendor/api-platform/core/src/Bridge/Doctrine/Orm/Metadata/Property/DoctrineOrmPropertyMetadataFactory.php:48)
  at ApiPlatform\Core\Bridge\Doctrine\Orm\Metadata\Property\DoctrineOrmPropertyMetadataFactory->create()
     (/srv/www/vendor/api-platform/core/src/Metadata/Property/Factory/SerializerPropertyMetadataFactory.php:51)
  at ApiPlatform\Core\Metadata\Property\Factory\SerializerPropertyMetadataFactory->create()
     (/srv/www/vendor/api-platform/core/src/Metadata/Property/Factory/DefaultPropertyMetadataFactory.php:37)
  at ApiPlatform\Core\Metadata\Property\Factory\DefaultPropertyMetadataFactory->create()
     (/srv/www/vendor/api-platform/core/src/Metadata/Property/Factory/AnnotationSubresourceMetadataFactory.php:45)
  at ApiPlatform\Core\Metadata\Property\Factory\AnnotationSubresourceMetadataFactory->create()
     (/srv/www/vendor/api-platform/core/src/Metadata/Property/Factory/AnnotationPropertyMetadataFactory.php:46)
  at ApiPlatform\Core\Metadata\Property\Factory\AnnotationPropertyMetadataFactory->create()
     (/srv/www/vendor/api-platform/core/src/Metadata/Property/Factory/ExtractorPropertyMetadataFactory.php:46)
  at ApiPlatform\Core\Metadata\Property\Factory\ExtractorPropertyMetadataFactory->create()
     (/srv/www/vendor/api-platform/core/src/Bridge/Symfony/Validator/Metadata/Property/ValidatorPropertyMetadataFactory.php:92)
  at ApiPlatform\Core\Bridge\Symfony\Validator\Metadata\Property\ValidatorPropertyMetadataFactory->create()
     (/srv/www/vendor/api-platform/core/src/Metadata/Property/Factory/CachedPropertyMetadataFactory.php:47)
  at ApiPlatform\Core\Metadata\Property\Factory\CachedPropertyMetadataFactory->ApiPlatform\Core\Metadata\Property\Factory\{closure}()
     (/srv/www/vendor/api-platform/core/src/Cache/CachedTrait.php:44)
  at ApiPlatform\Core\Metadata\Property\Factory\CachedPropertyMetadataFactory->getCached()
     (/srv/www/vendor/api-platform/core/src/Metadata/Property/Factory/CachedPropertyMetadataFactory.php:48)
  at ApiPlatform\Core\Metadata\Property\Factory\CachedPropertyMetadataFactory->create()
     (/srv/www/vendor/api-platform/core/src/Api/IdentifiersExtractor.php:55)
  at ApiPlatform\Core\Api\IdentifiersExtractor->getIdentifiersFromResourceClass()
     (/srv/www/vendor/api-platform/core/src/Api/CachedIdentifiersExtractor.php:60)
  at ApiPlatform\Core\Api\CachedIdentifiersExtractor->getIdentifiersFromResourceClass()
     (/srv/www/vendor/api-platform/core/src/Bridge/Symfony/Routing/ApiLoader.php:231)
  at ApiPlatform\Core\Bridge\Symfony\Routing\ApiLoader->addRoute()
     (/srv/www/vendor/api-platform/core/src/Bridge/Symfony/Routing/ApiLoader.php:104)
  at ApiPlatform\Core\Bridge\Symfony\Routing\ApiLoader->load()
     (/srv/www/vendor/symfony/config/Loader/FileLoader.php:158)
  at Symfony\Component\Config\Loader\FileLoader->doImport()
     (/srv/www/vendor/symfony/config/Loader/FileLoader.php:97)
  at Symfony\Component\Config\Loader\FileLoader->import()
     (/srv/www/vendor/symfony/routing/Loader/YamlFileLoader.php:196)
  at Symfony\Component\Routing\Loader\YamlFileLoader->parseImport()
     (/srv/www/vendor/symfony/routing/Loader/YamlFileLoader.php:90)
  at Symfony\Component\Routing\Loader\YamlFileLoader->load()
     (/srv/www/vendor/symfony/config/Loader/FileLoader.php:158)
  at Symfony\Component\Config\Loader\FileLoader->doImport()
     (/srv/www/vendor/symfony/config/Loader/FileLoader.php:97)
  at Symfony\Component\Config\Loader\FileLoader->import()
     (/srv/www/vendor/symfony/routing/Loader/GlobFileLoader.php:32)
  at Symfony\Component\Routing\Loader\GlobFileLoader->load()
     (/srv/www/vendor/symfony/routing/RouteCollectionBuilder.php:360)
  at Symfony\Component\Routing\RouteCollectionBuilder->load()
     (/srv/www/vendor/symfony/routing/RouteCollectionBuilder.php:65)
  at Symfony\Component\Routing\RouteCollectionBuilder->import()
     (/srv/www/src/Kernel.php:51)
  at App\Kernel->configureRoutes()
     (/srv/www/vendor/symfony/framework-bundle/Kernel/MicroKernelTrait.php:191)
  at App\Kernel->loadRoutes()
     (/srv/www/vendor/symfony/routing/Loader/ObjectLoader.php:62)
  at Symfony\Component\Routing\Loader\ObjectLoader->load()
     (/srv/www/vendor/symfony/config/Loader/DelegatingLoader.php:40)
  at Symfony\Component\Config\Loader\DelegatingLoader->load()
     (/srv/www/vendor/symfony/framework-bundle/Routing/DelegatingLoader.php:69)
  at Symfony\Bundle\FrameworkBundle\Routing\DelegatingLoader->load()
     (/srv/www/vendor/symfony/framework-bundle/Routing/Router.php:68)
  at Symfony\Bundle\FrameworkBundle\Routing\Router->getRouteCollection()
     (/srv/www/vendor/symfony/routing/Router.php:350)
  at Symfony\Component\Routing\Router->getGeneratorDumperInstance()
     (/srv/www/vendor/symfony/routing/Router.php:324)
  at Symfony\Component\Routing\Router->Symfony\Component\Routing\{closure}()
     (/srv/www/vendor/symfony/config/ResourceCheckerConfigCacheFactory.php:39)
  at Symfony\Component\Config\ResourceCheckerConfigCacheFactory->cache()
     (/srv/www/vendor/symfony/routing/Router.php:327)
  at Symfony\Component\Routing\Router->getGenerator()
     (/srv/www/vendor/symfony/routing/Router.php:235)
  at Symfony\Component\Routing\Router->generate()
     (/srv/www/vendor/api-platform/core/src/Bridge/Symfony/Routing/Router.php:106)
  at ApiPlatform\Core\Bridge\Symfony\Routing\Router->generate()
     (/srv/www/vendor/api-platform/core/src/Hydra/EventListener/AddLinkHeaderListener.php:50)
  at ApiPlatform\Core\Hydra\EventListener\AddLinkHeaderListener->onKernelResponse()
     (/srv/www/vendor/symfony/event-dispatcher/Debug/WrappedListener.php:117)
  at Symfony\Component\EventDispatcher\Debug\WrappedListener->__invoke()
     (/srv/www/vendor/symfony/event-dispatcher/EventDispatcher.php:230)
  at Symfony\Component\EventDispatcher\EventDispatcher->callListeners()
     (/srv/www/vendor/symfony/event-dispatcher/EventDispatcher.php:59)
  at Symfony\Component\EventDispatcher\EventDispatcher->dispatch()
     (/srv/www/vendor/symfony/event-dispatcher/Debug/TraceableEventDispatcher.php:151)
  at Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher->dispatch()
     (/srv/www/vendor/symfony/http-kernel/HttpKernel.php:190)
  at Symfony\Component\HttpKernel\HttpKernel->filterResponse()
     (/srv/www/vendor/symfony/http-kernel/HttpKernel.php:178)
  at Symfony\Component\HttpKernel\HttpKernel->handleRaw()
     (/srv/www/vendor/symfony/http-kernel/HttpKernel.php:79)
  at Symfony\Component\HttpKernel\HttpKernel->handle()
     (/srv/www/vendor/symfony/http-kernel/EventListener/ErrorListener.php:60)
  at Symfony\Component\HttpKernel\EventListener\ErrorListener->onKernelException()
     (/srv/www/vendor/symfony/event-dispatcher/Debug/WrappedListener.php:117)
  at Symfony\Component\EventDispatcher\Debug\WrappedListener->__invoke()
     (/srv/www/vendor/symfony/event-dispatcher/EventDispatcher.php:230)
  at Symfony\Component\EventDispatcher\EventDispatcher->callListeners()
     (/srv/www/vendor/symfony/event-dispatcher/EventDispatcher.php:59)
  at Symfony\Component\EventDispatcher\EventDispatcher->dispatch()
     (/srv/www/vendor/symfony/event-dispatcher/Debug/TraceableEventDispatcher.php:151)
  at Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher->dispatch()
     (/srv/www/vendor/symfony/http-kernel/HttpKernel.php:218)
  at Symfony\Component\HttpKernel\HttpKernel->handleThrowable()
     (/srv/www/vendor/symfony/http-kernel/HttpKernel.php:111)
  at Symfony\Component\HttpKernel\HttpKernel->terminateWithException()
     (/srv/www/vendor/symfony/http-kernel/EventListener/DebugHandlersListener.php:127)
  at Symfony\Component\HttpKernel\EventListener\DebugHandlersListener::Symfony\Component\HttpKernel\EventListener\{closure}()
     (/srv/www/vendor/symfony/error-handler/ErrorHandler.php:607)
  at Symfony\Component\ErrorHandler\ErrorHandler->handleException()

It turns out $annot here can be an array also with attributes:

if (isset($this->entityAnnotationClasses[get_class($annot)])) {

The Index attribute is tried according to this release documentation: https://www.doctrine-project.org/2021/05/24/orm2.9.html

Exception: Target ManagerRegistry is not instantiable

Hi there!

I'm getting a weird error when I updated the package to version "1.3.3". Working with Laravel 6 version and Doctrine, tried to do the composer update and getting the following error:

Illuminate\Contracts\Container\BindingResolutionException : Target [Doctrine\Persistence\ManagerRegistry] is not instantiable while building [App\Console\Commands\SomeCommand, App\Support\EntityManager].

In my construct() method I inject the Doctrine\Common\Persistence\ManagerRegistry class. When I downgrade to version "1.2.0" everything works fine. Any help with this? Thank you!

Merge is deprecated

DuckDuckGo tells me to use merge operation to issue UPDATE: Screenshot_20200831_133148

Your annotation tells me:

     * @deprecated Merge operation is deprecated and will be removed in Persistence 2.0.
     *             Merging should be part of the business domain of an application rather than
     *             a generic operation of ObjectManager.

I don't see the rationale why you don't want to support generalized UPDATE SQL generation any longer.

Error On Composer Update: MappingDriverChain not Found

Uncaught Error: Class 'Doctrine\Common\Persistence\Mapping\D
river\MappingDriverChain' not found in /var/customers/webs/../../var/cache/prod/ContainerQ67jQdQ/getDoctrine_Orm_DefaultEntityManage
rService.php:51
Maybe missing use ?

Cannot convert cache to PSR-6 cache

Hi. Since version 2.2.0 I have a bug:

Cannot convert cache to PSR-6 cache

Type: BadMethodCallException
File: Packages/Libraries/doctrine/persistence/lib/Doctrine/Persistence/Mapping/AbstractClassMetadataFactory.php
Line: 91

Support for Mapping Files on Traits

Traits allows to write reusable piece of code defing common fields.

Using php annotations is already possible to inherit fields definition in our enties.

We should support XML and YAML mapping files too.

Cache key contains reserved characters

Hello,

After upgrading to doctrine persistence 3, i have this error on cache clear:

In CacheItem.php line 159:
!!
!!    Cache key "AppBundle:EntityName__CLASSMETADATA__" contains reserved
!!    characters "{}()/\@:".

I looked at https://github.com/doctrine/persistence/blob/3.0.x/UPGRADE.md#upgrade-to-30 to upgrade correctly.

I thought it was my configuration:

naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware

But it's not that.

EDIT: I am not sure issue should be here 🤔

Thank you.

question: Why doesn't repository contain save method?

I had a discussion with my colleagues about repositories that are designed in doctrine for queries only.
They are agree with that repositories in common means add/find but as they said

repositories in doctrine mean something particular and that's why ObjectRepository doesn't contain any persist/remove methods.

I'm pretty sure repositories mean to have add/remove methods so I wonder why doctrine/persistence ObjectRepository doesn't have those?

Error in Composer dependencies / incompatibility with `symfony/security-core`

I think there's something wrong with composer dependencies somewhere. I can't tell you the exact source - I can only tell you what I've observed:

In the beggining, I have this in my composer.json (only showing doctrine/* and symfony/security-*):

"doctrine/annotations": "^1.8",
"doctrine/dbal": "^2.12",
"doctrine/orm": "^2.7",
"symfony/security-bundle": "4.4.*",

...and this is contained in the output of composer show:

doctrine/persistence  1.3.8
symfony/security-core v4.4.15

Now, if I add "symfony/security-core": "4.4.*", to composer.json and run composer update, this happens:

Lock file operations: 0 installs, 3 updates, 1 removal
  - Removing doctrine/reflection (1.2.1)
  - Upgrading doctrine/common (2.13.3 => 3.0.2)
  - Upgrading doctrine/persistence (1.3.8 => 2.1.0)
  - Downgrading symfony/orm-pack (v1.2.0 => v1.1.0)

(which breaks my project, due to https://stackoverflow.com/q/63688919/1668200)

But then, if I also add "doctrine/persistence": "^1.3", to composer.json and run composer update, the downgrade is magically undone:

Lock file operations: 1 install, 3 updates, 0 removals
  - Downgrading doctrine/common (3.0.2 => 2.13.3)
  - Downgrading doctrine/persistence (2.1.0 => 1.3.8)
  - Locking doctrine/reflection (1.2.1)
  - Upgrading symfony/orm-pack (v1.1.0 => v1.2.0)

Should there be an AbstractConnectionRegistry?

It appears that the ManagerRegistry interface extends the ConnectionRegistry. It feels a bit like the AbstractManagerRegistry should extend an AbstractConnectionRegistry so they could be overloaded at either point. If someone wanted just a ConnectionRegistry it would be easier to work with.

Unexpected response returned from `AbstractManagerRegistry::getManagerNames()`

The ManagerRegistry::getManagerNames() should return An array of object manager names. string[]

/**
* Gets all object manager names.
*
* @return string[] An array of object manager names.
*/
public function getManagerNames();

But the implementation in AbstractManagerRegistry returns an array of serviceId indexed by name.

public function getManagerNames()
{
return $this->managers;
}

I'm not sure what is the expected response. I would expect that getManagerNames returned ['foo', 'bar']. I would expect such code worked: But this is not the case.

foreach ($this->registry->getManagerNames() as $name) {
  dump($this->registry->getManager($name));
}

But fixing it in the AbstractManagerRegistry class could be a BC break.
Otherwise, we should improve the documentation of the interface.

Support returning a function when using the PhpDriver

When defining ORM mapping using the php driver there is $metadata variable floating around in the mapping file. IDE's complain about type hinting.

It would be nice to be able to return a static function that gets the $metadata variable as an argument, so then you can write the mapping in php like this:

// config/orm/mapping/App.Entity.User.php

<?php

use Doctrine\ORM\Mapping\Builder\ClassMetadataBuilder;
use Doctrine\ORM\Mapping\ClassMetadata;

return static function (ClassMetadata $metadata): void
{
    $builder = new ClassMetadataBuilder($metadata);
    
    // ...
};

I modified the PHP driver to be able to do this (lib/Doctrine/Persistence/Mapping/Driver/PHPDriver.php):

// ...
    protected function loadMappingFile($file)
    {
        $metadata = $this->metadata;
        $mapping = include $file;
    
        if (is_callable($mapping)) {
            $mapping($metadata);
        }

        return [$metadata->getName() => $metadata];
    }
// ...

Is there any argument against doing this? The big advantage here is that you at least have a type hint.

DCOM-287: [GH-369] [RFC] Load parent classes when loading metadata from cache

Jira issue originally created by user @doctrinebot:

This issue is created automatically through a Github pull request on behalf of gonzalovilaseca:

Url: doctrine/common#369

Message:

This can be done more neatly, but before putting more time in it I'd like to check if it's a good idea.
I came across this solution because we had a problem with Gedmo extensions when caching metadata in Redis, this is our scenario:

Class A extends B;

Class B has a Gedmo extension mapped field.

On first request metadata for both Class A and Class B is cached in Redis.

On second request AbstractClassMetadataFactory loads Class A from Redis.

Gedmo extension loops through all Class A parents and calls method hasMetadataFor($parentClass) in AbstractClassMetadataFactory, only Class A metadata has been loaded previously, therefore hasMetadataFor($parentClass) returns false, and Gedmo then skips the parent class.

Should Gedmo exension load the metadata for the parent class or should it be done as proposed in this PR?

Adding not-nullable search methods to ObjectRepository

I'm currently in the process of improving my codebase with static analysis (PHPStan in this case), and I've found an interesting use case to improve the ObjectRepository interface: I find it pretty annoying have to specify/check each time that I don't expect null values from my find()/findOneBy() methods etc, so it would be nice if there was some get*() twin methods for which a nullable return would not be allowed.

This is obviously a BC, so it should target 3.0, hence leveraging nullable types from PHP 7.1 it would make really sense.... What do you think?

PS: since we already have doctrine/common#826 doctrine/common#738 etc, maybe we can create a 3.0 milestone?

Deprecate short namespace aliases

As in doctrine/orm#8818.

There are at least a couple of places:

// Check for namespace alias
if (strpos($classNameOrAlias, ':') !== false) {
[$namespaceAlias, $simpleClassName] = explode(':', $classNameOrAlias, 2);
/** @psalm-var class-string */
return $this->getAliasNamespace($namespaceAlias) . '\\' . $simpleClassName;
}

if (strpos($className, ':') !== false) {
[$namespaceAlias, $simpleClassName] = explode(':', $className, 2);
$realClassName = $this->getFqcnFromAlias($namespaceAlias, $simpleClassName);

if (strpos($class, ':') !== false) {
[$namespaceAlias, $simpleClassName] = explode(':', $class, 2);
$class = $this->getFqcnFromAlias($namespaceAlias, $simpleClassName);
}

StaticPHP driver quoting reserved SQL keyword problem

Hi,

We are having a problem with a database column name. The column's name is default which is an SQL reserved keyword. We are using the StaticPHP metadata driver.

According to the docs this should be fixable by manually quoting the column name with backticks. The official docs provide an annotation example, but this is not useful to us.

We are getting the follow exception:

ReflectionException
Property App\Printer\Entities\Printer::$`default` does not exist

Thanks in advance,

AnnotationDriver is not loading entities from symlinked directories

Entity directory structure (AppBundle/Entity)

  • Blog (directory)
    • Post.php
  • Blog2 (symlink)
    • Post2.php

Mapping loaded from AnnotationDriver (e.g. via symfony's bin/console doctrine:mapping:info) will display info for Post but not for Post2 because Blog2 is symlinked.

\RecursiveDirectoryIterator::FOLLOW_SYMLINKS flag need to be passed to RecursiveDirectoryIterator to fix this.

To reproduce this in symfony:

symfony new symlinkedEntities
composer install
bin/console doctrine:gen:entity --entity=AppBundle:Blog/Post --format=annotation --fields="title:string(length=255 nullable=true unique=true)" --no-interaction
# set DB params adn then
bin/console doc:data:create
# works
bin/console doctrine:gen:entities AppBundle:Blog

# does not work
mv src/AppBundle/Entity/Blog .
ln -s FULL_PATH/symlinkedEntities/Blog src/AppBundle/Entity/Blog
bin/console doctrine:gen:entities AppBundle:Blog

Generating entities for namespace "AppBundle\Entity\Blog"
[RuntimeException]
Namespace "AppBundle\Entity\Blog" does not contain any mapped entities.

Object that are not entities are checked for Metadata without cache

This is a followup of doctrine/dbal#3838, I just want to check if maintainers see a room for improvement.

TL;DR: when we check metadata for doctrine entities, there is a cache that prevents checking for metadata across requests and there is memoization to prevent hitting on the cache. When passing objects that are not doctrine entities with fallback there is no cache but memoization, and without fallback there is none of that.

There are at least two paths that trigger that behavior (just to show that this is not an easy fix in userland):

1/ doctrine query with datetime parameter without the third parameter "datetime" (dev and prod)

$q = $em->createQuery('SELECT d from App\Entity\DataSample d WHERE d.referenceDate = :date');
$q->setParameter('date', Carbon::now(), 'datetime');

This is fixable in userland, but quite not fun.

This is a blackfire profile in prod env with 20 sql requests with a datetime parameter WITHOUT the third parameter set. The after is a simple test at the beginning of the getMetadataFor to avoid loading the metadata stack:

        if ($className === 'DateTime') {
            throw new MappingException();
        }

image

2/ symfony validation (dev only)

3/ doctrine embedable classes


I don't know the best fix for that but I figures that on the life on a request / cache, this should not happen. Even I who know this bug, I forgot to add the third parameter, it should really be resolved in doctrine/persistence.

We could:

  • cache the exception and add some instanceof / throw somewhere.
  • cache null and return an exception if null, we should change the isset by array_key_exists

Add support for generics via static analysis

As was done in doctrine/collections, we should add support for generics using the @psalm-template annotations for generic classes like Repositories and Registries. We should also ensure that generics in PHPStan are supported as well.

See doctrine/collections#177 for the reference implementation in collections.

Throw exception in getManagerForClass when multiple entity managers manage the same entity

This came to me while reading through symfony/symfony-docs#9878. In a few of those cases, people have the same entity managed by multiple entity managers. While I'm not sure whether that constitutes a valid use-case, the manager registry is equipped to handle this by allowing to specify en entity manager to use when calling AbstractManagerRegistry::getRepository.

However, AbstractManagerRegistry::getManagerForClass handles those cases wrong IMO: it simply returns the first entity manager that manages the entity in question. In cases like the above, this can lead to undesired behaviour as we're ignoring the fact that we can't reliably say which entity manager is responsible for.a given class.

Assuming the use-case of having the same entity managed by multiple entity managers is valid, we should throw an exception in getManagerForClass if we realise that the same class is managed by more than a single entity manager.

Make the annotation driver to work with phars under Windows

The current implementation of AnnotationDriver doesn't work in Windows when the application runs inside a phar.

The RecursiveDirectoryIterator at line 221 will search in subdirectories of $path, but under Windows entities and repositories get a backslash after the path:

phar://path/to/phar/src/AppBundle\MyEntity.php

Because of the check at line 247 the entity is simply ignored (ReflectionClass always returns forward slashes because source file is inside the phar itself)

phar://path/to/phar/src/AppBundle/MyEntity.php

I think it will be enough a replace when iterating file files (the same is done at line 228):

foreach ($iterator as $file) {
    $sourceFile = str_replace('\\', '/', $file[0]);

    // ...
}

Compile Error: Declaration of Doctrine XmlDriver

Symfony 4.4, on composer u i got this:

  • Updating doctrine/persistence (1.2.0 => 1.3.0): Loading from cache
    !! In XmlDriver.php line 881:
    !!
    !! Compile Error: Declaration of Doctrine\ORM\Mapping\Driver\XmlDriver::loadMe
    !! tadataForClass($className, Doctrine\Common\Persistence\Mapping\ClassMetadat
    !! a $metadata) must be compatible with Doctrine\Persistence\Mapping\Driver\Ma
    !! ppingDriver::loadMetadataForClass($className, Doctrine\Persistence\Mapping\
    !! ClassMetadata $metadata)

Add abstract manager registry supporting PSR-11 ContainerInterface

The current AbstractManagerRegistry implementation provides abstract getService and resetService methods to allow subclasses to implement their own logic how to retrieve connection and manager services. However, with PSR-11 defining a lightweight container interface, I believe it's best to deprecate AbstractManagerRegistry in favour of a ContainerManagerRegistry that takes a ContainerInterface in the constructor and forwards all calls to the ContainerInterface::get.

A basic example implementation for this would be the ManagerRegistry provided in the Symfony DoctrineBridge: https://github.com/symfony/symfony/blob/master/src/Symfony/Bridge/Doctrine/ManagerRegistry.php. There is some dark magic going on with resetService, where we'd have to discuss how to best solve this. Not sure why we need resetting services, but again, this shouldn't be an implementation detail of an abstract registry.

This new class could be added in 1.2 with the AbstractManagerRegistry potentially being deprecated in either the same release or in a subsequent 2.x release.

Fatal error when upgrading to 2.0.4 and using ORM

BC Break Report

When executing cache:clear after composer update there is PHP fatal error.

PHP Fatal error:  Declaration of Doctrine\ORM\MappingClassMetadataFactory::wakeupReflection(Doctrine\Common\Persistence\Mapping\ClassMetadata $class, Doctrine\Common\Persistence\Mapping\ReflectionService $reflService) must be compatible with Doctrine\Persistence\MappingAbstractClassMetadataFactory::wakeupReflection(Doctrine\Persistence\Mapping\ClassMetadata $class, Doctrine\Persistence\Mapping\ReflectionService $reflService) in /var/www/html/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php on line 797

PHP Stack trace:
1. {main}() /var/www/html/bin/console:0
2. Symfony\Bundle\FrameworkBundle\Console\Application->run() /var/www/html/bin/console:44
3. Symfony\Bundle\FrameworkBundle\Console\Application->doRun() /var/www/html/vendor/symfony/console/Application.php:148
4. Symfony\Bundle\FrameworkBundle\Console\Application->registerCommands() /var/www/html/vendor/symfony/framework-bundle/Console/Application.php:65
5. App\Kernel->boot() /var/www/html/vendor/symfony/framework-bundle/Console/Application.php:159
6. App\Kernel->initializeContainer() /var/www/html/vendor/symfony/http-kernel/Kernel.php:136
7. Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerAggregate->warmUp() /var/www/html/vendor/symfony/http-kernel/Kernel.php:658
8. ContainerEPFlGxJ\srcApp_KernelDevDebugContainer->{closure:/var/www/html/var/cache/dev/ContainerEPFlGxJ/getCacheWarmerService.php:12-25}() /var/www/html/vendor/symfony/http-kernel/CacheWarmer/CacheWarmerAggregate.php:89
9. ContainerEPFlGxJ\srcApp_KernelDevDebugContainer->load() /var/www/html/var/cache/dev/ContainerEPFlGxJ/getCacheWarmerService.php:17
10. require() /var/www/html/var/cache/dev/ContainerEPFlGxJ/srcApp_KernelDevDebugContainer.php:785
11. ContainerEPFlGxJ\srcApp_KernelDevDebugContainer->getValidator_BuilderService() /var/www/html/var/cache/dev/ContainerEPFlGxJ/getValidator_Mapping_CacheWarmerService.php:13
12. ContainerEPFlGxJ\srcApp_KernelDevDebugContainer->getDoctrine_Orm_DefaultEntityManagerService() /var/www/html/var/cache/dev/ContainerEPFlGxJ/srcApp_KernelDevDebugContainer.php:3127
13. Doctrine\ORM\EntityManager::create() /var/www/html/var/cache/dev/ContainerEPFlGxJ/srcApp_KernelDevDebugContainer.php:1111
14. Doctrine\ORM\EntityManager->__construct() /var/www/html/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php:873
15. spl_autoload_call() /var/www/html/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php:159
16. Symfony\Component\Debug\DebugClassLoader->loadClass() /var/www/html/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php:159

In ClassMetadataFactory.php line 797:
Compile Error: Declaration of Doctrine\ORM\Mapping\ClassMetadataFactory::wakeupReflection(Doctrine\Common\Persistence\Mapping\ClassMetadata $class, Doctrine\Common\Persistence\Mapping\ReflectionService $reflService) must be compatible with Doctrine\Persistence\Mapping\AbstractClassMetadataFactory::wakeupReflection(Doctrine\Persistence\Mapping\ClassMetadata $class, Doctrine\Persistence\Mapping\ReflectionService $reflService)
Q A
BC Break yes
Version 2.0.4

Package mongodb-odm is provided through doctrine/mongodb-odm-bundle (^4.0).
Adding fixed "doctrine/mongodb-odm": "2.0.3" to composer as a temporary fix does the trick.

doctrine/persistence 1.3.2 bug

PHP Fatal error: Uncaught TypeError: Argument 1 passed to Doctrine\ORM\Configuration::setMetadataDriverImpl() must be an instance of Doctrine\Common\Persistence\Mapping\Driver\MappingDriver, instance of Doctrine\Persistence\Mapping\Driver\MappingDriverChain given

Preloading issues

I'm unable to preload from opcache hits list due to the following 2 conflicts:

api-php         | Message: Cannot declare class Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain, because the name is already in use in /srv/www/vendor/doctrine/persistence/lib/Doctrine/Common/Persistence/Mapping/Driver/MappingDriverChain.php:9 ErrorException called
api-php         | File: /srv/www/vendor/doctrine/persistence/lib/Doctrine/Common/Persistence/Mapping/Driver/MappingDriverChain.php
api-php         | Message: Cannot declare class Doctrine\Common\Persistence\Mapping\RuntimeReflectionService, because the name is already in use in /srv/www/vendor/doctrine/persistence/lib/Doctrine/Common/Persistence/Mapping/RuntimeReflectionService.php:9 ErrorException called
api-php         | File: /srv/www/vendor/doctrine/persistence/lib/Doctrine/Common/Persistence/Mapping/RuntimeReflectionService.php

When looking at the MappingDriverChain, it looks like there is some BC work being done by creating a class alias. It looks really nasty to me, so I'm not surprised by this error.

Registry::getManagerForClass doesn't work with anonymous classes

Situation:

  • PHP 7.1.5
  • Using windows (it's an important part)
  • Trying to use Symfony validator to validate anonymous class

The validator point is useless, but what's triggered behind is the
$registry->getManagerForClass(get_class($myAnonymousClassInstance));

The test

$a = new class {
    public $value;
};

var_dump(get_class($a));

$manager = $this->getDoctrine()->getManagerForClass(get_class($a));

Output on Windows:

class@anonymous\x00E:\dev\www\skeleton\src\AppBundle\Controller\DefaultController.php000001982329027F

With this, I get an ORMException:

Unknown Entity namespace alias 'class@anonymousE'.

Obviously, because there is the : syntax, Doctrine is looking for a specific entity namespace.


I also tested this on linux inside a command and it works:

$a = new class {
    public $value;
};

$manager = $this->getContainer()->get('doctrine')->getManagerForClass(get_class($a));

var_dump($class, $manager);

Output is correct because $manager is null:

"class@anonymous\x00/mnt/e/dev/www/skeleton/src/AppBundle/Command/TestCommand.php0x7f66b1aa5341"
null

The fix

I think the AbstractManagerRegistry::getManagerForClass() should return null if the class name starts with class@anonymous\x00, whatever the platform, because it is the way PHP 7.1 handles anonymous classes names.

What do you think?

`ManagerRegistry#getRepository()` does not use `getManagerForClass()` internally

Assuming the Foo class is not in the default entity manager:

  • works:
$objectManager = $managerRegistry->getManagerForClass(Foo::class);
$repository = $objectManager->getRepository(Foo::class);
  • works:
$repository = $managerRegistry->getRepository(Foo::class, <manager name>);
  • doesn't work (because Foo is looked into the default manager):
$repository = $managerRegistry->getRepository(Foo::class);

I would have thought the 3rd case would work: after all the manager registry can retrieve the correct manager using getManagerForClass() internally.


Would it make sense to have getRepository() use getManagerForClass() internally to retrieve the repository in the correct manager?

Use `@no-named-parameters` in interfaces

Triggered by doctrine/mongodb-odm#2315 (comment)

Using the latest version (4.7.3) of vimeo/psalm makes psalm fail when a method overrides a parent method but renames a parameter because it could fail when using PHP 8 named parameters.

Renaming parameters could be BC break, so @malarzm suggested to add @no-named-arguments to some of the public API.

We could add them for example in https://github.com/doctrine/persistence/blob/70d7177779d4ff6e31f269169bc5c919de1bf7d7/lib/Doctrine/Persistence/ObjectManager.php, but I guess this should be decided internally to use it or not.

DCOM-250: [GH-335] add base events class

Jira issue originally created by user @doctrinebot:

This issue is created automatically through a Github pull request on behalf of jdeniau:

Url: doctrine/common#335

Message:

Hi,

All doctrine projects implements events. A lot of them are similars, but there is no base class defining common Events.

I tried to gathen them all in this PR. I looked into CouchDb-orm, doctrine-orm, doctrine-mongodb-odm and phpcr-odm.

I only added events present in all packages, but CouchDB is the only one to not implement some events implemented in every other packages (postPersist, loadClassmetadata, preFlush, etc.).

Common interface for ObjectManager

As discussed here, it could be nice to have an interface defining common method for some ObjectManagers.

I am specificaly talking about the ORM/EntityManagerInterface and the MongoDB/DocumentManager: those two classes implements a getReference method with the same signature.
The getReference method can not be added in the ObjectManager abstract class, because I don't think it is an ObjectManager specific method, but It could be a new interface (HasReference or something like that), available in doctrine/common.

This way, eternal packages can only verify if the interface is implemented.

What do you think ?

ObjectManager::merge and detach deprecation messages

Hello,

Since version 1.2 of this bundle, the methods ObjectManager::merge and ObjectManager::detach are commented as deprecated and to be removed in Persistence 2.0. However, these methods are still declared in ObjectManager of version 2.x and 3.0.x. So are merge and detach still deprecated methods ? And if so, when will it be removed ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.