Ryan H
Ryan H

Reputation: 547

How to tell API version from Zend routing

I recently picked up a client's old project. It was originally developed using Zend framework, which is a new one to me. I'm trying to modify the correct file but they have three versions of the API.

in the module.config they have the route as:

'api.rest.social-credential' => array(
                'type' => 'Segment',
                'options' => array(
                    'route' => '/social-credential[/:social_credential_id]',
                    'scheme' => 'http',
                    'defaults' => array(
                        'controller' => 'Api\\V1\\Rest\\SocialCredential\\Controller',
                    ),
                ),
            ),

To me this means the controller I should be looking at is v1 or Api\\V1\\Rest\\SocialCredential\\Controller However, when looking through the code and seeing how the server responds it is clearly running v3.

The two Controllers are defined as follows: v1

'Api\\V1\\Rest\\SocialCredential\\Controller' => array(
            'listener' => 'Api\\V1\\Rest\\SocialCredential\\SocialCredentialResource',
            'route_name' => 'api.rest.social-credential',
            'route_identifier_name' => 'social_credential_id',
            'collection_name' => 'social_credential',
            'entity_http_methods' => array(
                0 => 'PATCH',
            ),
            'collection_http_methods' => array(),
            'collection_query_whitelist' => array(),
            'page_size' => '25',
            'page_size_param' => '',
            'entity_class' => 'Api\\V1\\Rest\\SocialCredential\\SocialCredentialEntity',
            'collection_class' => 'Api\\V1\\Rest\\SocialCredential\\SocialCredentialCollection',
            'service_name' => 'SocialCredential',
        ),

v3

'Api\\V3\\Rest\\SocialCredential\\Controller' => array(
            'listener' => 'Api\\V3\\Rest\\SocialCredential\\SocialCredentialResource',
            'route_name' => 'api.rest.social-credential',
            'route_identifier_name' => 'social_credential_id',
            'collection_name' => 'social_credential',
            'entity_http_methods' => array(
                0 => 'PATCH',
                1 => 'DELETE',
            ),
            'collection_http_methods' => array(),
            'collection_query_whitelist' => array(),
            'page_size' => '25',
            'page_size_param' => '',
            'entity_class' => 'Api\\V3\\Rest\\SocialCredential\\SocialCredentialEntity',
            'collection_class' => 'Api\\V3\\Rest\\SocialCredential\\SocialCredentialCollection',
            'service_name' => 'SocialCredential',
        ),

I find nothing in the module.config that makes me believe that v3 should be the target other then this definition existing. Either I'm missing something or I don't understand how Zend routing works. Could someone shed some light on this please?

Upvotes: 0

Views: 352

Answers (1)

Ryan H
Ryan H

Reputation: 547

Finally found it, the default_version under zf-versioning

'zf-versioning' => array(
        'uri' => array(
            ...
            13 => 'api.rest.social-credential',
        ),
        'default_version' => 3,
    ),

More info here: https://github.com/zfcampus/zf-versioning

Upvotes: 1

Related Questions