Ticket #138 (new defect)

Opened 7 months ago

Last modified 7 months ago

Solar_Locale::fetch() generates a miss-configured parents directory stack. (Affects Solar_Auth!)

Reported by: umka.dk@… Owned by: pmjones
Priority: critical Component: code
Keywords: Solar_Locale, Solar_Auth Cc:

Description

From what I can work out, Solar_Locale::fetch() does not determine correctly a directory stack ($parents) of where possible locale files may reside when the framework is configured to use a custom locale class which uses a locale other then one of the supplied defaults. In other words, the bug is present when the following conditions are true:

  1. My_Locale extends Solar_Locale
  2. My_Locale::setCode('en_GB')

This results in a key=>value file for a custom locale class never being read by Solar_Auth (as executed by Solar_User). If the locale file is never read then Solar_Auth has no way of determining if a current form submission is a login attempt or not, as a result a valid user will not be able to login and no error message will be displayed.

Attachments

Change History

Changed 7 months ago by anonymous

Possible solution is to update Solar_Locale::fetch() to check if a non standard locale is in use and to append that locales parent stack to the reported class stack. I doubt if this is the best solution but it seems to fix the problem, at least temporarily.

Solar_Locale (+181):

        // find all parents of the class, including the class itself
        $parents = Solar::parents($class, true);
        
        // check current locale class in use and add its vendor namespace to 
        // the stack of vendor-wide strings if using a non-default locale.
        if (Solar_Registry::exists('locale')) {
            $locale = Solar_Registry::get('locale');
            $lparents = Solar::parents($locale, true);
            // remove _Locale prefix from the class names in order not to 
            // confuse $this->_load method which will look for locale files 
            // in class_name/Locale directory.
            array_walk($lparents, create_function('&$val, $key',
                'if (substr($val, -7) == "_Locale") {
                    $val = substr_replace($val, "", -7);
                }'));
            // merge locale parents with class parents.
            $parents = array_merge($parents, $lparents);
        }
        
        // add the vendor namespace to the stack for vendor-wide strings,
        // and add Solar as the final fallback.
        $pos = strpos($class, '_');
        if ($pos !== false) {
            $vendor = substr($class, 0, $pos);
            $parents[] = $vendor;
            if ($vendor != 'Solar') {
                $parents[] = 'Solar';
            }
        } else {
            $parents[] = 'Solar';
        }
        
        // clean created parents array of any duplicate values.
        $parents = array_unique($parents);
        
        // go through all parents and find the first matching key
        foreach ($parents as $parent) { ...

Add/Change #138 (Solar_Locale::fetch() generates a miss-configured parents directory stack. (Affects Solar_Auth!))

Author



Action
as new
 
Note: See TracTickets for help on using tickets.