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

Using a Filesystem cache storage adapter results in an exception #10

Closed
weierophinney opened this issue Dec 31, 2019 · 1 comment · Fixed by #123
Closed

Using a Filesystem cache storage adapter results in an exception #10

weierophinney opened this issue Dec 31, 2019 · 1 comment · Fixed by #123
Assignees

Comments

@weierophinney
Copy link
Member

Object of class Zend\I18n\Translator\TextDomain could not be converted to string

Switching to another adapter (like memory) works fine, looks like this happens because Filesystem doesn’t do any serialization, just:

// Zend\Cache\Storage\Adapter\Filesystem::putFileContent()
if (! is_string($data)) {
    // Ensure we have a string
    $data = (string) $data;
}

I’m not sure if Translator should serialize the TextDomain object before storing it, or if this is more a bug in the cache adapter. Perhaps we should check whether the cache can indeed store objects by using $cache->getCapabilities(), and serialize it if not?


Originally posted by @kinglozzer at zendframework/zend-i18n#44

@weierophinney
Copy link
Member Author

@kinglozzer

the following works for me:

try installing zend-serializer and this configuration (i use a global config file for i18n in order to have language files inside a /path/to/app/lang dir, you can use a per-module config with getcwd() call replaced by __DIR__)

return [
//...
    'translator' => [
        //..
        'cache' => [
            'adapter' => [
                'name' => 'filesystem',
                'options' => [
                    'cache_dir' => getcwd() . '/data/cache',
                    'ttl'       => 3600,
                ],
            ],
            'plugins' => [
                'serializer',
                'exception_handler' => [
                    'throw_exceptions' => false,
                ],
            ],
        ],
    ];

kind regards,
maks


Originally posted by @pine3ree at zendframework/zend-i18n#44 (comment)

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

Successfully merging a pull request may close this issue.

2 participants