Skip to content

Commit ee9a017

Browse files
author
david-kurniawan
committed
more fixed
1 parent f650cb0 commit ee9a017

File tree

4 files changed

+51
-73
lines changed

4 files changed

+51
-73
lines changed

src/Validator.php

Lines changed: 51 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,61 @@
22

33
namespace Validvid\Validation;
44

5-
use Illuminate\Container\Container;
5+
use Illuminate\Validation;
6+
use Illuminate\Translation;
7+
use Illuminate\Validation\Factory;
68
use Illuminate\Filesystem\Filesystem;
79
use Illuminate\Translation\FileLoader;
810
use Illuminate\Translation\Translator;
9-
use Illuminate\Validation\Factory;
1011

1112
class Validator
1213
{
13-
public function make(array $data, array $rules)
14-
{
15-
try {
16-
$loader = new FileLoader(new Filesystem, 'lang');
17-
$translator = new Translator($loader, 'en');
18-
$validation = new Factory($translator, new Container);
19-
20-
return $validation->make($data, $rules);
21-
} catch (\Exception $e) {
22-
return $e->getMessage();
23-
}
24-
}
14+
public $lang;
15+
public $group;
16+
public $factory;
17+
public $namespace;
18+
public $basePath;
19+
public static $translator;
20+
21+
public function __construct($namespace = 'lang', $lang = 'en', $group = 'validation')
22+
{
23+
$this->lang = $lang;
24+
$this->group = $group;
25+
$this->namespace = $namespace;
26+
$this->basePath = $this->getTranslationsRootPath();
27+
$this->factory = new Factory($this->loadTranslator());
28+
}
29+
30+
public function translationsRootPath(string $path = '')
31+
{
32+
if (!empty($path)) {
33+
$this->basePath = $path;
34+
$this->reloadValidatorFactory();
35+
}
36+
return $this;
37+
}
38+
39+
private function reloadValidatorFactory()
40+
{
41+
$this->factory = new Factory($this->loadTranslator());
42+
return $this;
43+
}
44+
45+
public function getTranslationsRootPath() : string
46+
{
47+
return dirname(__FILE__) . '/';
48+
}
49+
50+
public function loadTranslator() : Translator
51+
{
52+
$loader = new FileLoader(new Filesystem(), $this->basePath . $this->namespace);
53+
$loader->addNamespace($this->namespace, $this->basePath . $this->namespace);
54+
$loader->load($this->lang, $this->group, $this->namespace);
55+
return static::$translator = new Translator($loader, $this->lang);
56+
}
57+
58+
public function __call($method, $args)
59+
{
60+
return call_user_func_array([$this->factory, $method], $args);
61+
}
2562
}

src/lang/en/auth.php

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/lang/en/pagination.php

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/lang/en/passwords.php

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)