Last active
December 18, 2015 07:48
-
-
Save nbari/5748904 to your computer and use it in GitHub Desktop.
PPI Framework binding
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace PPI\DataSource\Connection; | |
use DALMP\dalmp; | |
use PPI\DataSource\ConnectionInferface; | |
class Dalmp implements ConnectionInferface | |
{ | |
protected $config = array(); | |
protected $conns = array(); | |
public function __construct(array $config) | |
{ | |
$this->config = $config; | |
} | |
public function getConnectionByName($name) | |
{ | |
if(!isset($this->config[$name])) { | |
throw new \Exception('No DALMP db connection found named: ' . $name); | |
} | |
if (!isset($this->conns[$name])) { | |
$this->conns[$name] = DB::connection($this->config[$name]); | |
} | |
return $this->conns[$name]; | |
} | |
public function constructDSN($config) | |
{ | |
if (!isset($config['port'])) { | |
$config['port'] = 3306; | |
} | |
if (!isset($config['hostname'])) { | |
$host = is_readable('/tmp/mysql.sock') ? 'unix_socket=\tmp\mysql.sock' : '127.0.0.1' . ':' . $config['port']; | |
} else { | |
$host = $config['hostname'] .':'. $config['port'] | |
} | |
return new DAMP(sprintf('%s://%s:%s@%s/%s', $config['charset'], $config['username'], $config['password'], $host, $config['database'])); | |
} | |
public function supports($library) | |
{ | |
return $library === 'dalmp'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment