/** * Setup Eloquent ORM Service Provider * * @param Application $app * @source https://github.com/illuminate/database */ public function register(Application $app) { $this->eloquent = new EloquentCapsule(); $config = Database::getDatabaseConfiguration(); /** | We will loop over all connections | and set connection */ foreach ($config as $key => $c) { $this->setConnection($c); } $this->eloquent->setEventDispatcher(new Dispatcher(new Container())); // Make this Capsule instance available globally via static methods... (optional) $this->eloquent->setAsGlobal(); // Setup the Eloquent ORM... (optional; unless you've used setEventDispatcher()) $this->eloquent->bootEloquent(); }
/** * @param $connKey * * @return mixed */ public function getConnection($connKey) { if (isset(self::$connectionObject[$connKey]) && self::$connectionObject[$connKey] instanceof PDO) { return self::$connectionObject[$connKey]; } $config = []; $config = Configure::getDatabaseConfiguration(); foreach ($config as $key => $value) { if (trim($value['database']) == trim($connKey)) { return self::$connectionObject[$connKey] = $this->setConnection($value); } } }