ZF-7099: Translate_Adapter: setOptions calls setLocale with wrong parameter

Description

In the setOptions, you search for the 'locale' key and if found you set the variable $locale. Then, if all the options are processed, you will set the locale by calling setLocale with as parameter the latest option you processed. And that isn't always the locale option. So you call the setLocale with an unpredictable value.


public function setOptions(array $options = array())
    {
        // *****
        $locale = null;
        foreach ($options as $key => $option) {
            if ($key == 'locale') {
                $locale = $option;
            } else if ((isset($this->_options[$key]) and ($this->_options[$key] != $option)) or
                // ****
            }
        }

        if ($locale !== null) {
            $this->setLocale($option);
        }
        //******
    }

Fix is of course use the $locale variable:


public function setOptions(array $options = array())
    {
        // *****
        $locale = null;
        foreach ($options as $key => $option) {
           //****
        }

        if ($locale !== null) {
            $this->setLocale($locale);
        }
        //******
    }

Comments

In Incubator since r16320, waiting for code review of r16247

Accepted and integrated into core with r16883.