Skip to content

Commit 20a5d3f

Browse files
committedFeb 28, 2015
Initial commit
0 parents  commit 20a5d3f

File tree

5 files changed

+99
-0
lines changed

5 files changed

+99
-0
lines changed
 

‎.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.buildpath
2+
.project
3+
.settings
4+
composer.phar
5+
composer.lock
6+
vendor

‎README.md

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Doctrine DBAL service provider
2+
3+
A silex provider for Doctine DBAL using puzzle/configuration (https://github.com/Niktux/puzzle-configuration)
4+
5+
## Installation
6+
7+
```
8+
{
9+
"require": {
10+
"silex-spear/dbal-provider": "~1.0"
11+
}
12+
}
13+
```
14+
15+
or
16+
17+
```bash
18+
composer require silex-spear/dbal-provider
19+
```
20+
21+
#### What is the `config/db.yml-dist.example` file ?
22+
23+
It's a configuration example file for the configuration file hydrator karma (https://github.com/Niktux/karma)

‎composer.json

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "silex-spear/dbal-provider",
3+
"description": "A Silex provider for Doctrine DBAL",
4+
"type": "library",
5+
"authors": [{
6+
"name": "Claude LE BRIS",
7+
"email": "claude.lebris@gmail.com"
8+
}],
9+
"license": [
10+
"MIT"
11+
],
12+
"require": {
13+
"php": ">=5.4",
14+
"silex/silex": "~1.2",
15+
"doctrine/dbal": "~2.2",
16+
"puzzle/configuration": "~1.7"
17+
},
18+
"autoload": {
19+
"psr-4": {
20+
"Spear\\Silex\\Provider\\": "src/"
21+
}
22+
}
23+
}

‎config/db.yml-dist.example

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
database: <%db.name%>
2+
host: <%db.host%>
3+
user: <%db.user%>
4+
password: <%db.password%>
5+
port: <%db.port%>
6+
charset: <%db.charset%>

‎src/DBAL.php

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace Spear\Silex\Provider;
4+
5+
use Silex\ServiceProviderInterface;
6+
use Puzzle\Configuration;
7+
use Silex\Application;
8+
use Silex\Provider\DoctrineServiceProvider;
9+
10+
class DBAL implements ServiceProviderInterface
11+
{
12+
public function register(Application $app)
13+
{
14+
$this->validatePuzzleConfiguration($app);
15+
16+
$app->register(new DoctrineServiceProvider(), array(
17+
'db.options' => array(
18+
'driver' => 'pdo_mysql',
19+
'dbname' => $app['configuration']->readRequired('db/database'),
20+
'host' => $app['configuration']->readRequired('db/host'),
21+
'user' => $app['configuration']->readRequired('db/user'),
22+
'password' => $app['configuration']->readRequired('db/password'),
23+
'port' => $app['configuration']->read('db/port', 3306),
24+
'charset' => $app['configuration']->read('db/charset', 'utf8'),
25+
)
26+
));
27+
}
28+
29+
public function boot(Application $app)
30+
{
31+
;
32+
}
33+
34+
private function validatePuzzleConfiguration(Application $app)
35+
{
36+
if(! isset($app['configuration']) || ! $app['configuration'] instanceof Configuration)
37+
{
38+
throw new \LogicException('AsseticProvider requires an instance of puzzle/configuration for the key configuration to be defined.');
39+
}
40+
}
41+
}

0 commit comments

Comments
 (0)
Please sign in to comment.