From 367ec9a7c79ea928eadc2ea9e6954cd50091da71 Mon Sep 17 00:00:00 2001 From: Marcos Neves Date: Sat, 17 Aug 2013 12:41:58 -0300 Subject: [PATCH] fix bug moving message loading to constructor and replace require with include to avoid fatal error --- src/Valitron/Validator.php | 8 ++------ tests/Valitron/StaticVsInstanceTest.php | 4 ++-- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/Valitron/Validator.php b/src/Valitron/Validator.php index cb7cc8e..04a6244 100644 --- a/src/Valitron/Validator.php +++ b/src/Valitron/Validator.php @@ -44,8 +44,8 @@ class Validator // set langDir in the follow order: constructor param, static::$_langDir, default to package lang dir $langDir = $langDir ?: static::langDir(); - static::langDir($langDir); - static::lang($lang); + // Load language file in directory + static::$_ruleMessages = include rtrim($langDir, '/') . '/' . $lang . '.php'; } /** @@ -55,10 +55,6 @@ class Validator { if($lang !== null) { static::$_lang = $lang; - - // Load language file in directory - $langDir = static::langDir(); - static::$_ruleMessages = require rtrim($langDir, '/') . '/' . $lang . '.php'; } return static::$_lang ?: 'en'; } diff --git a/tests/Valitron/StaticVsInstanceTest.php b/tests/Valitron/StaticVsInstanceTest.php index 17d5d8a..c83dad4 100644 --- a/tests/Valitron/StaticVsInstanceTest.php +++ b/tests/Valitron/StaticVsInstanceTest.php @@ -3,11 +3,11 @@ use Valitron\Validator; class StaticVsInstanceTest extends BaseTestCase { - public function testInstanceOverrideStatic() + public function testInstanceOverrideStaticLang() { Validator::lang('ar'); new Validator(array(), array(), 'en'); $this->assertEquals('ar', Validator::lang(), - 'lang defined statically should not be override by instance lang'); + 'instance defined lang should not replace static global lang'); } }