Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(metadata): Refactor metadata #56

Merged
merged 7 commits into from
Mar 15, 2024
Merged

feat(metadata): Refactor metadata #56

merged 7 commits into from
Mar 15, 2024

Conversation

joelwurtz
Copy link
Member

@joelwurtz joelwurtz commented Mar 13, 2024

This PR aim to improve metadata implementation in order to prepare the work for the attributes :

  • MapperMetadata : simple metadata about a mapper that is needed for runtime (basically a source / target and the mapper classname)
  • GeneratorMetadata : all metadata about how to generate a mapper (properties / variable registry / default configuration)
  • PropertyMetadata : all metadata about a property mapping for the generator, source, target and some configuration (max depth etc ...)
  • SourcePropertyMetadata : metadata about the source for a property mapping, the name, how to access it, if it's ignored, groups, the date time format to use if necessary, do we check if this attribute exist,
  • TargetPropertyMetadata : metadata about the target for a property mapping, the name, how to write it, does it may be write in constructor, if it's ignored, groups, the date time format to use if necessary

The goal will be that Attribute or other extension point only update those object to change how the generated code (like the name of the source / target property, if it's use the constructor, the date time format, if it's ignored, etc ....)

There is a lot of BC break, not sure if we could make it work with current version, i would merge this in a 9.0 with the new extensions point without doing a big layer for BC break, current change of interface are either new (8.2) or IMO too complicated / low level so that few people use them

@joelwurtz
Copy link
Member Author

Ready for review

@joelwurtz joelwurtz changed the base branch from main to 9.0 March 14, 2024 08:25
Copy link
Member

@Korbeil Korbeil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small stuff, LGTM otherwise 👍

src/Generator/PropertyConditionsGenerator.php Outdated Show resolved Hide resolved
src/Generator/PropertyConditionsGenerator.php Outdated Show resolved Hide resolved
src/Generator/PropertyConditionsGenerator.php Outdated Show resolved Hide resolved
src/Generator/PropertyConditionsGenerator.php Outdated Show resolved Hide resolved
src/Generator/PropertyConditionsGenerator.php Outdated Show resolved Hide resolved
src/Generator/PropertyConditionsGenerator.php Outdated Show resolved Hide resolved
src/Generator/PropertyConditionsGenerator.php Outdated Show resolved Hide resolved
* @param mixed $value Value to map
* @param array $context Options mapper have access to
* @param mixed $value Value to map
* @param array<string, mixed> $context Options mapper have access to
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we make an object to have a better typing there ? Or maybe it's too much for now and can be done later on ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could, but can be in another PR, this one is already big enough maybe create an issue to discuss on what to do for the context options in 9.0 ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair 👍

@@ -50,12 +50,12 @@ public function supportsNormalization(mixed $data, string $format = null, array
return false;
}

return $this->autoMapper->hasMapper($data::class, 'array');
return true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if it's something we can't map ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can always map :)

@Korbeil Korbeil merged commit b8b7d49 into 9.0 Mar 15, 2024
12 checks passed
@Korbeil Korbeil deleted the feat/metadata-refactor branch March 15, 2024 15:21
Korbeil added a commit that referenced this pull request Mar 25, 2024
* feat(metadata): Refactor metadata (#56)

* feat(metadata): Refactor metadata, split them depending on their roles, adapt transform interface with them

* feat(transformer): remove callback transformer

* feat(extractor): remove callback extractor

* feat(transformer): remove deprecation trigger

* chore(api): add internal everywhere it makes sense

* chore(cs): fix wrong case for variable

* feat(mapper): be nice with typing

* feat(event): add event system, make serializer optional

* feat(event): move map to context implementation to event listener

* feat(bundle): Merge bundle directly into automapper, will replace automapper-bundle (#63)

* feat(bundle): Merge bundle directly into automapper, will replace automapper-bundle

* Migrate to bundle PHP config

* chore(doc): update doc with new configuration / bundle namespace

* feat(bundle): add all possible configuration to the bundle

---------

Co-authored-by: Baptiste Leduc <baptiste.leduc@gmail.com>

* chore(deps): allow to use sf 5.4 for most things, remove useless deps / suggests (#68)

* feat(attribute): add map to attribute

* feat(map-to): add transformer support

* feat(map-to): throw exception if there is the same map to attribute for the same target

* Fixes

* feat(map-to): better callable support for transformer

* chore(doc): add documentation about MapTo attribute

* feat(attribute): add map-from attribute

* feat(map-to): make it works with methods

* chore(typo): fix variable name

* fix(map-to): split map to / map from, fix from array

* fix(event): use interface for class metadata factory

* fix(groups): don't map property if groups specified and no groups attached

* fix(normalize): don't map unexisting context, fix target to populate

* fix(transformer): check class exists when checking reflection class in object transformer factory

* feat(types): use a new interface to check types during runtime

* feat(types): use a type matching class for types, allow to make better relationship between types

* fix(ast): use correct php parser class

* feat(types): add doc on check type interface, use named parameters for event

* Update AutoMapper version for 9.0 branch

* fix(types): try to get types from read accessor / write mutator first

* feat(type): add new type extractor into bundle

* feat(map-to): add listeners to bundle

* feat(transformer): refactor the way to create custom transformer

* feat(if): add if feature to map to / map from attributes

* feat(if): allow to use a callable for if

* fix(types): correctly handle prometed properties

* fix(types): add documentation about why we need this extractor

* feat(map-to): allow map to / from attribute in class when declaring a transformer and a name

* Update CHANGELOG

* feat(attribute): add groups to map to / from attributes

* fix(map-from): correctly use method from target if asked

* feat(transformer): allow expression language for transformer, add provider for custom functions

* feat(transformer): add attribute to automatically bind service to expression language in bundle

* feat(bundle): allow to use eval loader instead of file

* fix(proxy): get real class name when a proxy is mapped in automapper

* fix(normalizer): don't normalize iterable object (array)

* fix(transformer): use current instead of dimension fetching, allow array not indexed by int

* fix(transformer): fix incorrect date time transformer guess

* fix: add tests for iterable normalizer, real class name and date time

* feat(mapper): correctly map from an inherited class

* feat(normalizer): add normalizer format in context

* feat(groups): add a flags to completly skip group checking for a property

* feat(normalizer): remove registry interface from normalizer as not needed

* chore(test): allow to run symfony app in tests

* chore(doc): reorganize documentation structure

* chore(doc): rewrite getting started and bundle part of the documentation

* Fix documentation build

* Fix documentation build

* chore(doc): add doc about mapping

* fix(serializer): fix map to overriding ignore / groups attribute from serializer

* chore(type): fix most phpstan issues

* Update CHANGELOG.md

* feat(normalizer): allow normalizer to only work with registered mapping

* feat(migrate): fix doc with new config, add migrate doc, add tests

* feat(mapper): add a way to instantiate object in mapper with providers

* Update CHANGELOG.md

* Small fixes

---------

Co-authored-by: Joel Wurtz <jwurtz@jolicode.com>
Co-authored-by: Joel Wurtz <joel.wurtz@gmail.com>
@nikophil nikophil mentioned this pull request May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants