flow icon indicating copy to clipboard operation
flow copied to clipboard

[Proposal]: Make EntryFactory configurable

Open norberttech opened this issue 2 months ago • 1 comments

Describe the Proposal

Currently EntryFactory comes with set of predefined rules. This is convenient but also very limiting (can't be extended by user).

The idea is simple, make EntryFactory configurable by allowing to register type mappings.

EntryFactory works in two modes:

  • manual - when we know what Entry type we want to get for passed value
  • automated - when we just have value and we want entry factory to figure out the best entry type for it

The manual part is covered by EntryFactory::createAs() method that requires Definition|Type, the automated one is EntryFactory::create().

So now what happens is that when create is used without Schema|Definition it would try to use TypeDetector() to guess the type.

Then we should create a second map, SplObjectStorage<Type, EntryType> that would be used in EntryFactory::createAs method.

This way we give users full control over what input can be mapped into what entry type.

But to make it possible, we also need to make sure that literally everywhere in the DataFrame (all scalar functions, transformations, transformers) EntryFactory is taken from FlowContext. Once this condition is meet, we can add to src/core/etl/src/Flow/ETL/Config/ConfigBuilder.php method to replace default EntryFactory

API Adjustments

Add possibility to modify EntryFactory in Config Builder:

ConfigBuilder::entryFactory(EntryFactory $factory)

Add maps of map<Type,Narrower> and map<Type,class-string<EntryType>>

This would be great first step towards allowing externa libraries/adapters to register custom Entries and Types

Are you intending to also work on proposed change?

Yes

Are you interested in sponsoring this change?

None

Integration & Dependencies

No response

norberttech avatar Oct 28 '25 14:10 norberttech

https://github.com/flow-php/flow/pull/1943 we decided to move away from using type narrowers in entry factory to make it more predictable. So narrowers are no longer needed in configurable EntryFactory 🎉

norberttech avatar Nov 05 '25 10:11 norberttech