Skip to content

Comments

fix(media): restore Media state on unserialize from Doctrine cache#88

Open
BriceFab wants to merge 1 commit intojolicode:mainfrom
BriceFab:fix/media-unserialize-slc-87
Open

fix(media): restore Media state on unserialize from Doctrine cache#88
BriceFab wants to merge 1 commit intojolicode:mainfrom
BriceFab:fix/media-unserialize-slc-87

Conversation

@BriceFab
Copy link

@BriceFab BriceFab commented Feb 12, 2026

Summary

  • add Media::__unserialize() so cached Media instances restore typed properties correctly
  • keep backward compatibility with legacy indexed payloads ([0 => path, 1 => library])
  • register Media::$resolverInitializer in bundle boot (same resolver used by Doctrine media types)
  • add regression tests for serialize/unserialize behavior

Problem

When an entity containing JoliCode\MediaBundle\Model\Media is read from Doctrine second-level cache, unserialization may create dynamic properties ($0, $1) instead of restoring constructor-backed typed properties.

This can leave $path uninitialized and later crash at runtime when getPath() is accessed.

Validation

  • added tests in tests/src/Model/MediaTest.php for:
    • serialize/unserialize roundtrip
    • legacy indexed payload support
  • syntax checks on modified files

Fixes #87

cc @xavierlacot

@BriceFab BriceFab changed the title Fix Media unserialization when loaded from Doctrine cache fix(media): restore Media state on unserialize from Doctrine cache Feb 12, 2026
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.

Doctrine second-level cache unserializes Media with uninitialized typed properties

1 participant