How to use multiple versions at the same time in an Apigility application with Doctrine?

Context first: Apigility managed application based on Zend Framework 2 . In the first version ( V1) I used for the model layer. Now I am implementing with Doctrine 2 as an ORM.ZfcBase DbMapperV2

Apigility provides easy switching between versions, and each version can use its own DB adapter:

/config/autoload/global.php/ /config/autoload/local.php

<?php
return array(
    ...
    'db' => array(
        'adapters' => array(
            'DB\\myproject_v1' => array(
                // settings (driver, hostname, database, driver_options)
                // credentials (username, password)
                ...
            ),
            'DB\\myproject_v2' => array(
                // settings (driver, hostname, database, driver_options)
                // credentials (username, password)
                ...
            ),
        ),
    ),
    ...
);

So, to use a different default version with a different database behind it, you only need to change the URL:

myproject.tld/my-endpoint    <-- version set to default
myproject.tld/v1/my-endpoint <-- version 1
myproject.tld/v2/my-endpoint <-- version 2

I want to add Doctrine 2 to my application, so I added local.phpas here :

<?php
return array(
    ...
    'doctrine' => array(
        'connection' => array(
            'orm_default' => array(
                'driverClass' => 'Doctrine\DBAL\Driver\PDOMySql\Driver',
                'params' => array(
                    // settings (host, port, dbname)
                    // credentials (user, password)
                    ...
                ),
            ),
        ),
    ),
    ...
);

, / . .

Doctrine Apigility? DB Apigility Doctrine / ?

+4
1

:

[
    'db'=>[
        'adapters' => [
            'DB\\myproject_v1' => [],
            'DB\\myproject_v2' => [],
        ]
    ]
]

factory, DB\\myproject_v1 DB\\myproject_v2 db.

, , :

'db-connected' => array(
    'YourDBConnectedResource' => array(
        'adapter_name'     => 'DB\\myproject_v1',
    ),
),

Doctrine factory , , Apigility Doctrine , . -, , .

return [
    'doctrine' => [
        'connection' => [
            'orm_default' => [ // you don't have to use orm_default, you can arbitrarily name this version1
                'driverClass' => 'Doctrine\DBAL\Driver\PDOMySql\Driver',
                'params' => [
                    // settings (host, port, dbname)
                    // credentials (user, password)

                ],
            ],
            'version2' => [
                'driverClass' => 'Doctrine\DBAL\Driver\PDOMySql\Driver',
                'params' => [
                    // settings (host, port, dbname)
                    // credentials (user, password)
                ],
            ],            
        ],
    ],
];

DB doctrine.connection.orm_default doctrine.connection.version2. , db.

'db-connected' => [
    'My\\Endpoint\\V1\\Rest\\MyResource' => [
        'adapter_name'     => 'doctrine.connection.orm_default',
    ],
    'My\\Endpoint\\V2\\Rest\\MyResource' => [
        'adapter_name'     => 'doctrine.connection.version2',
    ],
],
+1

All Articles