-
-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Should we add more file types and custom decoders/encoders? #167
Comments
Hi Timur, yes it is a good idea, especially, if the user wants to implement rest API, where the other end, needs a specific file type, for communicating. |
I suggest for a first release to create a json_encode Encoder/Decoder (Wrapper) and an Interface for that. interface SaveStrategyInterface {
public function decode(string $data) : array;
public function encode(array $data) : string;
public function getFileExtension() : string;
}
class JsonSaveStrategy implements SaveStrategyInterface {
private $file_extension = '.json';
public function decode(string $data): array
{
try {
return json_decode($data);
} catch (\Exception $exception) {
return [];
}
}
public function encode(array $data): string
{
try {
return json_encode($data);
} catch (\Exception $exception) {
return '';
}
}
public function getFileExtension(): string
{
return $this->file_extension;
}
} Next to that, we should add an option to the Store constructor, to provide the Strategy-Class. |
Hay all, I've just come to use this library and have hit a wall where I am having to jump through some hoops to custom serialize my data before storage and custom deserialize after storage. I would think this could be one of the best additions to this library, and as a default implementation, use Zumba JsonSerializer to have a quick turnaround. |
We could add the ability to save the documents in a different file format, for example in plain txt files or yaml files.
To achieve that we could provide a file format configuration and hooks for the users, where they can apply their own encoder/decoder.
This is just an idea and I am not sure if there is a use case for such a feature.
I would like to hear your opinions.
The text was updated successfully, but these errors were encountered: