zendframework / zend-i18n

I18n component from Zend Framework
BSD 3-Clause "New" or "Revised" License
65 stars 49 forks source link

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

Open kinglozzer opened 8 years ago

kinglozzer commented 8 years ago

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?

pine3ree commented 8 years ago

@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

weierophinney commented 4 years ago

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.