-
I have an object that I want to convert back to an array. Currently I've found that passing $book = new Book(id: 1, title: 'Book Title');
$result = (array) $this->mapper->map($book, new \stdClass());
// ['id' => 1, 'title' => 'Book Title']; My question: is this the proper way of using the mapper, or can it be done another/better way? Read in the README that since Version: |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
As of 1.1, the mapper is fully capable of handling arrays as mentioned in the documentation. Thing is that array is supported, only not as the root object. The problem is now we are bound to In the future, I'll probably create something like I think I'll defer these decisions until after I migrate mapper to use In the meantime, I think you should create your own adapter for your use case. It would convert an array input to |
Beta Was this translation helpful? Give feedback.
As of 1.1, the mapper is fully capable of handling arrays as mentioned in the documentation. Thing is that array is supported, only not as the root object.
The problem is now we are bound to
MapperInterface
. I decided onmap()
taking an object and returning an object to simplify the job of those who want to extend the mapper.In the future, I'll probably create something like
MixedMapperInterface
that accepts and returns mixed. But I still have to figure out how to specify array as the target, do we use the string'array'
or specify an empty array[]
? Then there is a question on the use cases where the source is a collection, and we want to map it toarray<int,Something>
I think I'll defe…