本文整理汇总了PHP中Doctrine\ORM\Configuration::newDefaultAnnotationDriver方法的典型用法代码示例。如果您正苦于以下问题:PHP Configuration::newDefaultAnnotationDriver方法的具体用法?PHP Configuration::newDefaultAnnotationDriver怎么用?PHP Configuration::newDefaultAnnotationDriver使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\Configuration
的用法示例。
在下文中一共展示了Configuration::newDefaultAnnotationDriver方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: obterConfiguracao
private function obterConfiguracao($dados)
{
$this->config = new Configuration();
// Definição do driver de mapeamento
$metadata_driver = "Doctrine\\ORM\\Mapping\\Driver\\{$dados['metadata_driver']}";
if ($dados['metadata_driver'] == "AnnotationDriver") {
$driver = $this->config->newDefaultAnnotationDriver(array(MODELO), true);
} else {
$driver = new $metadata_driver(CONFIG . DS . 'orm');
}
if (!empty($dados['map_paths'])) {
$driver->addPaths(preg_split('/, ?/', $dados['map_paths']));
}
$this->config->setMetadataDriverImpl($driver);
// Configurações de proxies
$this->config->setProxyDir(RAIZ . DS . $dados['proxy_dir']);
$this->config->setProxyNamespace($dados['proxy_namespace']);
$this->config->setAutoGenerateProxyClasses($dados['auto_proxies']);
// Definição da estratégia de caches de consultas e metadados
$metadata_cache = "Doctrine\\Common\\Cache\\{$dados['metadata_cache']}";
$query_cache = "Doctrine\\Common\\Cache\\{$dados['query_cache']}";
$result_cache = "Doctrine\\Common\\Cache\\{$dados['query_cache']}";
$this->config->setMetadataCacheImpl(new $metadata_cache());
$this->config->setQueryCacheImpl(new $query_cache());
$this->config->setResultCacheImpl(new $result_cache());
// Ferramenta de log de consultas
if (!empty($dados['sql_logger'])) {
$sql_logger = "Doctrine\\DBAL\\Logging\\{$dados['sql_logger']}";
$logger = new $sql_logger();
$this->config->setSQLLogger($logger);
}
}
示例2: setUp
public function setUp()
{
$this->configuration = new Configuration();
$this->configuration->setMetadataCacheImpl(new ArrayCache());
$this->configuration->setQueryCacheImpl(new ArrayCache());
$this->configuration->setProxyDir(__DIR__ . '/Proxies');
$this->configuration->setProxyNamespace('DoctrineExtensions\\Tests\\Proxies');
$this->configuration->setAutoGenerateProxyClasses(true);
$this->configuration->setMetadataDriverImpl($this->configuration->newDefaultAnnotationDriver(__DIR__ . '/../Entities'));
$this->entityManager = EntityManager::create(array('driver' => 'pdo_sqlite', 'memory' => true), $this->configuration);
}
示例3: register
/**
* {@inheritdoc}
*/
public function register(Container $app)
{
// @todo crear DoctrineOrmManagerRegistryProvider
// o poner en boot estos servicios
$app->extend('form.extensions', function ($extensions, $app) {
$extensions[] = new DoctrineOrmExtension($app['doctrine']);
return $extensions;
});
$app['doctrine.orm.validator.unique_validator'] = function ($app) {
return new UniqueEntityValidator($app['doctrine']);
};
if (!isset($app['validator.validator_service_ids'])) {
$app['validator.validator_service_ids'] = [];
}
$app['validator.validator_service_ids'] = array_merge($app['validator.validator_service_ids'], ['doctrine.orm.validator.unique' => 'doctrine.orm.validator.unique_validator']);
$app->extend('validator.object_initializers', function (array $objectInitializers, $app) {
$objectInitializers[] = new DoctrineInitializer($app['doctrine']);
return $objectInitializers;
});
$app['doctrine'] = function ($app) {
return new ManagerRegistry($app);
};
$app['orm.em'] = function ($app) {
$em = EntityManager::create($app['db'], $app['orm.config'], $app['db.event_manager']);
return $em;
};
// Entity manager alias
$app['em'] = function ($app) {
return $app['orm.em'];
};
$app['orm.config'] = function ($app) {
$config = new Configuration();
// @todo path!
$config->setProxyDir(sprintf('%s/../../../../../../var/cache/doctrine/proxies', __DIR__));
$config->setProxyNamespace('DoctrineProxies');
$config->setAutoGenerateProxyClasses($app['debug']);
// The strongly recommended FALSE in production
$chain = new MappingDriverChain();
// Pulsar
$path = realpath(sprintf('%s/../Entity', __DIR__));
$driver = $config->newDefaultAnnotationDriver((array) $path, false);
$chain->addDriver($driver, 'Pulsar\\Entity');
// App
$path = realpath(sprintf('%s/../../../../../../src/App', __DIR__));
$driver = $config->newDefaultAnnotationDriver((array) $path, false);
$chain->addDriver($driver, 'App\\Entity');
$config->setMetadataCacheImpl($app['orm.cache']);
$config->setMetadataDriverImpl($chain);
return $config;
};
$app['orm.cache'] = function () {
return new ArrayCache();
};
}
示例4: testNewDefaultAnnotationDriver
public function testNewDefaultAnnotationDriver()
{
$paths = array(__DIR__);
$reflectionClass = new ReflectionClass(__NAMESPACE__ . '\\ConfigurationTestAnnotationReaderChecker');
$annotationDriver = $this->configuration->newDefaultAnnotationDriver($paths, false);
$reader = $annotationDriver->getReader();
$annotation = $reader->getMethodAnnotation($reflectionClass->getMethod('namespacedAnnotationMethod'), 'Doctrine\\ORM\\Mapping\\PrePersist');
$this->assertInstanceOf('Doctrine\\ORM\\Mapping\\PrePersist', $annotation);
$annotationDriver = $this->configuration->newDefaultAnnotationDriver($paths);
$reader = $annotationDriver->getReader();
$annotation = $reader->getMethodAnnotation($reflectionClass->getMethod('simpleAnnotationMethod'), 'Doctrine\\ORM\\Mapping\\PrePersist');
$this->assertInstanceOf('Doctrine\\ORM\\Mapping\\PrePersist', $annotation);
}
示例5: _initDoctrine
protected function _initDoctrine()
{
$config = new Configuration();
switch (APPLICATION_ENV) {
case 'production':
case 'staging':
$cache = new \Doctrine\Common\Cache\ApcCache();
break;
// Both development and test environments will use array cache.
// Both development and test environments will use array cache.
default:
$cache = new \Doctrine\Common\Cache\ArrayCache();
break;
}
$config->setMetadataCacheImpl($cache);
$driverImpl = $config->newDefaultAnnotationDriver(APPLICATION_PATH . '/models');
$config->setMetadataDriverImpl($driverImpl);
$config->setQueryCacheImpl($cache);
$config->setProxyDir(APPLICATION_PATH . '/proxies');
$config->setProxyNamespace('D2Test\\Proxies');
$options = $this->getOption('doctrine');
$config->setAutoGenerateProxyClasses($options['auto_generate_proxy_class']);
$em = EntityManager::create($options['db'], $config);
Zend_Registry::set('EntityManager', $em);
return $em;
}
示例6: __construct
public function __construct()
{
// load database configuration from CodeIgniter
require_once APPPATH . 'config/database.php';
// Set up class loading. You could use different autoloaders, provided by your favorite framework,
// if you want to.
//require_once APPPATH.'libraries/Doctrine/Common/ClassLoader.php';
// We use the Composer Autoloader instead - just set
// $config['composer_autoload'] = TRUE; in application/config/config.php
//require_once APPPATH.'vendor/autoload.php';
//A Doctrine Autoloader is needed to load the models
$entitiesClassLoader = new ClassLoader('Entities', APPPATH . "models");
$entitiesClassLoader->register();
// Set up caches
$config = new Configuration();
$cache = new ArrayCache();
$config->setMetadataCacheImpl($cache);
$driverImpl = $config->newDefaultAnnotationDriver(array(APPPATH . 'models/Entities'));
$config->setMetadataDriverImpl($driverImpl);
$config->setQueryCacheImpl($cache);
$config->setQueryCacheImpl($cache);
// Proxy configuration
$config->setProxyDir(APPPATH . '/models/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' => 'dev_pila', 'password' => 'damienludothomas', 'host' => 'localhost', 'dbname' => 'tradr');
// Create EntityManager
$this->em = EntityManager::create($connectionOptions, $config);
}
示例7: getEntityManager
/**
* @return EntityManager
*/
protected function getEntityManager()
{
if (null !== $this->em) {
return $this->em;
}
$config = new Configuration();
$config->setMetadataCacheImpl(new ArrayCache());
$config->setQueryCacheImpl(new ArrayCache());
$config->setProxyDir(__DIR__ . '/Proxies');
$config->setAutoGenerateProxyClasses(ProxyFactory::AUTOGENERATE_EVAL);
$config->setProxyNamespace('SimpleThings\\EntityAudit\\Tests\\Proxies');
$config->setMetadataDriverImpl($config->newDefaultAnnotationDriver(array(realpath(__DIR__ . '/Fixtures/Core'), realpath(__DIR__ . '/Fixtures/Issue'), realpath(__DIR__ . '/Fixtures/Relation')), false));
Gedmo\DoctrineExtensions::registerAnnotations();
$connection = $this->_getConnection();
// get rid of more global state
$evm = $connection->getEventManager();
foreach ($evm->getListeners() as $event => $listeners) {
foreach ($listeners as $listener) {
$evm->removeEventListener(array($event), $listener);
}
}
$this->em = EntityManager::create($connection, $config);
if (isset($this->customTypes) and is_array($this->customTypes)) {
foreach ($this->customTypes as $customTypeName => $customTypeClass) {
if (!Type::hasType($customTypeName)) {
Type::addType($customTypeName, $customTypeClass);
}
$this->em->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('db_' . $customTypeName, $customTypeName);
}
}
return $this->em;
}
示例8: init
public function init()
{
$dbParams = ['driver' => $this->driver, 'host' => $this->host, 'user' => $this->user, 'password' => $this->password, 'dbname' => $this->dbname, 'charset' => 'utf8mb4'];
$this->pathProxy = $this->path . DIRECTORY_SEPARATOR . 'proxy';
if (!is_dir($this->pathCache)) {
File::createDirectory($this->pathCache);
}
if (!is_dir($this->pathProxy)) {
File::createDirectory($this->pathProxy);
}
$config = new Configuration();
$cache = new \Doctrine\Common\Cache\FilesystemCache($this->pathCache);
$config->setMetadataCacheImpl($cache);
$config->setQueryCacheImpl($cache);
$driverImpl = $config->newDefaultAnnotationDriver($this->path);
$config->setMetadataDriverImpl($driverImpl);
$config->setProxyDir($this->pathProxy);
$config->setProxyNamespace('app\\tables\\proxy');
if ($this->applicationMode == "development") {
$config->setAutoGenerateProxyClasses(true);
} else {
$config->setAutoGenerateProxyClasses(false);
}
$this->doctrine = EntityManager::create($dbParams, $config);
}
示例9: loadDependencyDefaults
public function loadDependencyDefaults(ContainerInterface $container)
{
// logger
$container['logger'] = function (ContainerInterface $c) {
$settings = $c->get('settings')['logger'];
$debug = array_key_exists('debug', $settings) && $settings['debug'];
$logger = new Logger($settings['name']);
$logger->pushProcessor(new UidProcessor());
$logger->pushHandler(new StreamHandler($settings['path'], $debug ? Logger::DEBUG : Logger::ERROR));
return $logger;
};
// entity manager
$container['entityManager'] = function (ContainerInterface $c) {
$settings = $c->get('settings')['database'];
$config = new Configuration();
$config->setMetadataCacheImpl(new ArrayCache());
$driverImpl = $config->newDefaultAnnotationDriver(array(__DIR__ . '/Entity'));
$config->setMetadataDriverImpl($driverImpl);
$config->setProxyDir(__DIR__ . '/Entity/Proxy');
$config->setProxyNamespace('Proxy');
return EntityManager::create($settings, $config);
};
$container['foundHandler'] = function () {
return new RequestResponseArgs();
};
$container['dataFormatter'] = function () {
return new ResponseDataFormatter();
};
return $container;
}
示例10: initDoctrine
function initDoctrine()
{
require_once __DIR__ . '/../lib/vendor/doctrine-common/lib/Doctrine/Common/ClassLoader.php';
// Set up class loading. You could use different autoloaders, provided by your favorite framework,
// if you want to.
$classLoader = new ClassLoader('Doctrine\\ORM', realpath(__DIR__ . '/../lib'));
$classLoader->register();
$classLoader = new ClassLoader('Doctrine\\DBAL', realpath(__DIR__ . '/../lib/vendor/doctrine-dbal/lib'));
$classLoader->register();
$classLoader = new ClassLoader('Doctrine\\Common', realpath(__DIR__ . '/../lib/vendor/doctrine-common/lib'));
$classLoader->register();
$classLoader = new ClassLoader('Symfony', realpath(__DIR__ . '/../lib/vendor'));
$classLoader->register();
$classLoader = new ClassLoader('Entities', __DIR__);
$classLoader->register();
$classLoader = new ClassLoader('Proxies', __DIR__);
$classLoader->register();
// Set up caches
$config = new Configuration();
$cache = new ApcCache();
$config->setMetadataCacheImpl($cache);
$driverImpl = $config->newDefaultAnnotationDriver(array(__DIR__ . "/Entities"));
$config->setMetadataDriverImpl($driverImpl);
$config->setQueryCacheImpl($cache);
// Proxy configuration
$config->setProxyDir(__DIR__ . '/Proxies');
$config->setProxyNamespace('Proxies');
$config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache());
// Database connection information
$connectionOptions = array('driver' => 'pdo_sqlite', 'path' => __DIR__ . '/database.sqlite');
// Create EntityManager
$em = EntityManager::create($connectionOptions, $config);
return $em;
}
示例11: __construct
public function __construct()
{
//cargamos la configuración de base de datos de codeigniter
require APPPATH . "config/database.php";
//utilizamos el namespace Entities para mapear el directorio models
$entitiesClassLoader = new ClassLoader('Entities', rtrim(APPPATH . "models"));
$entitiesClassLoader->register();
//utilizamos el namespace Proxies para mapear el directorio models/proxies
$proxiesClassLoader = new ClassLoader('Proxies', APPPATH . 'models/proxies');
$proxiesClassLoader->register();
// Configuración y chaché
$config = new Configuration();
$cache = new ArrayCache();
$config->setMetadataCacheImpl($cache);
$driverImpl = $config->newDefaultAnnotationDriver(array(APPPATH . 'models/entities'));
$config->setMetadataDriverImpl($driverImpl);
$config->setQueryCacheImpl($cache);
$config->setQueryCacheImpl($cache);
// Configuración Proxy
$config->setProxyDir(APPPATH . '/models/proxies');
$config->setProxyNamespace('Proxies');
// Habilitar el logger para obtener información de cada proceso
$logger = new EchoSQLLogger();
//$config->setSQLLogger($logger);
$config->setAutoGenerateProxyClasses(TRUE);
//configuramos la conexión con la base de datos utilizando las credenciales de nuestra app
$connectionOptions = array('driver' => 'pdo_mysql', 'user' => $db["default"]["username"], 'password' => $db["default"]["password"], 'host' => $db["default"]["hostname"], 'dbname' => $db["default"]["database"]);
// Creamos el EntityManager
$this->em = EntityManager::create($connectionOptions, $config);
}
示例12: __construct
public function __construct()
{
$this->setRoot("/var/www/html/uan/");
$this->setEntidade(array($this->getRoot() . "models/"));
$this->setIsDevMode(true);
$mode = "DESENVOLVIMENTO";
$config = Setup::createAnnotationMetadataConfiguration($this->getEntidade(), $this->getIsDevMode(), NULL, NULL, FALSE);
if ($mode == "DESENVOLVIMENTO") {
$cache = new \Doctrine\Common\Cache\ArrayCache();
} else {
$cache = new \Doctrine\Common\Cache\ApcCache();
}
$config = new Configuration();
$config->setMetadataCacheImpl($cache);
$driverImpl = $config->newDefaultAnnotationDriver($this->getRoot() . 'models/');
$config->setMetadataDriverImpl($driverImpl);
$config->setQueryCacheImpl($cache);
$config->setProxyDir($this->getRoot() . 'proxies/');
$config->setProxyNamespace('proxies');
if ($mode == "DESENVOLVIMENTO") {
$config->setAutoGenerateProxyClasses(true);
} else {
$config->setAutoGenerateProxyClasses(false);
}
$config = Setup::createAnnotationMetadataConfiguration($this->getEntidade(), $this->getIsDevMode(), NULL, NULL, FALSE);
$dbParams = array('driver' => 'pdo_mysql', 'user' => 'root', 'password' => '', 'dbname' => 'ceafie', 'charset' => 'utf8', 'driverOptions' => array(1002 => 'SET NAMES utf8'));
$this->em = EntityManager::create($dbParams, $config);
$loader = new ClassLoader('Entity', __DIR__ . '/models');
$loader->register();
}
示例13: __construct
public function __construct()
{
if (defined('FCPATH')) {
//Get CI instance
$this->ci = CI_Controller::get_instance();
//Load database configuration from CodeIgniter
$this->db = $this->ci->db;
//Database connection information
$connectionOptions = array('user' => $this->db->username, 'password' => $this->db->password, 'host' => $this->db->hostname, 'dbname' => $this->db->database);
} elseif (ENVIRONMENT === 'development') {
include_once str_replace("/", DIRECTORY_SEPARATOR, APPPATH) . 'config' . DIRECTORY_SEPARATOR . 'development' . DIRECTORY_SEPARATOR . 'database.php';
$connectionOptions = array('user' => $db['default']['username'], 'password' => $db['default']['password'], 'host' => $db['default']['hostname'], 'dbname' => $db['default']['database']);
}
$connectionOptions['driver'] = 'pdo_mysql';
$connectionOptions['charset'] = 'utf8';
$connectionOptions['driverOptions'] = array(1002 => 'SET NAMES utf8');
$config = new Configuration();
//Set up caches
$cache = new ArrayCache();
$config->setMetadataCacheImpl($cache);
$config->setQueryCacheImpl($cache);
//Set up Annotation
$driverImpl = $config->newDefaultAnnotationDriver(array(APPPATH . 'models/Entities'));
$config->setMetadataDriverImpl($driverImpl);
//Proxy configuration
$config->setProxyDir(APPPATH . '/models/proxies');
$config->setProxyNamespace('Proxies');
$config->setAutoGenerateProxyClasses(TRUE);
// Create EntityManager
$this->em = EntityManager::create($connectionOptions, $config);
//Fix the problem: "unknown database type enum requested"
$platform = $this->em->getConnection()->getDatabasePlatform();
$platform->registerDoctrineTypeMapping('enum', 'string');
}
示例14: createEntityManager
public static function createEntityManager($database)
{
$config = new Doctrine\ORM\Configuration();
// annotations
$annotationDriver = $config->newDefaultAnnotationDriver(array(APP_DIR . '/Model', NEURON_DIR . '/Model'));
$config->setMetadataDriverImpl($annotationDriver);
// proxy
$config->setProxyNamespace('Neuron\\Proxy');
$config->setProxyDir(TEMP_DIR);
// cache
$cache = Environment::isProduction() ? new NetteDoctrineCache() : new Doctrine\Common\Cache\ArrayCache();
$config->setMetadataCacheImpl($cache);
$config->setQueryCacheImpl($cache);
// debugbar
$config->setSQLLogger(Doctrine2Panel::getAndRegister());
// entity manager
$em = Doctrine\ORM\EntityManager::create((array) $database, $config);
$evm = $em->getEventManager();
$evm->addEventSubscriber(new Doctrine\DBAL\Event\Listeners\MysqlSessionInit("utf8", "utf8_czech_ci"));
$evm->addEventSubscriber(new ValidationSubscriber());
$evm->addEventSubscriber(new CacheSubscriber());
$neonParser = new \Nette\NeonParser();
$aliases = $neonParser->parse(file_get_contents(APP_DIR . "/entityClassAliases.neon"));
$evm->addEventSubscriber(new \Neuron\Model\Doctrine\EntityClassAliasesSubscriber($aliases));
return $em;
}
示例15: __construct
public function __construct($config)
{
if (isset($config["doctrine"])) {
$dbParams = $config["doctrine"]["db_params"];
$paths = StringCommon::replaceKeyWords($config["doctrine"]["entity_paths"]);
$isDevMode = $config["doctrine"]["is_dev_mode"];
$proxyDir = StringCommon::replaceKeyWords($config["doctrine"]["proxy_dir"]);
$proxyNamespace = $config["doctrine"]["proxy_namespace"];
$applicationMode = Game::getInstance()->getApplicationMode();
if ($applicationMode == Game::DEVELOPMENT_MODE) {
$cache = new \Doctrine\Common\Cache\ArrayCache();
} else {
$cache = new \Doctrine\Common\Cache\ApcCache();
}
$doctrineConfig = new Configuration();
$doctrineConfig->setMetadataCacheImpl($cache);
$driverImpl = $doctrineConfig->newDefaultAnnotationDriver($paths);
$doctrineConfig->setMetadataDriverImpl($driverImpl);
$doctrineConfig->setQueryCacheImpl($cache);
$doctrineConfig->setProxyDir($proxyDir);
$doctrineConfig->setProxyNamespace($proxyNamespace);
if ($applicationMode == Game::DEVELOPMENT_MODE) {
$doctrineConfig->setAutoGenerateProxyClasses(true);
} else {
$doctrineConfig->setAutoGenerateProxyClasses(false);
}
$entityManager = EntityManager::create($dbParams, $doctrineConfig);
Game::getInstance()->getContainer()->set("entity_manager", $entityManager);
} else {
throw new \RuntimeException("You need add Doctrine config in your res/config.yml");
}
}