Created
February 19, 2016 19:13
-
-
Save fabriziomachado/5050d89257d95eda1a3d to your computer and use it in GitHub Desktop.
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 | |
require 'vendor\autoload.php'; | |
require __DIR__ . '/bootstrap/app.php'; | |
$provider = new App\Providers\DoctrineServiceProvider($app); | |
$entityManager = $provider->getEntityManager(); | |
return \Doctrine\ORM\Tools\Console\ConsoleRunner::createHelperSet($entityManager); |
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 DoctrineServiceProvider extends ServiceProvider | |
{ | |
/** | |
* @var EntityManager | |
*/ | |
private $entityManager; | |
public function getEntityManager() | |
{ | |
// Caminho para a pasta de models/entities, está pasta não existe na instalação do Laravel e pode ser criada em "app/Http/Entities" | |
$path = array(__DIR__."/../Entities"); | |
// Verifica se a aplicação está com debug | |
$debug = isset($_ENV['APP_DEBUG']) ? $_ENV['APP_DEBUG'] : true; | |
// Array com as configurações de banco de dados | |
$database_array = require __DIR__ . '/../../config/database.php'; | |
// Array com a configuração de conexão com o banco de dados | |
$database_connection = $database_array['connections'][$database_array['default']]; | |
// Método do Doctrine usado para configurar | |
$config = Setup::createAnnotationMetadataConfiguration($path, $debug); | |
// Retorna uma instância do EntityManager | |
return EntityManager::create($database_connection, $config); | |
} | |
/** | |
* Bootstrap the application services. | |
* | |
* @return void | |
*/ | |
public function boot() | |
{ | |
$this->entityManager = self::getEntityManager(); | |
} | |
/** | |
* Register the application services. | |
* | |
* @return void | |
*/ | |
public function register() | |
{ | |
$this->app->singleton('Doctrine\ORM\EntityManagerInterface', function($app){ | |
return $this->entityManager; | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment