🧩 Back to Open Source: Flexible Data Mapping with event4u/data-helpers
After several years working exclusively in startup environments, focusing on product‑driven internal development, I’ve finally found the time and motivation to return to the Open Source community.
To mark this shift, I’ve revived and rebuilt an old idea of mine: a lightweight PHP package that solves a common but often underestimated challenge — accessing and transforming deeply nested data.
Whether you're dealing with messy API responses, preparing clean outputs, or mapping between different internal structures — this package helps you extract and restructure data in a clear and consistent way.
🚀 What does the package do?
The main goal of event4u/data-helpers is to simplify access, mutation and mapping of structured data using dot notation and wildcards.
It’s framework‑agnostic and works well with Laravel, Symfony, or any plain PHP app.
Key features:
- 🔍 Dot notation access with support for wildcards (
*) - 🛠️ Helpers to map or mutate data structures
- ♻️ Reusable mapping definitions
- ✅ Type-safe, predictable, and testable transformations
- 🧩 Especially useful for APIs, DTOs, imports and exports
💡 Code Example
Say you get a messy API response like this:
// From this messy API response...
$apiResponse = [
'data' => [
'departments' => [
['users' => [['email' => 'alice@example.com'], ['email' => 'bob@example.com']]],
['users' => [['email' => 'charlie@example.com']]],
],
],
];
// ...to this clean result in one line
$accessor = new DataAccessor($apiResponse);
$emails = $accessor->get('data.departments.*.users.*.email');
// Result: ['alice@example.com', 'bob@example.com', 'charlie@example.com']
You can also use the Mapper class to define reusable transformations with default values, custom logic, and support for bidirectional mapping (e.g., for transforming requests and responses).
🤝 Looking for Feedback
This is just the beginning — the package already supports many advanced use cases, but I’m actively looking for ideas to improve it further.
If you:
- have ideas for features or syntax improvements
- encounter edge‑cases or bugs
- use it in a real PHP project and would like to share your experience
…I’d love to hear from you!
👉 GitHub: https://github.com/event4u-app/data-helpers
📚 Docs: https://event4u-app.github.io/data-helpers
Thanks for reading — I’m excited to contribute back to the open source community again!
Let me know what you think in the comments 💬
Top comments (3)
I see you have put a lot of effort in the library. The question I ask myself is does it really require much more code to do the same in PHP.
For your example in the post.
You got to love the
array_columnfunction and the spread operator.For an example from your documentation.
The PHP version
The most magic is in the sorting, but once you understand the spaceship operator you don't go back.
I'm sure there will be situations where your library will be useful. But for the most examples I have seen I would use plain PHP.
Hi, thank you for the answer. And i agree, you could do the same in plain PHP.
But that is like the question, why eloquent or doctrine? Why using the Query-Builder?
"SELECT * FROM users WHERE id = 3"would do the same as
USER::select('*')->where('id', 3);But the complexer the query might be, the more need for a simple/fluent query builder is there for some users. 😉
And to work with your example, the main goal was to work with template strings/expressions.
Still go with you, the PHP is still shorter. - But now you can build a template like this with a drag and drop editor and store it in a database.
This makes it possible, to map import files, api responses, etc. without any programming. 😊
That is the main reason for building this package. - But i agree with you, just for normal mapping, you might not need it. Even it could be helpful, if you don't know the spaceship operator or you like fluent and readable expressions, that everyone might understood.
Thank you for that great feedback and this real good example. ❤️
Sure I understand people like a fluent API, look at the success of Laravel. And if array templates are something that benefits the application you are building, the library is a solution.
I just looked at it from my perspective.
Oh, on the ORM's. I don't use them. Native queries are far more descriptive and robust.