Roave / psr-container-doctrine

Doctrine Factories for PSR-11 Containers
BSD 2-Clause "Simplified" License
95 stars 31 forks source link

Issues with my configuration because of an issue running orm:mapping:describe #97

Open settermjd opened 1 year ago

settermjd commented 1 year ago

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,
],
settermjd commented 1 year ago

I've got a setup working with Slim. All being well, I'll figure out what I missed by comparison to that project.