Skip to content

Conversation

SDekkers
Copy link

@SDekkers SDekkers commented Aug 31, 2025

Summary

  • Migrated from the abandoned spatie/data-transfer-object to the actively maintained spatie/laravel-data package
  • Refactored BaseDTO class to implement custom property initialization and type casting without inheritance
  • Enhanced array conversion and serialization methods for improved data handling
  • Updated all related DTO classes and collections to work with the new implementation

Changes Made

  • BaseDTO.php: Complete refactor removing DataTransferObject inheritance, added custom __construct(), property initialization, type
    casting, and improved toArray() methods
  • BaseDTOCollection.php: Updated template annotations for better type safety
  • ExtractedEndpointData.php: Enhanced serialization logic for better array handling
  • Parameter.php: Improved array conversion methods
  • composer.json: Updated dependency from spatie/data-transfer-object to spatie/laravel-data ^3.0|^4.0

Benefits

  • ✅ Uses actively maintained package (spatie/laravel-data)
  • ✅ Better Laravel integration and modern PHP features
  • ✅ Improved type safety and validation capabilities
  • ✅ Enhanced array handling and serialization
  • ✅ Maintains backward compatibility

Test Plan

  • All existing tests pass
  • DTO instantiation works correctly
  • Array conversion maintains expected format
  • Collection handling functions properly
  • No breaking changes to public API

Replaced spatie/data-transfer-object with spatie/laravel-data in BaseDTO and related classes. Refactored BaseDTO to remove inheritance from DataTransferObject, added custom property initialization, type casting, and improved array conversion methods. Updated BaseDTOCollection template and improved serialization logic in ExtractedEndpointData and Output/Parameter. Updated composer.json dependencies accordingly.
@SDekkers SDekkers changed the title Refactor DTOs to use spatie/laravel-data and improve array handling Replace abandoned spatie/data-transfer-object with spatie/laravel-dat Aug 31, 2025
@SDekkers SDekkers changed the title Replace abandoned spatie/data-transfer-object with spatie/laravel-dat Replace abandoned spatie/data-transfer-object with spatie/laravel-data Aug 31, 2025
@andrija535
Copy link

Did you hear back anything related to this?

Copy link
Contributor

@s-shiryaev s-shiryaev left a comment

Choose a reason for hiding this comment

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

I see the goal is to remove the abandoned dependency. Currently, this is achieved by moving its logic into our own BaseDTO, not by adopting spatie/laravel-data as the title and description suggests.

To align with the description, we would need to actually integrate spatie/laravel-data. Otherwise, the title and description should be updated to reflect that this is an internal refactor. In this case, the unused spatie/laravel-data dependency should also be removed.

As a side note, this internal refactor could serve as a quick path to PHP 9.0 support, whereas a full migration to spatie/laravel-data might require more work.

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.

3 participants