Created
May 10, 2015 23:44
-
-
Save eminetto/e66bd041328eadd87db5 to your computer and use it in GitHub Desktop.
bootstrap.php
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 | |
//AutoLoader do Composer | |
$loader = require __DIR__.'/vendor/autoload.php'; | |
//vamos adicionar nossas classes ao AutoLoader | |
$loader->add('DoctrineNaPratica', __DIR__.'/src'); | |
use Doctrine\ORM\Tools\Setup; | |
use Doctrine\ORM\EntityManager; | |
use Doctrine\ORM\Mapping\Driver\AnnotationDriver; | |
use Doctrine\Common\Annotations\AnnotationReader; | |
use Doctrine\Common\Annotations\AnnotationRegistry; | |
//se for falso usa o APC como cache, se for true usa cache em arrays | |
$isDevMode = true; | |
//caminho das entidades | |
$paths = array(__DIR__ . '/src/DoctrineNaPratica/Model'); | |
// configurações do banco de dados | |
$dbParams = array( | |
'driver' => 'pdo_mysql', | |
'user' => 'dnp', | |
'password' => 'dnp', | |
'dbname' => 'dnp', | |
'host' => '127.0.0.1', | |
'port' => 3306 | |
); | |
$config = Setup::createConfiguration($isDevMode); | |
//leitor das annotations das entidades | |
$driver = new AnnotationDriver(new AnnotationReader(), $paths); | |
$config->setMetadataDriverImpl($driver); | |
//registra as annotations do Doctrine | |
AnnotationRegistry::registerFile( | |
__DIR__ . '/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php' | |
); | |
// Enable second-level-cache | |
$cache = new \Doctrine\Common\Cache\ApcCache; | |
$cacheRegionConfiguration = new \Doctrine\ORM\Cache\RegionsConfiguration(); | |
$factory = new \Doctrine\ORM\Cache\DefaultCacheFactory($cacheRegionConfiguration, $cache); | |
$config->setSecondLevelCacheEnabled(); | |
$config->getSecondLevelCacheConfiguration()->setCacheFactory($factory); | |
//cria o entityManager | |
$entityManager = EntityManager::create($dbParams, $config); | |
//subscriber | |
$evm = $entityManager->getEventManager(); | |
$entitySubscriber = new DoctrineNaPratica\Model\Subscriber\EntitySubscriber; | |
$evm->addEventSubscriber($entitySubscriber); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment