1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
<?php
require_once(RACINE.'/LibrairiePhp/doctrine-orm/Doctrine/Common/ClassLoader.php');
$classLoader = new \Doctrine\Common\ClassLoader('Doctrine', RACINE.'/LibrairiePhp/doctrine-orm/');
$classLoader->register(); // register on SPL autoload stack
use Doctrine\ORM\EntityManager,
Doctrine\ORM\Configuration;
// ...
//cette variable permet de switcher entre l'environnement de dev et de prod
$applicationMode = 'developpement';
if ($applicationMode == DOCTRINECONFIGURATION) {
$cache = new \Doctrine\Common\Cache\ArrayCache;
} else {
$cache = new \Doctrine\Common\Cache\ApcCache;
}
$config = new Configuration;
$config->setMetadataCacheImpl($cache);
$driverImpl = $config->newDefaultAnnotationDriver(RACINE.'/Model/Entities');
$config->setMetadataDriverImpl($driverImpl);
$config->setQueryCacheImpl($cache);
$config->setProxyDir(RACINE.'/Model/Proxies');
$config->setProxyNamespace('\Model\Proxies');
$config->setAutoGenerateProxyClasses(false);
/*
$config->setSQLLogger($logger);
$config->getSQLLogger();
*/
$connectionOptions = array(
'dbname' => DATABASE,
'user' => SQLUSER,
'password' => SQLUSERPWD,
'host' => SQLSERVER,
'driver' => 'pdo_mysql',
);
$em = EntityManager::create($connectionOptions, $config);
// custom datatypes (not mapped for reverse engineering)
$em->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('set', 'string');
$em->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string');
$em->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('blob', 'string');
// fetch metadata
$driver = new \Doctrine\ORM\Mapping\Driver\DatabaseDriver(
$em->getConnection()->getSchemaManager()
);
$em->getConfiguration()->setMetadataDriverImpl($driver);
$cmf = new \Doctrine\ORM\Tools\DisconnectedClassMetadataFactory($em);
$cmf->setEntityManager($em);
$metadata = $cmf->getAllMetadata();
/*
$generator = new \Doctrine\ORM\Tools\EntityGenerator();
$generator->setGenerateAnnotations(true);
$generator->setUpdateEntityIfExists(false);
$generator->setGenerateStubMethods(true);
$generator->setGenerateAnnotations(true);
$generator->generate($metadata, RACINE.'/Model/Entities');
echo 'Done';
*/
$classLoader = new \Doctrine\Common\ClassLoader('Model', RACINE.'/Model/Entities/');
$classLoader->register(); // register on SPL autoload stack*/
$users = $em->find('Utilisateurs', 1);
//$users = $em->getRepository('Utilisateurs')->findBy(array('idUtilisateurs' => 1));
print_r($users);
?> |
Partager