Open sPooKee opened 9 years ago
I think, changing the behaviour in the constructor at this point is a bad idea. (This can be a BC break.)
But you can use the setLocale
method:
public function testIgnoreLocaleFromRegistry()
{
require_once 'Zend/Registry.php';
Zend_Registry::set('Zend_Locale', new Zend_Locale('de_AT'));
$validator = new Zend_Validate_Iban();
$validator->setLocale(false);
$this->assertTrue($validator->isValid('DE68210501700012345678'));
}
@froschdesign In your Example Zend_Validate_Iban will still use de_AT
, because empty($locale)
is still false
.
By the way, I've just overwritten the class and used the following in my __construct()
function:
...
if (false !== $locale && empty($locale)) {
require_once 'Zend/Registry.php';
if (Zend_Registry::isRegistered('Zend_Locale')) {
$locale = Zend_Registry::get('Zend_Locale');
}
}
...
In your Example Zend_Validate_Iban will still use de_AT, because empty($locale) is still false.
No. Please have a look:
$validator->setLocale(false);
Ah, okay, sorry, I see ;) But that doesn't help me in a "short" FormElement creation:
...
$e['IBAN'] = $this->createElement('text', 'IBAN')
->addFilters([
['StringTrim'],
['StringToUpper']
])
->addValidators([
['Iban', false, ['locale'=> false]],
])
->setRequired();
...
But that doesn't help me in a "short" FormElement creation:
->addValidators(
[
call_user_func(function () {
$validator = new Zend_Validate_Iban();
$validator->setLocale(false);
return $validator;
}),
])
:wink:
The problem still exists: This can be a BC break.
An Ungreedy IBAN validation with
new Zend_Validate_Iban(['locale' => false])
is not possible, if you have aZend_Locale
in yourZend_Registry
.Zend/Validate/Iban.php:143ff sets
$locale = $locale['locale'];
, which isfalse
, and sinceempty(false)
istrue
,$locale
gets overwritten byZend_Registry::get('Zend_Locale');
.