在Apigility中忽略了水化器设置 [英] The hydrator settings are ignored in Apigility

查看:100
本文介绍了在Apigility中忽略了水化器设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Apigility中,可以通过Apigility UI为每个Entity设置一个Hydrator

In Apigility it's possible to set a Hydrator for every Entity -- either over the Apigility UI

或直接在module.config.php中,例如:

return array(
    ...
    'zf-hal' => array(
        'metadata_map' => array(
            'Portfolio\\V2\\Rest\\Project\\ProjectEntity' => array(
                'entity_identifier_name' => 'id',
                'route_name' => 'portfolio.rest.project',
                'route_identifier_name' => 'id',
                'hydrator' => 'Zend\\Stdlib\\Hydrator\\ObjectProperty',
                // 'hydrator' => 'MyNamespace\\Hydrator\\ProjectHydrator',
            ),
            ...
        ),
        ...
    ),
    ...
);

另请参见文档.

当前,我正在使用 ClassMethods 我所有实体的水化器.

Currently I'm using the ClassMethods hydrator for all my entities.

现在,我尝试将设置更改为自定义水龙头.我还尝试了另一个Zend水化器.但是无论我做什么,都只会忽略我在module.config.php中定义的水合.

Now I tried to change the setting to a custom hydrator. I've also tried another Zend hydrator. But whatever I do, only the hydrated I have defined in the `module.config.php is ignored.

编辑:它适用于单个实体,但不适用于集合.我已经在调试器中检查了一下,然后看到:当我回收一个集合时,不会调用我的自定义水化器.我无法确定实际使用了哪个水化器-我设置了断点,甚至在所有水化器(ArraySerializableClassMethodsObjectPropertyReflection,以及我的自定义ProjectHydrator)中,但应用程序根本没有注意到,并且仍在运行.看来根本没有水合作用...

EDIT: It works for sigle entities, but not for collections. I've checked this with the debugger and see: when I retieve a collection, my custom hydrator doesn't get called. I cannot find out, which hydrator is actually being used -- I set breakpoints and even wrote die()s in the extract() and hydrate() methods of all hydrators (ArraySerializable, ClassMethods, ObjectProperty, Reflection, and also in my custom ProjectHydrator), but the application didn't notice that at all and is still working. Seems so, that no hydration is made at all...

这有什么问题,以及如何使水合设置正常工作?

推荐答案

旧,但是发现了这一点: 对于collectionRender,不调用水化器 https://github.com/zfcampus/zf -hal/blob/master/src/Plugin/Hal.php#L570

Old but found this: For collectionRender the hydrator is not called https://github.com/zfcampus/zf-hal/blob/master/src/Plugin/Hal.php#L570

对于entityRender,为: https://github.com/zfcampus/zf -hal/blob/master/src/Plugin/Hal.php#L695

For entityRender is: https://github.com/zfcampus/zf-hal/blob/master/src/Plugin/Hal.php#L695

需要为此打电话.

编辑[07.10.16]:

Edit[07.10.16]:

我错了.

我的解决方案适用于Apigility 1.3.没有测试早期版本.

My solution works with Apigility 1.3. Didn't test earlier versions.

您可以使用Zend\\Hydrator\\DelegatingHydrator

        'metadata_map' => array(
        'Test\\DomainModel\\UseCase\\Query\\ShowTask\\Response\\Task' => array(
            'entity_identifier_name' => 'uuid',
            'route_name' => 'descriptive-module.rest.task',
            'route_identifier_name' => 'task_id',
            'hydrator' => 'Zend\\Hydrator\\DelegatingHydrator',
        ),
        'Test\\DomainModel\\UseCase\\Query\\ListTask\\Response\\Task' => array(
            'entity_identifier_name' => 'uuid',
            'route_name' => 'descriptive-module.rest.task',
            'route_identifier_name' => 'task_id',
            'hydrator' => 'Zend\\Hydrator\\DelegatingHydrator',
        ),

第一个,对于实体. 第二个,返回的Collection的元素.

First one, for entity. Second one, elements of returned Collection.

然后在module.config.php中

Then in module.config.php

   'hydrators' => array(
    'invokables' => array(
        \Test\DomainModel\UseCase\Query\ShowTask\Response\Task::class =>
            \TestApi\V1\Rest\Task\Hydrator\ShowTaskHydrator::class,
        \Test\DomainModel\UseCase\Query\ListTask\Response\Task::class =>
            \TestApi\V1\Rest\Task\Hydrator\ListTaskHydrator::class,
    ),
    'factories' => array(),
),

TaskShowHydrator/ListTaskHydrator需要工具Zend\Hydrator\HydratorInterface

这篇关于在Apigility中忽略了水化器设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆