fix bug moving message loading to constructor and replace require with include to avoid fatal error

This commit is contained in:
Marcos Neves 2013-08-17 12:41:58 -03:00
parent ca4f6737dc
commit 367ec9a7c7
2 changed files with 4 additions and 8 deletions

View File

@ -44,8 +44,8 @@ class Validator
// set langDir in the follow order: constructor param, static::$_langDir, default to package lang dir // set langDir in the follow order: constructor param, static::$_langDir, default to package lang dir
$langDir = $langDir ?: static::langDir(); $langDir = $langDir ?: static::langDir();
static::langDir($langDir); // Load language file in directory
static::lang($lang); static::$_ruleMessages = include rtrim($langDir, '/') . '/' . $lang . '.php';
} }
/** /**
@ -55,10 +55,6 @@ class Validator
{ {
if($lang !== null) { if($lang !== null) {
static::$_lang = $lang; static::$_lang = $lang;
// Load language file in directory
$langDir = static::langDir();
static::$_ruleMessages = require rtrim($langDir, '/') . '/' . $lang . '.php';
} }
return static::$_lang ?: 'en'; return static::$_lang ?: 'en';
} }

View File

@ -3,11 +3,11 @@ use Valitron\Validator;
class StaticVsInstanceTest extends BaseTestCase class StaticVsInstanceTest extends BaseTestCase
{ {
public function testInstanceOverrideStatic() public function testInstanceOverrideStaticLang()
{ {
Validator::lang('ar'); Validator::lang('ar');
new Validator(array(), array(), 'en'); new Validator(array(), array(), 'en');
$this->assertEquals('ar', Validator::lang(), $this->assertEquals('ar', Validator::lang(),
'lang defined statically should not be override by instance lang'); 'instance defined lang should not replace static global lang');
} }
} }