roave / psr-container-doctrine Goto Github PK
View Code? Open in Web Editor NEWDoctrine Factories for PSR-11 Containers
License: BSD 2-Clause "Simplified" License
Doctrine Factories for PSR-11 Containers
License: BSD 2-Clause "Simplified" License
Due to the latest license incidents in PHP-land, @alcaeus asked me to reach out to you and ask if it's ok to use parts of your service factories in the DoctrineMongoODMModule package.
Most of the factories are the same for ORM and ODM and your AbstractFactory
is written quite nicely so I used them to instantiate the services there while upgrading the library to be compatible with mongodb-odm 2.0
Is it ok for you to put a license header to each file stating that it's origin or should I mention it somewhere else (LICENCE
, README
)?
Thanks!
Please help me how to fix the error?
command php vendor/bin/doctrine-migrations migrations:diff
causes an error:
Fatal error: Uncaught Doctrine\Migrations\Configuration\Migration\Exception\MissingConfigurationFile: It was not possible to locate any configuration file. in /app/vendor/doctrine/migrations/lib/Doctrine/Migrations/Configuration/Migration/Exception/MissingConfigurationFile.php:14
Stack trace:
#0 /app/vendor/doctrine/migrations/lib/Doctrine/Migrations/Configuration/Migration/ConfigurationFileWithFallback.php(52): Doctrine\Migrations\Configuration\Migration\Exception\MissingConfigurationFile::new()
#1 /app/vendor/doctrine/migrations/lib/Doctrine/Migrations/DependencyFactory.php(161): Doctrine\Migrations\Configuration\Migration\ConfigurationFileWithFallback->getConfiguration()
#2 /app/vendor/doctrine/migrations/lib/Doctrine/Migrations/DependencyFactory.php(187): Doctrine\Migrations\DependencyFactory->getConfiguration()
#3 /app/vendor/doctrine/migrations/lib/Doctrine/Migrations/DependencyFactory.php(279): Doctrine\Migrations\DependencyFactory->getEntityManager()
#4 /app/vendor/doctrine/migrations/lib/Doctrine/Migrations/Depen in /app/vendor/doctrine/migrations/lib/Doctrine/Migrations/Configuration/Migration/Exception/MissingConfigurationFile.php on line 14
file cli-config.php
:
<?php
$container = require 'config/container.php';
/** @var \Doctrine\ORM\EntityManager $entityManager */
$entityManager = $container->get(\Doctrine\ORM\EntityManager::class);
return \Doctrine\ORM\Tools\Console\ConsoleRunner::createHelperSet(
$container->get(\Doctrine\ORM\EntityManager::class)
);
file config/autoload/doctrine.local.php
:
<?php
declare(strict_types=1);
use Doctrine\Migrations\Tools\Console\Command;
return [
'doctrine' => [
'connection' => [
'orm_default' => [
'params' => [ ],
],
],
'migrations' => [
'orm_default' => [
'table_storage' => [
'table_name' => 'migrations',
'version_column_name' => 'version',
'version_column_length' => 255,
'executed_at_column_name' => 'executed_at',
'execution_time_column_name' => 'execution_time',
],
'migrations_paths' => ['DB\Migrations' => __DIR__ . '/../../data/migrations'],
'all_or_nothing' => true,
'check_database_platform' => true,
],
],
],
'dependencies' => [
'factories' => [
Command\DiffCommand::class => Roave\PsrContainerDoctrine\Migrations\CommandFactory::class,
Command\DumpSchemaCommand::class => Roave\PsrContainerDoctrine\Migrations\CommandFactory::class,
Command\ExecuteCommand::class => Roave\PsrContainerDoctrine\Migrations\CommandFactory::class,
Command\GenerateCommand::class => Roave\PsrContainerDoctrine\Migrations\CommandFactory::class,
Command\LatestCommand::class => Roave\PsrContainerDoctrine\Migrations\CommandFactory::class,
Command\MigrateCommand::class => Roave\PsrContainerDoctrine\Migrations\CommandFactory::class,
Command\RollupCommand::class => Roave\PsrContainerDoctrine\Migrations\CommandFactory::class,
Command\StatusCommand::class => Roave\PsrContainerDoctrine\Migrations\CommandFactory::class,
Command\UpToDateCommand::class => Roave\PsrContainerDoctrine\Migrations\CommandFactory::class,
Command\VersionCommand::class => Roave\PsrContainerDoctrine\Migrations\CommandFactory::class,
Doctrine\Migrations\DependencyFactory::class => Roave\PsrContainerDoctrine\Migrations\DependencyFactoryFactory::class,
Doctrine\Migrations\Configuration\Migration\ConfigurationLoader::class => Roave\PsrContainerDoctrine\Migrations\ConfigurationLoaderFactory::class,
],
],
];
Hi,
My goal is to upgrade doctrine/orm
to latest version 2.8.1 but a conflict for the doctrine/common
appeared because
this package 2.2.0 relies on doctrine/common ^2.6
but doctrine/orm
applies this constraint doctrine/common ^3.0
.
Is it possible to change the constraints on this package?
I've followed the documentation, attempting to get Mezzio integrated with Doctrine, using this package, but keep encountering the following error, when running: php vendor/bin/doctrine orm:mapping:describe QuoteUser
.
You do not have any mapped Doctrine ORM entities according to the current configuration. If you have entities or mapping files you should check your mapping configuration for errors.
I'm using roave/psr-container-doctrine 3.6.0 with PHP 8.1.14.
Here is my config/autoload/doctrine.global.php file:
<?php
use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
use Doctrine\Persistence\Mapping\Driver\MappingDriverChain;
use Ramsey\Uuid\Doctrine\UuidType;
use Roave\PsrContainerDoctrine\EntityManagerFactory;
return [
'dependencies' => [
'factories' => [
'doctrine.entity_manager.orm_default' => EntityManagerFactory::class,
],
],
'doctrine' => [
'connection' => [
'orm_default' => [
'params' => [
'url' => 'pgsql://user:password@database-test/developer_quotes_sender_test',
],
],
],
'annotation' => [
'metadata' => [
'src/App/src/Entity',
],
],
'entity_manager' => [
'orm_default' => [
'connection' => 'orm_default',
'configuration' => 'orm_default',
],
],
'driver' => [
'orm_default' => [
'class' => MappingDriverChain::class,
'drivers' => [
'QuoteUser' => 'quote_user',
],
],
'quote_user' => [
'class' => AnnotationDriver::class,
'cache' => 'array',
'paths' => __DIR__ . '/../../src/App/src/Entity',
],
],
'cache' => [
'array' => [
'class' => Doctrine\Common\Cache\ArrayCache::class,
'namespace' => 'psr-container-doctrine',
],
],
'types' => [
UuidType::NAME => UuidType::class,
]
],
];
In src/App/src/Entity, i have one file named QuoteUser.php, with the following definition:
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Ramsey\Uuid\Doctrine\UuidGenerator;
/**
* @ORM\Entity
* @ORM\Table(name="quote_users")
*/
class QuoteUser
{
/**
* @ORM\Id
* @ORM\Column(type="uuid", unique=true)
* @ORM\GeneratedValue(strategy="CUSTOM")
* @ORM\CustomIdGenerator(class=UuidGenerator::class)
*/
private $userId;
/** @ORM\Column(type="string",length="36",name="full_name") */
private $fullName;
/** @ORM\Column(type="string",length="18",name="mobile_number",unique="true") */
private $mobileNumber;
/** @ORM\Column(type="text",name="email_address",unique="true") */
private $emailAddress;
}
This is the contents of cli-config.php:
<?php
use Doctrine\ORM\Tools\Console\ConsoleRunner;
$container = require 'config/container.php';
return ConsoleRunner::createHelperSet(
$container->get('doctrine.entity_manager.orm_default')
);
Finally, I have the following factories
element in config/autoload/dependencies.global.php:
'factories' => [
// Fully\Qualified\ClassName::class => Fully\Qualified\FactoryName::class,
ExecuteCommand::class => CommandFactory::class,
ConfigurationLoader::class => ConfigurationLoaderFactory::class,
DependencyFactory::class => DependencyFactoryFactory::class,
],
For 3.0.0 release, we need to remove the bc-namespace-shim.php
.
The full example shows how the migrations can be configured:
https://github.com/Roave/psr-container-doctrine/blob/2.2.0/example/full-config.php#L152-L158
However, I that configuration is not valid, because the AbstractFactory
retrieves the configuration by a config key, which in most cases is orm_default
, so instead of having this:
'migrations' => [
'directory' => 'scripts/orm/migrations',
'name' => 'My DB Migrations',
'namespace' => 'My\Migration',
'table' => 'migration',
'column' => 'version_timestamp',
],
what we would really want to have is this:
'migrations' => [
'orm_default' => [
'directory' => 'scripts/orm/migrations',
'name' => 'My DB Migrations',
'namespace' => 'My\Migration',
'table' => 'migration',
'column' => 'version_timestamp',
],
],
I'm not sure if this is correct, so I'm posting it as an issue, not a PR, so we can have a discussion first.
Hello, there!
I'm struggling for 3 days to configure the roave/psr-container-doctrine with mezzio.
First I struggled with caches, then with MappingDriver, now I managed to make it all work, but it doesn't recognize entities.
This is my exception:
Doctrine\ORM\Mapping\MappingException: Class "Usuario\Entity\Usuario" is not a valid entity or mapped super class. in file /mnt/arquivos/Projetos/Neocyber/NeoSchool/Backend/private/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/MappingException.php on line 378
Stack trace:
1. Doctrine\ORM\Mapping\MappingException->() /mnt/arquivos/Projetos/Neocyber/NeoSchool/Backend/private/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/MappingException.php:378
2. Doctrine\ORM\Mapping\MappingException->classIsNotAValidEntityOrMappedSuperClass() /mnt/arquivos/Projetos/Neocyber/NeoSchool/Backend/private/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php:101
3. Doctrine\ORM\Mapping\Driver\AnnotationDriver->loadMetadataForClass() /mnt/arquivos/Projetos/Neocyber/NeoSchool/Backend/private/vendor/doctrine/persistence/lib/Doctrine/Persistence/Mapping/Driver/MappingDriverChain.php:79
4. Doctrine\Persistence\Mapping\Driver\MappingDriverChain->loadMetadataForClass() /mnt/arquivos/Projetos/Neocyber/NeoSchool/Backend/private/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php:156
5. Doctrine\ORM\Mapping\ClassMetadataFactory->doLoadMetadata() /mnt/arquivos/Projetos/Neocyber/NeoSchool/Backend/private/vendor/doctrine/persistence/lib/Doctrine/Persistence/Mapping/AbstractClassMetadataFactory.php:382
6. Doctrine\Persistence\Mapping\AbstractClassMetadataFactory->loadMetadata() /mnt/arquivos/Projetos/Neocyber/NeoSchool/Backend/private/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php:85
7. Doctrine\ORM\Mapping\ClassMetadataFactory->loadMetadata() /mnt/arquivos/Projetos/Neocyber/NeoSchool/Backend/private/vendor/doctrine/persistence/lib/Doctrine/Persistence/Mapping/AbstractClassMetadataFactory.php:251
8. Doctrine\Persistence\Mapping\AbstractClassMetadataFactory->getMetadataFor() /mnt/arquivos/Projetos/Neocyber/NeoSchool/Backend/private/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php:293
9. Doctrine\ORM\EntityManager->getClassMetadata() /mnt/arquivos/Projetos/Neocyber/NeoSchool/Backend/private/vendor/doctrine/orm/lib/Doctrine/ORM/Repository/DefaultRepositoryFactory.php:45
10. Doctrine\ORM\Repository\DefaultRepositoryFactory->getRepository() /mnt/arquivos/Projetos/Neocyber/NeoSchool/Backend/private/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php:768
11. Doctrine\ORM\EntityManager->getRepository() /mnt/arquivos/Projetos/Neocyber/NeoSchool/Backend/private/src/Usuario/src/Repository/UsuarioRepository.php:23
12. Usuario\Repository\UsuarioRepository->getByLogin() /mnt/arquivos/Projetos/Neocyber/NeoSchool/Backend/private/src/Usuario/src/Middleware/LoginMiddleware.php:53
13. Usuario\Middleware\LoginMiddleware->process() /mnt/arquivos/Projetos/Neocyber/NeoSchool/Backend/private/vendor/mezzio/mezzio/src/Middleware/LazyLoadingMiddleware.php:37
14. Mezzio\Middleware\LazyLoadingMiddleware->process() /mnt/arquivos/Projetos/Neocyber/NeoSchool/Backend/private/vendor/mezzio/mezzio-router/src/Route.php:85
15. Mezzio\Router\Route->process() /mnt/arquivos/Projetos/Neocyber/NeoSchool/Backend/private/vendor/mezzio/mezzio-router/src/RouteResult.php:97
16. Mezzio\Router\RouteResult->process() /mnt/arquivos/Projetos/Neocyber/NeoSchool/Backend/private/vendor/mezzio/mezzio-router/src/Middleware/DispatchMiddleware.php:30
17. Mezzio\Router\Middleware\DispatchMiddleware->process() /mnt/arquivos/Projetos/Neocyber/NeoSchool/Backend/private/vendor/mezzio/mezzio/src/Middleware/LazyLoadingMiddleware.php:37
18. Mezzio\Middleware\LazyLoadingMiddleware->process() /mnt/arquivos/Projetos/Neocyber/NeoSchool/Backend/private/vendor/laminas/laminas-stratigility/src/Next.php:51
19. Laminas\Stratigility\Next->handle() /mnt/arquivos/Projetos/Neocyber/NeoSchool/Backend/private/vendor/mezzio/mezzio-helpers/src/UrlHelperMiddleware.php:48
20. Mezzio\Helper\UrlHelperMiddleware->process() /mnt/arquivos/Projetos/Neocyber/NeoSchool/Backend/private/vendor/mezzio/mezzio/src/Middleware/LazyLoadingMiddleware.php:37
21. Mezzio\Middleware\LazyLoadingMiddleware->process() /mnt/arquivos/Projetos/Neocyber/NeoSchool/Backend/private/vendor/laminas/laminas-stratigility/src/Next.php:51
22. Laminas\Stratigility\Next->handle() /mnt/arquivos/Projetos/Neocyber/NeoSchool/Backend/private/vendor/mezzio/mezzio-router/src/Middleware/MethodNotAllowedMiddleware.php:56
23. Mezzio\Router\Middleware\MethodNotAllowedMiddleware->process() /mnt/arquivos/Projetos/Neocyber/NeoSchool/Backend/private/vendor/mezzio/mezzio/src/Middleware/LazyLoadingMiddleware.php:37
24. Mezzio\Middleware\LazyLoadingMiddleware->process() /mnt/arquivos/Projetos/Neocyber/NeoSchool/Backend/private/vendor/laminas/laminas-stratigility/src/Next.php:51
25. Laminas\Stratigility\Next->handle() /mnt/arquivos/Projetos/Neocyber/NeoSchool/Backend/private/vendor/mezzio/mezzio-router/src/Middleware/ImplicitOptionsMiddleware.php:72
26. Mezzio\Router\Middleware\ImplicitOptionsMiddleware->process() /mnt/arquivos/Projetos/Neocyber/NeoSchool/Backend/private/vendor/mezzio/mezzio/src/Middleware/LazyLoadingMiddleware.php:37
27. Mezzio\Middleware\LazyLoadingMiddleware->process() /mnt/arquivos/Projetos/Neocyber/NeoSchool/Backend/private/vendor/laminas/laminas-stratigility/src/Next.php:51
28. Laminas\Stratigility\Next->handle() /mnt/arquivos/Projetos/Neocyber/NeoSchool/Backend/private/vendor/mezzio/mezzio-router/src/Middleware/ImplicitHeadMiddleware.php:76
29. Mezzio\Router\Middleware\ImplicitHeadMiddleware->process() /mnt/arquivos/Projetos/Neocyber/NeoSchool/Backend/private/vendor/mezzio/mezzio/src/Middleware/LazyLoadingMiddleware.php:37
30. Mezzio\Middleware\LazyLoadingMiddleware->process() /mnt/arquivos/Projetos/Neocyber/NeoSchool/Backend/private/vendor/laminas/laminas-stratigility/src/Next.php:51
31. Laminas\Stratigility\Next->handle() /mnt/arquivos/Projetos/Neocyber/NeoSchool/Backend/private/vendor/mezzio/mezzio-router/src/Middleware/RouteMiddleware.php:50
32. Mezzio\Router\Middleware\RouteMiddleware->process() /mnt/arquivos/Projetos/Neocyber/NeoSchool/Backend/private/vendor/mezzio/mezzio/src/Middleware/LazyLoadingMiddleware.php:37
33. Mezzio\Middleware\LazyLoadingMiddleware->process() /mnt/arquivos/Projetos/Neocyber/NeoSchool/Backend/private/vendor/laminas/laminas-stratigility/src/Next.php:51
34. Laminas\Stratigility\Next->handle() /mnt/arquivos/Projetos/Neocyber/NeoSchool/Backend/private/vendor/laminas/laminas-stratigility/src/Middleware/PathMiddlewareDecorator.php:43
35. Laminas\Stratigility\Middleware\PathMiddlewareDecorator->process() /mnt/arquivos/Projetos/Neocyber/NeoSchool/Backend/private/vendor/laminas/laminas-stratigility/src/Next.php:51
36. Laminas\Stratigility\Next->handle() /mnt/arquivos/Projetos/Neocyber/NeoSchool/Backend/private/vendor/mezzio/mezzio-helpers/src/BodyParams/BodyParamsMiddleware.php:83
37. Mezzio\Helper\BodyParams\BodyParamsMiddleware->process() /mnt/arquivos/Projetos/Neocyber/NeoSchool/Backend/private/vendor/mezzio/mezzio/src/Middleware/LazyLoadingMiddleware.php:37
38. Mezzio\Middleware\LazyLoadingMiddleware->process() /mnt/arquivos/Projetos/Neocyber/NeoSchool/Backend/private/vendor/laminas/laminas-stratigility/src/Next.php:51
39. Laminas\Stratigility\Next->handle() /mnt/arquivos/Projetos/Neocyber/NeoSchool/Backend/private/vendor/mezzio/mezzio-helpers/src/ServerUrlMiddleware.php:36
40. Mezzio\Helper\ServerUrlMiddleware->process() /mnt/arquivos/Projetos/Neocyber/NeoSchool/Backend/private/vendor/mezzio/mezzio/src/Middleware/LazyLoadingMiddleware.php:37
41. Mezzio\Middleware\LazyLoadingMiddleware->process() /mnt/arquivos/Projetos/Neocyber/NeoSchool/Backend/private/vendor/laminas/laminas-stratigility/src/Next.php:51
42. Laminas\Stratigility\Next->handle() /mnt/arquivos/Projetos/Neocyber/NeoSchool/Backend/private/vendor/tuupola/cors-middleware/src/CorsMiddleware.php:124
43. Tuupola\Middleware\CorsMiddleware->process() /mnt/arquivos/Projetos/Neocyber/NeoSchool/Backend/private/vendor/laminas/laminas-stratigility/src/Next.php:51
44. Laminas\Stratigility\Next->handle() /mnt/arquivos/Projetos/Neocyber/NeoSchool/Backend/private/vendor/laminas/laminas-stratigility/src/Middleware/ErrorHandler.php:131
45. Laminas\Stratigility\Middleware\ErrorHandler->process() /mnt/arquivos/Projetos/Neocyber/NeoSchool/Backend/private/vendor/mezzio/mezzio/src/Middleware/LazyLoadingMiddleware.php:37
46. Mezzio\Middleware\LazyLoadingMiddleware->process() /mnt/arquivos/Projetos/Neocyber/NeoSchool/Backend/private/vendor/laminas/laminas-stratigility/src/Next.php:51
47. Laminas\Stratigility\Next->handle() /mnt/arquivos/Projetos/Neocyber/NeoSchool/Backend/private/vendor/laminas/laminas-stratigility/src/MiddlewarePipe.php:76
48. Laminas\Stratigility\MiddlewarePipe->process() /mnt/arquivos/Projetos/Neocyber/NeoSchool/Backend/private/vendor/laminas/laminas-stratigility/src/MiddlewarePipe.php:65
49. Laminas\Stratigility\MiddlewarePipe->handle() /mnt/arquivos/Projetos/Neocyber/NeoSchool/Backend/private/vendor/laminas/laminas-httphandlerrunner/src/RequestHandlerRunner.php:96
50. Laminas\HttpHandlerRunner\RequestHandlerRunner->run() /mnt/arquivos/Projetos/Neocyber/NeoSchool/Backend/private/vendor/mezzio/mezzio/src/Application.php:68
51. Mezzio\Application->run() /mnt/arquivos/Projetos/Neocyber/NeoSchool/Backend/public/index.php:30
52. {closure}() /mnt/arquivos/Projetos/Neocyber/NeoSchool/Backend/public/index.php:31
Also (but less important) when I try to validate the schema on cli it tells me that the enum type is not supported.
Could someone give me some help?
My actual doctrine.global.config
:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
return array(
'doctrine' => [
'driver' => [
'orm_default' => [
'class' => \Doctrine\Persistence\Mapping\Driver\MappingDriverChain::class,
]
],
'connection' => [
'orm_default' => [
'driverClass' => \Doctrine\DBAL\Driver\PDOMySql\Driver::class,
'charset' => 'UTF8mb4',
'collation' => 'UTF8mb4_unicode_ci',
]
],
'configuration' => [
'orm_default' => [
'result_cache' => 'custom_cache',
'metadata_cache' => 'custom_cache',
'query_cache' => 'custom_cache',
'hydration_cache' => 'custom_cache',
]
],
'cache' => [
'custom_cache' => [
'class' => \Common\Cache\CustomCache::class, // Because Doctrine Cache breaking changes
],
],
'types' => [
'enum' => Doctrine\DBAL\Types\StringType::class
]
],
'dependencies' => [
'factories' => [
'doctrine.entity_manager.orm_default' => \Roave\PsrContainerDoctrine\EntityManagerFactory::class,
],
]
);
Relevant part of ConfigProvider.php
:
/**
* Retorna configuração das Entities do doctrine
* @return array
*/
public function getEntities()
{
return array(
'driver' => [
'orm_default' => [
'drivers' => [
Entity\Usuario::class => 'usuario_entity',
],
],
// Here I tried several possible ways and configuration structures for the driver and paths, but with no result.
'usuario_entity' => [
'class' => AnnotationDriver::class,
'cache' => 'custom_cache',
'paths' => __DIR__ . '/Entity',
],
],
);
}
...
If anyone can help me figure out where I'm going wrong I'll be very grateful.
I use a configuration very similar to this one in another API with Zend Expressive and with the DASPRiD/container-interop-doctrine plugin, and there it works perfectly.
But here I haven't been able to find the way yet.
Thanks in advance.
I added Psalm in #1 but there are a bunch of issues to be resolved.
The current documentation suggests the following configuration:
return new HelperSet(
[
'em' => new EntityManagerHelper(
$container->get('doctrine.entity_manager.orm_default')
),
]
);
However, when I try to run php vendor/bin/doctrine-migrations migrations:status
, it says that I have to provide a configuration for the database. The exact error is the following: You have to specify a --db-configuration file or pass a Database Connection as a dependency to the Migrations.
. Shouldn't we actually make it as follows?
/** @var EntityManagerInterface $entityManager */
$entityManager = $container->get('doctrine.entity_manager.orm_default');
return new HelperSet(
[
'em' => new EntityManagerHelper(
$entityManager
),
'configuration' => new ConfigurationHelper(
$entityManager->getConnection(),
$container->get('doctrine.migrations.orm_default')
),
]
);
Hey there,
I tried to use this package with multiple EntityManager
instances.
I realized that the EntityManagerFactory
does not pass the requestedName
to the factory and thus its always orm_default
which is being created:
if (is_string($factory) && class_exists($factory)) {
$factory = new $factory();
$lazyLoaded = true;
}
/** @internal */
public function __construct(string $configKey = 'orm_default')
{
$this->configKey = $configKey;
}
/**
* @return mixed
*/
public function __invoke(ContainerInterface $container)
{
return $this->createWithConfig($container, $this->configKey);
}
$requestedName
is never passed the __construct
consumed by __invoke
.
Did I overlooked something or is this a bug?
Hi i noticed that /src/DriverFactory.php is not compatible with doctrine/common ^3.0
since
use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Annotations\AnnotationRegistry;
are only available below version 3.0, so it seems the package.json is broken with psr-contrianer-doctrine 3.x
As it says on the tin.
Since the original package should be credited to @DASPRiD clearly, add a note about this in the readme.
psr-container-doctrine/composer.json
Line 19 in 653bdba
This is an exercise in "eating our own dogfood" - this is probably from the initial fork of the project, when it was first imported in roave/
, but we should really use a stricter range here.
Add a few notes about BC breaks, and things to be aware of (like namespace change, but also the BC shim so old namespaces work). BC breaks so far are adding types in AbstractFactory for example. It probably makes sense to mark this @internal
too. Also include any important BC breaks in #3 .
Released version 5.2.1 does not contains any changes at all, as can be seen there: 5.2.0...5.2.1
But according to the release notes, it should contains at the very least two commits.
That explains #133 (comment).
Can we please get a new patch release that contains at least 3fcf042 ?
Hello.
Recently released ORM v2.12 add support for persistence v3.0
Will be work solutions if allow v3 in this package, like this: "doctrine/persistence": "^2.4 || ^3"?
Hello
I'm switching between the repository of Dasprid and that of Roave.
I have the following configuration for the configuration of my entityManager.
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain;
return [
'driver' => [
'domain' => [
'class' => MappingDriverChain::class,
'drivers' => [
'Domain' => 'domain_entity'
],
],
'domain_entity' => [
'class' => XmlDriver::class,
'paths' => __DIR__ . '/../src/Infrastructure/Mapping',
]
]
];
When I instantiate the entityManager I get the following error: (For information it worked correctly with Dasprid services)
The class 'Domain\Account\Entity\User' was not found in the chain configured namespaces
.
If I understand correctly, the problem comes from the Factory DriverFactory
which tests if the driver and type is an instance Doctrine\Persistence\Mapping\Driver\MappingDriverChain
and not an instance of Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain
as described in the example of minimal configuration
Except I do not use the Doctrine\Persistence
library, it is also not required in the composer.
So, what should I do ? Install 'Doctrine\Persistence' and use it in my configuration ?
Thank you in advance for your help.
This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.
These updates are awaiting their schedule. Click on a checkbox to get an update now.
These updates have all been created already. Click a checkbox below to force a retry/rebase of any.
composer.json
php ~8.2.0 || ~8.3.0
doctrine/common ^3.4.4
doctrine/dbal ^4.1.0
doctrine/event-manager ^2.0.1
doctrine/migrations ^3.8.0
doctrine/orm ^3.2.1
doctrine/persistence ^3.3.3
psr/cache ^2.0.0 || ^3.0.0
psr/container ^1.1.2 || ^2.0.2
doctrine/coding-standard ^12.0.0
phpunit/phpunit ^10.5.30
psalm/plugin-phpunit ^0.19.0
symfony/yaml ^7.1.1
vimeo/psalm ^5.25.0
example/composer.json
php ~8.2.0 || ~8.3.0
illuminate/container ^11.20.0
laminas/laminas-servicemanager ^4.2.0
symfony/cache ^7.1.3
docker-compose.yml
Dockerfile
php 8.3
.github/workflows/coding-standards.yml
actions/checkout v4
shivammathur/setup-php 2.31.1
actions/cache v4
.github/workflows/composer-require-checker.yml
actions/checkout v4
shivammathur/setup-php 2.31.1
actions/cache v4
.github/workflows/release-on-milestone-closed-triggering-release-event.yml
actions/checkout v4
laminas/automatic-releases v1
laminas/automatic-releases v1
laminas/automatic-releases v1
laminas/automatic-releases v1
.github/workflows/roave-bc-check.yml
actions/checkout v4
shivammathur/setup-php 2.31.1
actions/cache v4
.github/workflows/static-analysis.yml
actions/checkout v4
shivammathur/setup-php 2.31.1
actions/cache v4
.github/workflows/test.yml
actions/checkout v4
shivammathur/setup-php 2.31.1
actions/cache v4
Hi,
is it possible that there is a little mistake "aliases" example in README.md?
This didn't work:
'aliases' => [
'doctrine.entity_manager.orm_default' => EntityManagerInterface::class,
],
This however, works (the other way round):
'aliases' => [
EntityManagerInterface::class => 'doctrine.entity_manager.orm_default',
],
But since I'm new to Laminas / Mezzio / Doctrine / PSR-11, it is also likely that I'm doing it wrong, so please forgive me if the mistake sits in front of the screen :-)
Kind regards
I tested the migrations functionality with and without registering the migrations commands inside the factories. It works even without registering them, when I try to call php vendor/bin/doctrine-migrations xxxxx
, where xxxxx
is the command. So, why do we need to register the commands as services?
In doctrine dbal 3, I had url starts with: mysql://
and doctrine correctly handle this connection string. But now, even with #124 I still cannot make a connection (pdo-mysql
is correct right now).
Looks like missing predefined scheme mapping in DsnParser https://github.com/Roave/psr-container-doctrine/pull/124/files#diff-a0906b5aa460579706c33a67d2bed0b0b2085cf46ef55a7d7ba103cbe5cf4407R116
It will be nice to be able to confiure this map. I see two ways:
DsnParser
from container and then I be able to make map by my own.Given the release of Doctrine Migrations v3, is the support for the new version planned? It's such a pity, because the migrations support for psr-container-doctrine
was added not a long time ago, but the version is now locked to v2. Can we do this without a BC break?
It appears doctrine/cache has stopped supporting pre-built caching implementations. This container needs to be updated to consider doctrine/cache 2.x. In the immediate, this should be locked into compatibility with doctrine/cache:^1.0.0.
I am currently using doctrine/cache 1.11.3 and can't confirm compatibility with versions previous to this.
I can also confirm that adding this version constraint locally fixed my issue.
Hi!
I'm facing some initialization problems with lib.
The exception that I receive is:
ServiceNotCreatedException
Service with name "doctrine.entity_manager.orm_default" could not be created. Reason: Missing "class" config key
My global config:
return array(
'doctrine' => [
'driver' => [
'orm_default' => [
'class' => \Doctrine\ORM\Mapping\Annotation::class,
],
],
'connection' => [
'orm_default' => [
'charset' => 'UTF8mb4',
'collation' => 'UTF8mb4_unicode_ci',
]
],
'configuration' => [
'orm_default' => [
'result_cache' => 'custom_cache',
'metadata_cache' => 'custom_cache',
'query_cache' => 'custom_cache',
'hydration_cache' => 'custom_cache',
]
],
'cache' => [
'orm_default' => [
'custom_cache' => [
'class' => CustomCacheProvider::class, // Because Doctrine Cache breaking changes
],
]
]
],
'dependencies' => [
'factories' => [
'doctrine.entity_manager.orm_default' => \Roave\PsrContainerDoctrine\EntityManagerFactory::class,
],
]
);
Edit: With some debug i found that problem is with cache factory, maybe related with #46
It's possible to disable cache for now, while I'm in developement time?
Does there can add some features, not just factories?
I'm ready some RP.
It's come up a couple of times in laminas' slack the question as to how to use a custom version comparator in doctrine migrations when using this library.
That should be documented, and the one I've been sharing is:
config/cli-config.php
<?php
declare(strict_types=1);
use Doctrine\Migrations\DependencyFactory;
use Doctrine\Migrations\Version\Comparator;
use Doctrine\Migrations\Version\Version;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Tools\Console\EntityManagerProvider\SingleManagerProvider;
use Laminas\ServiceManager\ServiceManager;
require dirname(__DIR__) . '/vendor/autoload.php';
/** @var ServiceManager $container */
$container = require __DIR__ . '/container.php';
global $argv;
if (str_contains($argv[0], 'doctrine-migrations')) {
/** @var DependencyFactory $factory */
$factory = $container->get(DependencyFactory::class);
$factory->setService(Comparator::class, new class() implements Comparator {
public function compare(Version $a, Version $b): int
{
return strcmp(self::versionWithoutNamespace($a), self::versionWithoutNamespace($b));
}
private static function versionWithoutNamespace(Version $version): string
{
$parsed = strrchr($version->__toString(), '\\');
if ($parsed === false) {
throw new \RuntimeException('Unable to parse version ' . $version->__toString());
}
return $parsed;
}
});
return $factory;
}
When run as: vendor/bin/doctrine-migrations ...
This example uses laminas service manager, and adds an anonymous class as the comparator, which compares version numbers regardless of their namespace, so that they can be run in order across different modules.
If no one beats me to it, I'll try to remember to create a PR for this if it would be welcome. I know its not just for this library, but everything else is pretty much available by configuration, so this comes up.
I've just switched from the DASPRiD package and get the Laminas\ServiceManager\Exception\ServiceNotCreatedException thrown upon my previously working configuration:
Service with name "Doctrine\ORM\EntityManager" could not be created. Reason: Undefined index: default_driver
I went through the readme and the sample configurations but found no clue as far as 'default_driver' is concerned.
What works is the following change in DriverFactory.php:71
if (@$config['default_driver'] !== null) {
Is there any interest to split this repository into pieces? one for dbal, orm, cache etc. to make it easier to resuse, for example for a version for mongodb orm?
I just tried version 3 of this package which requires doctrine migrations v3 and it took me a while to figure out to correctly wire up the migrations CLI commands.
I added the factories as outlined in the docs (copy/paste from the full-config
example) but to actually use the migration command I also had to add all migrations command to a $commands
array in cli-config.php
, which seems to be an (undocumented?) feature of the Doctrine CLI.
So, my question is... Did I do it wrong? If so, what is the correct way?
Should we add more documentation for this or is it obvious and I just didn't get it?
Also, should we add some possibilities to fetch the factory config and commands config (for CLI) from a helper? Searching for all possible Migrations commands is tedious.
When I was browsing the code I also noticed that the migrations stuff is neatly separated in a sub namespace, so maybe we could/should move the dependency from require
to a suggestion for people who don't use migrations?
Any opinions? Thanks!
The DriverFactory assumes that any subclass of AnnotationDriver will maintain its constructor signature:
psr-container-doctrine/src/DriverFactory.php
Lines 43 to 57 in 607341f
AttributeDriver redefines the constructor:
I'm working around this for now with a wrapper class:
<?php
declare(strict_types=1);
namespace MyData;
class AttributeDriver extends \Doctrine\ORM\Mapping\Driver\AttributeDriver
{
/**
* Redefine constructor to work around argument bug since
* \Doctrine\ORM\Mapping\Driver\AttributeDriver redefined the constructor
* and changed the arguments while the Roave factory assumes the same
* arguments as the parent AnnotationDriver
*/
public function __construct($reader, $paths = null)
{
parent::__construct($paths);
}
}
As it says on the tin: https://github.com/laminas/automatic-releases/
Note: this needs to be done by one of the Roave team since we have to rename branches etc
Moin,
the use of Doctrine\ORM\Mapping\Driver\AnnotationDriver
does not work since doctrine/orm:^2.12
.
Here in the https://github.com/doctrine/orm/blob/2.12.x/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php the parent class was changed to MappingDriver
.
In https://github.com/Roave/psr-container-doctrine/blob/3.6.x/src/DriverFactory.php#L52 it is checked whether this is a subclass of Doctrine\Persistence\Mapping\Driver\AnnotationDriver
. However, this class is deprecated and as far as I can see, no more subclasses are provided.
This then leads to the following error:
Call to a member function getClassAnnotations() on array in vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php:82
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.