phpro / zf-doctrine-hydration-module

Configurable Doctrine hydrators for ZF2
18 stars 33 forks source link

Strategies from the service manager #34

Open matwright opened 8 years ago

matwright commented 8 years ago

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.

veewee commented 8 years ago

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 :)