Created
August 15, 2016 16:37
-
-
Save mcfdn/f547c93e6a83e5392e4916d930656023 to your computer and use it in GitHub Desktop.
Doctrine EntityManager Service Provider for Laravel 5.2
This file contains hidden or 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 App\Providers; | |
use Illuminate\Support\ServiceProvider; | |
use Doctrine\ORM\Tools\Setup; | |
use Doctrine\ORM\EntityManager; | |
class EntityManagerServiceProvider extends ServiceProvider | |
{ | |
/** | |
* Bootstrap any application services. | |
* | |
* @return void | |
*/ | |
public function boot() | |
{ | |
// | |
} | |
/** | |
* Register any application services. | |
* | |
* @return void | |
*/ | |
public function register() | |
{ | |
$this->app->singleton('Doctrine\ORM\EntityManager', function ($app) { | |
$paths = [app_path('models')]; | |
$isDevMode = config('app.debug'); | |
// the connection configuration | |
$dbParams = config('database.doctrine'); | |
$config = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode); | |
return EntityManager::create($dbParams, $config); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment