-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor DataSource component to be open stack based #71
Comments
General Containernamespace PPI\DataSource;
interface ConnectionContainerInferface {
public function getConnectionByName($name);
} namespace PPI\DataSource\Container;
class Laravel implements ConnectionContainerInferface {
protected $connFactory;
protected $resolver;
public function __construct(array $connections) {
$connectionFactory = new Illuminate\Database\Connectors\ConnectionFactory;
$resolver = new Illuminate\Database\ConnectionResolver();
foreach($connections as $name => $conn) {
$resolver->addConnection($name, $connectionFactory->make($conn));
}
$resolver->setDefaultConnection('default');
$this->resolver = $resolver;
$this->connFactory = $connectionFactory;
}
public function getConnectionByName($name) {
if(!$this->resolver->hasConnection($name)) {
throw new \Exception('No connection found named: ' . $name);
}
return $this->connection($name);
}
}
class DoctrineDBAL implements ConnectionContainerInferface {
public function __construct(array $connections) {}
public function getConnectionByName() {}
} Framework DataSource ConnectionManagernamespace PPI\DataSource;
class ConnectionManager {
protected $connections;
protected $libraryToConnMap;
public function __construct($connections, $libraryToConnMap) {
$this->libraryToConnMap = $libraryToConnMap;
$this->connections = $connections;
}
public function getConnection($name) {
$library = $this->connections[$name]['library'];
$connContainer = $this->libraryToConnMap[$library]->getConnectionByName($name);
return $connContainer;
}
} Framework Bootup Code$connections = include 'app/config/datasource.php';
$allConnections = $laravelConns = array();
$libraryToConnMap = array();
foreach($connections as $name => $conn) {
if($conn['library'] === 'laravel') {
$laravelConns[$name] = $conn;
}
if($conn['library'] === 'doctrinedbal') {
$doctrineDBALConns[$name] = $conn;
}
}
$libraryToConnMap['laravel'] = new \PPI\DataSource\Container\Laravel($laravelConns);
$libraryToConnMap['doctrinedbal'] = new \PPI\DataSource\Container\DoctrineDBAL($doctrineDBALConns);
$connManager = new \PPI\DataSource\ConnectionManager($connections, $libraryToConnMap); Userland Service Creation Code'sessions.storage' => function($sm) {
$connection = $sm->get('datasource')->getConnectionByName('sessions'));
return new \Application\Storage\Sessions($connection);
} Userland Storage Class Codenamespace Application\Storage;
class Sessions {
protected $connection;
public function __construct($connection) {
$this->connection = $connection;
}
public function getAllRows() {
return $this->connection->getAll();
}
} Userland Datasource Config File$conns = array();
$conns['default'] = array(
'library' => 'doctrine'
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'database',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
);
$conns['sessions'] = array(
'library' => 'laravel'
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'sessions',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
); |
This has now been completed by commit #ed0f85a5e8c3356d29c6623831a04e5f0174fbc1 |
Re-Opening this until Documentation has been completed. |
ghost
assigned dragoonis
Jun 30, 2013
Waiting for @dragoonis to provide documentation. Moved milestone from 2.1.0 to 2.1.1. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
by open stack I mean not closely tied to doctrine\dbal by default, but have a
ConnectionManager
for dbal or whatever components we have setup.I want DataSource to be glue between the app's
app/config/datasource.php
config file and the chosen library.So for dbal we need a handler to give you a 'connection' setup per key
For laravel's db layer there's a conection manager too which i have a gist for.
It should be a clean component with some a ConnectionManagerInterface which each library will be setup with
The text was updated successfully, but these errors were encountered: