Skip to content
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

Open
Timu57 opened this issue Mar 6, 2021 · 3 comments
Open

Should we add more file types and custom decoders/encoders? #167

Timu57 opened this issue Mar 6, 2021 · 3 comments

Comments

@Timu57
Copy link
Member

Timu57 commented Mar 6, 2021

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.

@REDAL
Copy link

REDAL commented Mar 8, 2021

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.

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.

@basteyy
Copy link

basteyy commented May 21, 2022

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.

@designermonkey
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants