private function connect() { $configs = container()->getConfig()->getDb(); $config = isAke($configs, $this->entity); if (empty($config)) { throw new Exception("Database configuration does not exist."); } $username = $config->getUsername(); if (empty($username)) { throw new Exception("Username is mandatory to connect database."); } $adapter = $config->getAdapter(); $password = $config->getPassword(); $dbName = $config->getDatabase(); $host = $config->getHost(); $dsn = $config->getDsn(); if (empty($dsn)) { $dsn = "{$adapter}:dbname={$dbName};host={$host}"; } else { $adapter = 'mysql'; } $connexions = Utils::get('SQLConnexions'); if (null === $connexions) { $connexions = array(); } $keyConnexion = sha1(serialize(array($dsn, $username, $password))); if (Arrays::exists($keyConnexion, $connexions)) { $db = $connexions[$keyConnexion]; } else { switch ($adapter) { case 'mysql': $db = Utils::newInstance('\\PDO', array($dsn, $username, $password)); break; } $connexions[$keyConnexion] = $db; Utils::set('SQLConnexions', $connexions); } return $db; }
function addEav($entity, array $attributes) { $eav = Utils::newInstance('Memory', array('Thin', 'EAV')); $eav = $eav->setEntity($entity); foreach ($attributes as $key => $value) { $setter = setter($key); $eav = $eav->{$setter}($value); } return $eav->save(); }