zf-doctrine-hydration-module icon indicating copy to clipboard operation
zf-doctrine-hydration-module copied to clipboard

Strategies from the service manager

Open matwright opened this issue 9 years ago • 1 comments

Each of the Hydrator strategies are configured in the service manager as invokable services. However within the module, the Hydrator strategy objects are instantiated from the class directly rather than via the service manager. For example in the EmbeddedReferenceField class:

        $strategy = new EmbeddedField($this->getObjectManager());
        $strategy->setClassMetadata($this->getClassMetadata());
        $strategy->setCollectionName($this->getCollectionName());
        $strategy->setObject($value);

It prevents being able to override the strategy via the service manager.

I know it is possible to configure custom strategies per field for an entity, however sometimes it may be desirable to set specific logic for all EmbeddedFields for example and therefore an option to set a custom EmbeddedFieldsStrategy without having to configure each specific embed field in every entity.

matwright avatar Jul 09 '16 12:07 matwright

The problem is that the base hydrator does not make it possible to inject any additional services. This means this is something that could be fixed for the ODM DoctrineObject, but won't work for ORM. I would like to keep both as in-sync as possible :)

veewee avatar Jul 14 '16 05:07 veewee