Can't get Doctrine ORM working

Hi,

I’m struggling with Doctrine ORM. I’ve added the modules and created config part for doctrine. I’ve made an entity with some ORM annotations and now I want to update the entities, so I try to run:

php vendor/bin/doctrine-module orm:schema-tool:update --force

I get an error:

Fatal error: Uncaught Laminas\Di\Exception\MissingPropertyException: Could not resolve value for parameter “storage” of type Laminas\Cache\Storage\StorageInterface in class DoctrineModule\Cache\LaminasStorageCache (requested as Doct
rineModule\Cache\LaminasStorageCache) in C:\Users\sfra\Documents\Prive\wamp\vhosts\laminasmodules\vendor\laminas\laminas-di\src\Resolver\DependencyResolver.php:323

Somethign to do with the cache. This is my doctrine config:

'doctrine' => [
        'cache' => [
            'strivex-cache' => [
                'class' => \DoctrineModule\Cache\LaminasStorageCache::class,
                'instance' => 'strivex-cache'
            ]
        ],
        'configuration' => [
            'orm_default' => [
                'metadata_cache' => 'strivex-cache',
                'query_cache' => 'strivex-cache',
                'result_cache' => 'strivex-cache'
            ]
        ],
        'connection' => [
            'orm_default' => [
                'driverClass' => \Doctrine\DBAL\Driver\Mysqli\Driver::class,
                'params' => [
                    'host' => 'localhost',
                    'port' => '3306',
                    'user' => 'laminasmodules',
                    'password' => 'laminasmodules',
                    'dbname' => 'laminasmodules'
                ]
            ]
        ],
    ]

and the strivex-cache is registered (and working) in the ‘caches’ config.

I’m lost. Can;t get it to work, it seems. What am I missing?

PS… used doctrine versions from composer.json:
“doctrine/doctrine-module”: “^6.1”,
“doctrine/doctrine-orm-module”: “^6.1”,
“doctrine/orm”: “^2.11.1”,

I was suggested to use cli-config.php and bootstrap the application, but that file is not being called in this script. It is in another Doctrine script.

Are you really using laminas-di? If not, then uninstall this first, because it is not need in a typical laminas-mvc or Mezzio application.

Ah, ok! That changes a lot. Now only configure te paths to the entities. I want to use all MODULE/src/Model paths. I should be able to fix that :wink:

Thanx.

I have configured the entity paths, psr-4 autoload, driver… but when updating nothing is done. “[OK] No Metadata Classes to process.”

    'doctrine' => [
        'cache' => [
            'strivex-cache' => [
                'class' => \DoctrineModule\Cache\LaminasStorageCache::class,
                'instance' => 'strivex-cache'
            ]
        ],
        'configuration' => [
            'orm_default' => [
                'metadata_cache' => 'strivex-cache',
                'query_cache' => 'strivex-cache',
                'result_cache' => 'strivex-cache'
            ]
        ],
        'connection' => [
            'orm_default' => [
                'driverClass' => \Doctrine\DBAL\Driver\Mysqli\Driver::class,
                'params' => [
                    'host' => 'localhost',
                    'port' => '3306',
                    'user' => 'laminasmodules',
                    'password' => 'laminasmodules',
                    'dbname' => 'laminasmodules'
                ]
            ]
        ],
        'driver' => [
            'strivex-driver' => [
                'class' => \Doctrine\ORM\Mapping\Driver\AnnotationDriver::class,
                'cache' => 'strivex-cache',
                'paths' => [
                    __DIR__ . '/../../module/Application/src/Model',
                    __DIR__ . '/../../module/laminas_strivex/src/Model',
                ]
            ],
            'orm_default' => [ // Corrected here
               'drivers' => [
                   'Laminas\Strivex\Model' => 'strivex-driver' // Corrected here
               ]
            ]
        ]
    ]

and psr-4 autoload for the strivex module:

"psr-4" : {
      "Laminas\\Strivex\\" : "src",
      "Laminas\\Model": "src/Model"
    },

The naming and paths for your modules do not seem to be correct. Please compare with:

And the prefix Laminas is also not needed.

The Laminas prefix is needed, because the module has that namespace :wink:

I removed the custom cache and corrected the psr-4 autoloading. Now its working. Going to look at “migrations” in doctrine to get the updates to the different stages of the DTAP cycle.

Thanx.

With regard to coding standards and PSR autoloading, the naming of the module still looks somewhat unconventional. When it comes to autoloading, Laminas and Composer specify what the namespacing should look like. Working with a “Laminas” prefix means that the module is an official Laminas module, which it is not. Kinda misleading. A single module should have exactly one psr-4 autoload entry to avoid complexity and followup problems.

What about the following change in your composer.json

"autoload": {
    "psr-4": {
        "Application\\": "module/Application/src/",
        "Strivex\\": "module/Strivex/src/",
    }
},

With this single entry everything will be found. Well, that means that the namespacing of your module should change to Strivex\Model in your classes. Shouldn 't be a problem with the auto-replace function of your IDE.

Keep it simple. You 'll having loads of fun then.

2 Likes

Hi,

Already solved it. There was a wrong path to the Strivex modules.

Already changes the namespace to Strivex/Laminas/… because the modules are for using in a Laminas application :wink:

Doctrine is working now. Now looking for a nice and clean way to handle upgrades (prob. using Migrations) in the future. For now a manual sync is working during this stage.

Thanx all!