31 lines
772 B
PHP
31 lines
772 B
PHP
<?php
|
|
namespace ProVM\Common\Service;
|
|
|
|
use \ORM;
|
|
use \Model;
|
|
use ProVM\Common\Service\Database\MySQL;
|
|
|
|
class Database {
|
|
protected $settings;
|
|
public function __construct($settings) {
|
|
$this->settings = $settings;
|
|
}
|
|
public function load() {
|
|
foreach ($this->settings->dbs as $name => $data) {
|
|
switch (strtolower($data->engine)) {
|
|
case 'mysql':
|
|
$obj = new MySQL($data);
|
|
break;
|
|
}
|
|
ORM::configure($obj->dsn(), null, $name);
|
|
if ($obj->hasUser()) {
|
|
ORM::configure('username', $data->user->name, $name);
|
|
ORM::configure('password', $data->user->password, $name);
|
|
}
|
|
}
|
|
if (isset($this->settings->short_names)) {
|
|
Model::$short_table_names = $this->settings->short_names;
|
|
}
|
|
}
|
|
}
|