예제 #1
0
파일: bootstrap.php 프로젝트: V3N0m21/Uppu4
function createDoctrineConfig($cache, $cachedAnnotationReader)
{
    AnnotationRegistry::registerFile(dirname(__DIR__) . "/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php");
    //$cache = new Doctrine\Common\Cache\ArrayCache;
    //    if (extension_loaded('apc')) {
    //        $cache = new \Doctrine\Common\Cache\ApcCache();
    //    } else {
    //        $cache = new \Doctrine\Common\Cache\PhpFileCache();
    //    }
    $isDevMode = true;
    //    $annotationReader = new AnnotationReader;
    //    $cachedAnnotationReader = new Doctrine\Common\Annotations\CachedReader(
    //        $annotationReader, // use reader
    //        $cache // and a cache driver
    //    );
    $annotationDriver = new Doctrine\ORM\Mapping\Driver\AnnotationDriver($cachedAnnotationReader, array(__DIR__ . '/Resource'));
    $driverChain = new Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain();
    Gedmo\DoctrineExtensions::registerAbstractMappingIntoDriverChainORM($driverChain, $cachedAnnotationReader);
    $driverChain->addDriver($annotationDriver, 'Uppu4\\Entity');
    $config = Setup::createAnnotationMetadataConfiguration(array(__DIR__ . "/Resource"), $isDevMode);
    //!!!!!!
    $config = new Doctrine\ORM\Configuration();
    $config->setProxyDir(sys_get_temp_dir());
    $config->setProxyNamespace('Proxy');
    $config->setAutoGenerateProxyClasses(true);
    // this can be based on production config.
    // register metadata driver
    $config->setMetadataDriverImpl($driverChain);
    // use our already initialized cache driver
    $config->setMetadataCacheImpl($cache);
    $config->setQueryCacheImpl($cache);
    $deleted = $cache->deleteAll();
    return $config;
}
예제 #2
0
 public function __construct()
 {
     // load database configuration from CodeIgniter
     require APPPATH . 'config/database.php';
     //A Doctrine Autoloader is needed to load the models
     // first argument of classloader is namespace and second argument is path
     // setup models/entity namespace
     $entityLoader = new ClassLoader('models', APPPATH);
     $entityLoader->register();
     foreach (glob(APPPATH . 'modules/*', GLOB_ONLYDIR) as $m) {
         $module = str_replace(APPPATH . 'modules/', '', $m);
         $entityLoader = new ClassLoader($module, APPPATH . 'modules');
         $entityLoader->register();
     }
     //Register proxies namespace
     $proxyLoader = new ClassLoader('Proxies', APPPATH . 'Proxies');
     $proxyLoader->register();
     // Set up caches
     $config = new Configuration();
     $cache = new ArrayCache();
     $config->setMetadataCacheImpl($cache);
     $driverImpl = $config->newDefaultAnnotationDriver(array(APPPATH . 'models'));
     $config->setMetadataDriverImpl($driverImpl);
     $config->setQueryCacheImpl($cache);
     // Set up entity
     $reader = new AnnotationReader($cache);
     $models = array(APPPATH . 'models');
     foreach (glob(APPPATH . 'modules/*/models', GLOB_ONLYDIR) as $m) {
         array_push($models, $m);
     }
     $driver = new AnnotationDriver($reader, $models);
     $config->setMetadataDriverImpl($driver);
     // Setup Gedmo
     $cachedAnnotationReader = new Doctrine\Common\Annotations\CachedReader($reader, $cache);
     // create a driver chain for metadata reading
     $driverChain = new Doctrine\ORM\Mapping\Driver\DriverChain();
     // load superclass metadata mapping only, into driver chain
     // also registers Gedmo annotations.NOTE: you can personalize it
     Gedmo\DoctrineExtensions::registerAbstractMappingIntoDriverChainORM($driverChain, $cachedAnnotationReader);
     $event = new EventManager();
     $timestampableListener = new TimestampableListener();
     $timestampableListener->setAnnotationReader($cachedAnnotationReader);
     $event->addEventSubscriber($timestampableListener);
     $slugListener = new SluggableListener();
     $slugListener->setAnnotationReader($cachedAnnotationReader);
     $event->addEventSubscriber($slugListener);
     // Proxy configuration
     $config->setProxyDir(APPPATH . '/proxies');
     $config->setProxyNamespace('Proxies');
     // Set up logger
     // $logger = new EchoSQLLogger;
     // $config->setSQLLogger($logger);
     $config->setAutoGenerateProxyClasses(TRUE);
     // Database connection information
     $connectionOptions = array('driver' => 'pdo_mysql', 'user' => $db['default']['username'], 'password' => $db['default']['password'], 'host' => $db['default']['hostname'], 'dbname' => $db['default']['database']);
     // Create EntityManager
     $this->em = EntityManager::create($connectionOptions, $config, $event);
 }
예제 #3
0
$loader->add('Gedmo', __DIR__ . '/../lib');
// autoloader for Entity namespace
$loader->add('Entity', __DIR__ . '/app');
// ensure standard doctrine annotations are registered
Doctrine\Common\Annotations\AnnotationRegistry::registerFile(__DIR__ . '/../vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php');
// Second configure ORM
// globally used cache driver, in production use APC or memcached
$cache = new Doctrine\Common\Cache\ArrayCache();
// standard annotation reader
$annotationReader = new Doctrine\Common\Annotations\AnnotationReader();
$cachedAnnotationReader = new Doctrine\Common\Annotations\CachedReader($annotationReader, $cache);
// create a driver chain for metadata reading
$driverChain = new Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain();
// load superclass metadata mapping only, into driver chain
// also registers Gedmo annotations.NOTE: you can personalize it
Gedmo\DoctrineExtensions::registerAbstractMappingIntoDriverChainORM($driverChain, $cachedAnnotationReader);
// now we want to register our application entities,
// for that we need another metadata driver used for Entity namespace
$annotationDriver = new Doctrine\ORM\Mapping\Driver\AnnotationDriver($cachedAnnotationReader, array(__DIR__ . '/app/Entity'));
// NOTE: driver for application Entity can be different, Yaml, Xml or whatever
// register annotation driver for our application Entity fully qualified namespace
$driverChain->addDriver($annotationDriver, 'Entity');
// general ORM configuration
$config = new Doctrine\ORM\Configuration();
$config->setProxyDir(sys_get_temp_dir());
$config->setProxyNamespace('Proxy');
$config->setAutoGenerateProxyClasses(false);
// this can be based on production config.
// register metadata driver
$config->setMetadataDriverImpl($driverChain);
// use our allready initialized cache driver
예제 #4
0
 * This is bootstrap for phpUnit unit tests,
 * use README.md for more details
 *
 * @author Gediminas Morkevicius <*****@*****.**>
 * @package Gedmo.Tests
 * @link http://www.gediminasm.org
 * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
 */
if (!class_exists('PHPUnit_Framework_TestCase') || version_compare(PHPUnit_Runner_Version::id(), '3.5') < 0) {
    die('PHPUnit framework is required, at least 3.5 version');
}
if (!class_exists('PHPUnit_Framework_MockObject_MockBuilder')) {
    die('PHPUnit MockObject plugin is required, at least 1.0.8 version');
}
define('TESTS_PATH', __DIR__);
define('TESTS_TEMP_DIR', __DIR__ . '/temp');
define('VENDOR_PATH', realpath(__DIR__ . '/../vendor'));
$classLoaderFile = VENDOR_PATH . '/Symfony/Component/ClassLoader/UniversalClassLoader.php';
if (!file_exists($classLoaderFile)) {
    die('cannot find vendor, run: php bin/vendors.php');
}
require_once $classLoaderFile;
$loader = new Symfony\Component\ClassLoader\UniversalClassLoader();
$loader->registerNamespaces(array('Symfony' => VENDOR_PATH, 'Doctrine\\MongoDB' => VENDOR_PATH . '/doctrine-mongodb/lib', 'Doctrine\\ODM\\MongoDB' => VENDOR_PATH . '/doctrine-mongodb-odm/lib', 'Doctrine\\Common' => VENDOR_PATH . '/doctrine-common/lib', 'Doctrine\\DBAL' => VENDOR_PATH . '/doctrine-dbal/lib', 'Doctrine\\ORM' => VENDOR_PATH . '/doctrine-orm/lib', 'Gedmo\\Mapping\\Mock' => __DIR__, 'Gedmo' => __DIR__ . '/../lib', 'Tool' => __DIR__ . '/Gedmo', 'Translator\\Fixture' => __DIR__ . '/Gedmo', 'Translatable\\Fixture' => __DIR__ . '/Gedmo', 'Timestampable\\Fixture' => __DIR__ . '/Gedmo', 'Tree\\Fixture' => __DIR__ . '/Gedmo', 'Sluggable\\Fixture' => __DIR__ . '/Gedmo', 'Sortable\\Fixture' => __DIR__ . '/Gedmo', 'Mapping\\Fixture' => __DIR__ . '/Gedmo', 'Loggable\\Fixture' => __DIR__ . '/Gedmo', 'SoftDeleteable\\Fixture' => __DIR__ . '/Gedmo', 'Uploadable\\Fixture' => __DIR__ . '/Gedmo', 'Wrapper\\Fixture' => __DIR__ . '/Gedmo', 'Gedmo\\Uploadable\\Stub' => __DIR__));
$loader->register();
Doctrine\Common\Annotations\AnnotationRegistry::registerFile(VENDOR_PATH . '/doctrine-orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php');
Doctrine\Common\Annotations\AnnotationRegistry::registerFile(VENDOR_PATH . '/doctrine-mongodb-odm/lib/Doctrine/ODM/MongoDB/Mapping/Annotations/DoctrineAnnotations.php');
Gedmo\DoctrineExtensions::registerAnnotations();
$reader = new \Doctrine\Common\Annotations\AnnotationReader();
$reader = new \Doctrine\Common\Annotations\CachedReader($reader, new \Doctrine\Common\Cache\ArrayCache());
$_ENV['annotation_reader'] = $reader;