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

ignore proxy object if not in hierarchy #1413

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mpoiriert
Copy link
Contributor

Q A
Bug fix? maybe
New feature? yes
Doc updated no
BC breaks? maybe
Deprecations? no
Tests pass? will see
Fixed tickets #...
License MIT

This is to cover a use case like this:

class MyEntity
{

  /**
   * @Serializer\Type("App\DTO\OtherEntity")
   */
  private OtherEntity $composition;
}

Currently the code will only work if the class is not currently loaded (since the class_exists don't use the autoload). But if the class is already loaded (E.g. Second object that go trough that loop).

This give the option to create a handler on a existing class like this:

 public function serializeOtherEntity(
        JsonSerializationVisitor $visitor,
        $value,
        array $type,
        Context $context
    ) {
        if (null === $value) {
            return null;
        }

        if ($value instanceof OtherEntity) {
            throw new SkipHandlerException();
        }

        return $context->getNavigator()->accept(new OtherEntity($value));
    }

From my point of view it's a bug fix since I would have expect this to work like this but we can consider it a new feature. It should be backward compatible since nobody would have done this since the behaviour is bugged.

@mpoiriert
Copy link
Contributor Author

mpoiriert commented Jun 23, 2022

@goetas Is there any change this would be merge ? Other wise I will do something else on my code base.

@goetas
Copy link
Collaborator

goetas commented Aug 6, 2022

hmm, this is weird. the uses case covered by that piece of code should handle this situation:

class MyEntity
{

  /**
   * @Serializer\Type("SOME_INTENTIONAL_WRONG_CLASS_NAME_USED_FOR_A_TYPE_HANDLER")
   */
  private OtherEntity $composition;
}

So a type handler registers on SOME_INTENTIONAL_WRONG_CLASS_NAME_USED_FOR_A_TYPE_HANDLER and does what needs to be done....

if the type-hint is the same as the class name, than i'm not sure what is the expected behaviour. can you please clarify?

(sorry for the late answer)

@mpoiriert
Copy link
Contributor Author

The issue is that your test is done with an arbitrary string that is not a real class. My use case is with a real class that does exists 'App\DTO\OtherEntity'.

Check at my PR if you want more context.

After that I will also have another issue for my use case but I will open another ticket for it. (Using two different type for the same object in the same execution flow).

@mpoiriert
Copy link
Contributor Author

@goetas Any decision on this ?

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.

2 participants