Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

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

Open
kinglozzer opened this issue Apr 15, 2016 · 2 comments
Open

Comments

@kinglozzer
Copy link

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
Copy link
Contributor

pine3ree commented Aug 1, 2016

@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
Copy link
Member

This repository has been closed and moved to laminas/laminas-i18n; a new issue has been opened at laminas/laminas-i18n#10.

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

No branches or pull requests

3 participants