Skip to content
This repository has been archived by the owner on Jul 16, 2023. It is now read-only.

translator comes error when doing configureAsExternal use ardent standalone #303

Open
imr092 opened this issue Jun 7, 2017 · 1 comment

Comments

@imr092
Copy link

imr092 commented Jun 7, 2017

at Ardent.php

line 17:
use Illuminate\Validation\Factory as ValidationFactory;

line 19:
use Symfony\Component\Translation\Translator;

line 512:
$translator = new Translator();

line 519:
self::$validationFactory = new ValidationFactory($translator);

the Illuminate\Validation\Factory needs a Illuminate\Contracts\Translation\Translator Object, but gives Symfony\Component\Translation\Translator

@imr092
Copy link
Author

imr092 commented Jun 7, 2017

my way:

BaseModel.php

use Illuminate\Database\Capsule\Manager as DatabaseCapsule;
use LaravelArdent\Ardent\Ardent;
use Illuminate\Events\Dispatcher;
use Illuminate\Container\Container;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Translation\FileLoader;
use Illuminate\Translation\Translator;
use Illuminate\Validation\Factory as ValidationFactory;
use Illuminate\Validation\DatabasePresenceVerifier;
use Illuminate\Hashing\BcryptHasher;

class BaseModel extends Ardent
{
    public $throwOnValidation = true;

    public static function configureAsExternal(array $connection, $lang = 'zh-CN') {
        $db = new DatabaseCapsule;
        $db->addConnection($connection);
        $db->setEventDispatcher(new Dispatcher(new Container));
        $db->setAsGlobal();
        $db->bootEloquent();

        $file = new Filesystem();
        $fileLoader = new FileLoader($file, dirname(__FILE__).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'lang'.DIRECTORY_SEPARATOR.$lang.DIRECTORY_SEPARATOR);
        $translator = new Translator($fileLoader, $lang);

        self::$external = true;
        self::$validationFactory = new ValidationFactory($translator);
        self::$validationFactory->setPresenceVerifier(new DatabasePresenceVerifier($db->getDatabaseManager()));

        self::$hasher = new BcryptHasher();
    }
}

and when start:
BaseModel::configureAsExternal($database);

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant