12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- <?php
- /**
- * This entity manager configuration works with doctrine 2.1.x and 2.2.x
- * versions. Regarding AnnotationDriver setup it most probably will be changed into
- * xml. Because annotation driver fails to read other classes in same namespace
- */
- // connection args, modify at will
- $connection = array(
- 'host' => '127.0.0.1',
- 'port' => 3306,
- 'user' => 'root',
- 'password' => 'nimda',
- 'dbname' => 'test',
- 'driver' => 'pdo_mysql'
- );
- // First of all autoloading of vendors
- $vendorPath = realpath(__DIR__.'/../vendor');
- $gedmoPath = realpath(__DIR__.'/../lib');
- $doctrineClassLoaderFile = $vendorPath.'/doctrine-common/lib/Doctrine/Common/ClassLoader.php';
- if (!file_exists($doctrineClassLoaderFile)) {
- die('cannot find vendor, run: php bin/vendors.php to install doctrine');
- }
- require $doctrineClassLoaderFile;
- use Doctrine\Common\ClassLoader;
- // autoload all vendors
- $loader = new ClassLoader('Doctrine\Common', $vendorPath.'/doctrine-common/lib');
- $loader->register();
- $loader = new ClassLoader('Doctrine\DBAL', $vendorPath.'/doctrine-dbal/lib');
- $loader->register();
- $loader = new ClassLoader('Doctrine\ORM', $vendorPath.'/doctrine-orm/lib');
- $loader->register();
- // gedmo extensions
- $loader = new ClassLoader('Gedmo', $gedmoPath);
- $loader->register();
- // if you use yaml, you need a yaml parser, same as command line tool
- $loader = new ClassLoader('Symfony', $vendorPath);
- $loader->register();
- // autoloader for Entity namespace
- $loader = new ClassLoader('Entity', __DIR__.'/app');
- $loader->register();
- // Second configure ORM
- $config = new Doctrine\ORM\Configuration;
- $config->setProxyDir(sys_get_temp_dir());
- $config->setProxyNamespace('Proxy');
- $config->setAutoGenerateProxyClasses(false);
- // standard annotation reader
- $annotationReader = new Doctrine\Common\Annotations\AnnotationReader;
- // standard doctrine annotations
- Doctrine\Common\Annotations\AnnotationRegistry::registerFile(
- $vendorPath.'/doctrine-orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php'
- );
- // register annotation driver
- $driverChain = new Doctrine\ORM\Mapping\Driver\DriverChain();
- // load superclass extension metadata mapping into driver chain also registers annotation autoload
- Gedmo\DoctrineExtensions::registerAbstractMappingIntoDriverChainORM($driverChain);
- // personal annotation reader for Entity namespace
- $annotationDriver = new Doctrine\ORM\Mapping\Driver\AnnotationDriver($annotationReader, array(
- __DIR__.'/app/Entity', // example entity
- ));
- // register our Entity driver
- $driverChain->addDriver($annotationDriver, 'Entity');
- // register metadata driver
- $config->setMetadataDriverImpl($driverChain);
- // cache
- $config->setMetadataCacheImpl(new Doctrine\Common\Cache\ArrayCache);
- $config->setQueryCacheImpl(new Doctrine\Common\Cache\ArrayCache);
- $evm = new Doctrine\Common\EventManager();
- // gedmo extension listeners
- $evm->addEventSubscriber(new Gedmo\Sluggable\SluggableListener);
- $evm->addEventSubscriber(new Gedmo\Tree\TreeListener);
- $evm->addEventSubscriber(new Gedmo\Loggable\LoggableListener);
- $evm->addEventSubscriber(new Gedmo\Timestampable\TimestampableListener);
- $translatable = new Gedmo\Translatable\TranslatableListener;
- $translatable->setTranslatableLocale('en');
- $translatable->setDefaultLocale('en');
- $evm->addEventSubscriber($translatable);
- // mysql set names UTF-8
- $evm->addEventSubscriber(new Doctrine\DBAL\Event\Listeners\MysqlSessionInit());
- // create entity manager
- return Doctrine\ORM\EntityManager::create($connection, $config, $evm);
|