Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
//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' => '',
'port' => 3306
$config = Setup::createConfiguration($isDevMode);
//leitor das annotations das entidades
$driver = new AnnotationDriver(new AnnotationReader(), $paths);
//registra as annotations do Doctrine
__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);
//cria o entityManager
$entityManager = EntityManager::create($dbParams, $config);
$evm = $entityManager->getEventManager();
$entitySubscriber = new DoctrineNaPratica\Model\Subscriber\EntitySubscriber;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.