Last active
December 21, 2015 17:43
-
-
Save dadamssg/901696cd79474fa7afa4 to your computer and use it in GitHub Desktop.
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 | |
use Doctrine\ORM\EntityManager; | |
use Doctrine\ORM\Mapping\Driver\SimplifiedYamlDriver; | |
use Doctrine\ORM\Tools\Setup; | |
use Silex\Application; | |
use Silex\ServiceProviderInterface; | |
class DoctrineServiceProvider implements ServiceProviderInterface | |
{ | |
public function register(Application $app) | |
{ | |
$app['doctrine'] = $app->share(function () use ($app) { | |
$params = [ | |
'driver' => $_ENV['DATABASE_DRIVER'], | |
'host' => $_ENV['DATABASE_HOST'], | |
'dbname' => $_ENV['DATABASE_NAME'], | |
'user' => $_ENV['DATABASE_USER'], | |
'password' => $_ENV['DATABASE_PASSWORD'] | |
]; | |
$config = Setup::createConfiguration(isset($_ENV['APP_DEBUG'])); | |
$namespaces = [ | |
__DIR__ . "/../../config/doctrine" => 'Acme\Project' | |
]; | |
$driver = new SimplifiedYamlDriver($namespaces); | |
$config->setMetadataDriverImpl($driver); | |
return EntityManager::create($params, $config); | |
}); | |
$app['db'] = $app->share(function () use ($app) { | |
return $app['doctrine']->getConnection(); | |
}); | |
$app['user.repository'] = $app->share(function () use ($app) { | |
return $app['doctrine']->getRepository(User::class); | |
}); | |
} | |
public function boot(Application $app) | |
{ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment