There is no meaning of PHP convention to Node.JS side in some cases.
For example user roles of array by symfony.
class Role {}
data = Serialize.unserialize(data, {
'Symfony\\Component\\Security\\Core\\Role\\Role': Role
});
[ Role {
'\u0000Symfony\\Component\\Security\\Core\\Role\\Role\u0000role': 'ROLE_USER' } ]
I wanted to get flat array like following.
I don't know how could be implemented in this use case scenarios.
But I have some suggestions.
Option 1
Refiner base class from library.
const Serialize = require('php-serialize')
class Role extends Serialize.Refiner {
refine(fields, className) {
return fields.role.value;
}
}
fields property can have this structure
{
"role": {
"value": "ROLE_USER",
"type": "private" // or enum value like public: 1, protected: 2, private: 3
}
}
className property can have the class name like 'Symfony\\Component\\Security\\Core\\Role\\Role'
className property required to use same refiner on different classes.
Option 2
Anonymous functions
const refiner = (fields, className) => {
return fields.role.value;
};
data = Serialize.unserialize(data, {
'Symfony\\Component\\Security\\Core\\Role\\Role': refiner
});