Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

MapNamingStrategy vs. ArrayMapNamingStrategy #9

Closed
adamlundrigan opened this issue Oct 27, 2015 · 3 comments
Closed

MapNamingStrategy vs. ArrayMapNamingStrategy #9

adamlundrigan opened this issue Oct 27, 2015 · 3 comments

Comments

@adamlundrigan
Copy link

Do we need both? From what I can deduce (from source and the PR that introduced ArrayMapNamingStrategy) they're nearly identical except:

  • MapNamingStrategy's argument is a hydration map and ArrayMapNamingStrategy is an extraction map. Both then flip the array to get the mapping for the opposite direction.
  • MapNamingStrategy allows overriding the reverse map, in case you want an asymmetrical mapping.
@froschdesign
Copy link
Member

@adamlundrigan

Do we need both?

I see no reason for this. Because:

…they're nearly identical except

Right.

@froschdesign froschdesign added this to the 3.0.0 milestone Oct 27, 2017
@weierophinney
Copy link
Member

What's interesting is that they operate in the exact opposite fashion with regards to the required initial constructor argument.

With ArrayMapNamingStrategy, that initial argument is used for extraction, and flipped for hydration.

With MapNamingStrategy, that initial argument is used for hydration, and flipped for extraction (unless a second argument is provided; that's used for extraction in that case).

As such, we would need to do a constructor that looks like this:

function (?array $extractionMap = null, ?array $hydrationMap = null)

I'll start work on this immediately.

weierophinney added a commit to weierophinney/zend-hydrator that referenced this issue Nov 29, 2018
Per zendframework#9, the two perform almost identical functionality; the main
difference is _which argument is first in the constructor_, and the fact
that `MapNamingStrategy` allowed a second argument for the opposite
direction.

This patch merges the two into `MapNamingStrategy`. The class is now
final (as was `ArrayMapNamingStrategy`, and accepts either a
`$hydrationMap` or an `$extractionMap` or both. If both are missing, it
raises an exception. If one or the other is missing, the value becomes
that of the `array_flip` of the other value present.

The patch includes a migration document section detailing the changes,
and expands the `MapNamingStrategy` documentation to cover all use
cases.
weierophinney added a commit to weierophinney/zend-hydrator that referenced this issue Dec 3, 2018
Per zendframework#9, the two perform almost identical functionality; the main
difference is _which argument is first in the constructor_, and the fact
that `MapNamingStrategy` allowed a second argument for the opposite
direction.

This patch merges the two into `MapNamingStrategy`. The class is now
final (as was `ArrayMapNamingStrategy`, and accepts either a
`$hydrationMap` or an `$extractionMap` or both. If both are missing, it
raises an exception. If one or the other is missing, the value becomes
that of the `array_flip` of the other value present.

The patch includes a migration document section detailing the changes,
and expands the `MapNamingStrategy` documentation to cover all use
cases.
@weierophinney
Copy link
Member

Fixed with #82, and will be shipped with 3.0.0.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants