zend-i18n icon indicating copy to clipboard operation
zend-i18n copied to clipboard

Using a Filesystem cache storage adapter results in an exception

Open kinglozzer opened this issue 8 years ago • 2 comments

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?

kinglozzer avatar Apr 15 '16 09:04 kinglozzer

@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

pine3ree avatar Aug 01 '16 20:08 pine3ree

This repository has been closed and moved to laminas/laminas-i18n; a new issue has been opened at https://github.com/laminas/laminas-i18n/issues/10.

weierophinney avatar Dec 31 '19 23:12 weierophinney