本文整理汇总了PHP中Doctrine\ORM\Tools\Setup类的典型用法代码示例。如果您正苦于以下问题:PHP Setup类的具体用法?PHP Setup怎么用?PHP Setup使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Setup类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct()
{
require APPPATH . 'config/database.php';
$dbParams = array('driver' => 'pdo_mysql', 'user' => $db['default']['username'], 'password' => $db['default']['password'], 'host' => $db['default']['hostname'], 'dbname' => $db['default']['database'], 'charset' => $db['default']['char_set'], 'driverOptions' => array('charset' => $db['default']['char_set']));
$isDevMode = true;
$config = new Configuration();
$setup = new Setup();
$config = $setup->createAnnotationMetadataConfiguration(array(APPPATH . "models"), $isDevMode);
$config = $setup->createYAMLMetadataConfiguration(array(APPPATH . "models/Yaml"), $isDevMode);
$this->em = EntityManager::create($dbParams, $config);
}
示例2: getConfig
public static function getConfig($appName, $modelNames = null)
{
$mappingDriver = new Tinebase_Record_DoctrineMappingDriver();
if (!$modelNames) {
$modelNames = array();
foreach ($mappingDriver->getAllClassNames() as $modelName) {
$modelConfig = $modelName::getConfiguration();
if ($modelConfig->getApplName() == $appName) {
$modelNames[] = $modelName;
}
}
}
$tableNames = array();
foreach ($modelNames as $modelName) {
$modelConfig = $modelName::getConfiguration();
if (!$mappingDriver->isTransient($modelName)) {
throw new Setup_Exception('Model not yet doctrine2 ready');
}
$tableNames[] = SQL_TABLE_PREFIX . Tinebase_Helper::array_value('name', $modelConfig->getTable());
}
$config = Setup::createConfiguration();
$config->setMetadataDriverImpl($mappingDriver);
$config->setFilterSchemaAssetsExpression('/' . implode('|', $tableNames) . '/');
return $config;
}
示例3: setUp
public function setUp()
{
$this->_oldEntityManager = \SoliantEntityAudit\Module::getModuleOptions()->getEntityManager();
$this->_oldAuditedClassNames = \SoliantEntityAudit\Module::getModuleOptions()->getAuditedClassNames();
$this->_oldJoinClasses = \SoliantEntityAudit\Module::getModuleOptions()->resetJoinClasses();
$isDevMode = false;
$config = Setup::createConfiguration($isDevMode, null, null);
$chain = new DriverChain();
// Use ZFC User for authentication tests
$chain->addDriver(new XmlDriver(__DIR__ . '/../../../vendor/zf-commons/zfc-user-doctrine-orm/config/xml/zfcuser'), 'ZfcUser\\Entity');
$chain->addDriver(new XmlDriver(__DIR__ . '/../../../vendor/zf-commons/zfc-user-doctrine-orm/config/xml/zfcuserdoctrineorm'), 'ZfcUserDoctrineORM\\Entity');
$chain->addDriver(new StaticPHPDriver(__DIR__ . "/../Models"), 'SoliantEntityAuditTest\\Models\\LogRevision');
$chain->addDriver(new AuditDriver('.'), 'SoliantEntityAudit\\Entity');
$config->setMetadataDriverImpl($chain);
// Replace entity manager
$moduleOptions = \SoliantEntityAudit\Module::getModuleOptions();
$conn = array('driver' => 'pdo_sqlite', 'memory' => true);
$moduleOptions->setAuditedClassNames(array('SoliantEntityAuditTest\\Models\\LogRevision\\Album' => array(), 'SoliantEntityAuditTest\\Models\\LogRevision\\Performer' => array(), 'SoliantEntityAuditTest\\Models\\LogRevision\\Song' => array(), 'SoliantEntityAuditTest\\Models\\LogRevision\\SingleCoverArt' => array()));
$entityManager = EntityManager::create($conn, $config);
$moduleOptions->setEntityManager($entityManager);
$schemaTool = new SchemaTool($entityManager);
// Add auditing listener
$entityManager->getEventManager()->addEventSubscriber(new LogRevision());
$sql = $schemaTool->getUpdateSchemaSql($entityManager->getMetadataFactory()->getAllMetadata());
#print_r($sql);die();
$schemaTool->createSchema($entityManager->getMetadataFactory()->getAllMetadata());
$this->_em = $entityManager;
}
示例4: __construct
public function __construct(Configuration $configuration)
{
$driver = new PHPDriver(__DIR__ . '/../Mapping/');
$config = Setup::createConfiguration($configuration['debug']);
$config->setMetadataDriverImpl($driver);
$this->entityManager = EntityManager::create($configuration['database']['write_connection'], $config);
}
示例5: register
public function register(Application $app)
{
$app['orm.em.paths'] = $app->share(function () {
return array();
});
$app['orm.event_manager'] = $app->share(function () use($app) {
return new EventManager();
});
$app['orm.config'] = $app->share(function () use($app) {
return Setup::createConfiguration($app['debug']);
});
$app['orm.anotation_reader'] = $app->share(function () use($app) {
$annotationReader = new AnnotationReader();
$cache = $app['orm.config']->getMetadataCacheImpl();
return new CachedReader($annotationReader, $cache);
});
$app['orm.default_anotation_driver'] = $app->share(function () use($app) {
AnnotationRegistry::registerFile($app['vendor_dir'] . '/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php');
return new AnnotationDriver($app['orm.anotation_reader'], $app['orm.em.paths']);
});
$app['orm.em'] = $app->share(function () use($app) {
$annotationReader = $app['orm.anotation_reader'];
$eventManager = $app['orm.event_manager'];
$driverChain = new MappingDriverChain();
$driverChain->setDefaultDriver($app['orm.default_anotation_driver']);
DoctrineExtensions::registerMappingIntoDriverChainORM($driverChain, $annotationReader);
$loggableListener = new LoggableListener();
$loggableListener->setAnnotationReader($annotationReader);
$loggableListener->setUsername('admin');
$eventManager->addEventSubscriber($loggableListener);
$config = $app['orm.config'];
$config->setMetadataDriverImpl($driverChain);
return EntityManager::create($app['db.default_options'], $config, $eventManager);
});
}
示例6: register
public function register(Application $app)
{
$paths = array(realpath($app['config']['doctrine']['paths']['entity']));
$isDevMode = $app['config']['doctrine']['devMode'];
$config = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode, null, null, false);
$app['doctrine'] = EntityManager::create($app['config']['doctrine']['db'], $config);
}
示例7: createService
public function createService(ServiceLocatorInterface $serviceLocator)
{
$config = $serviceLocator->get('config');
// The parameters in Doctrine 2 and ZF2 are slightly different.
// Below is an example how we can reuse the db settings
$doctrineDbConfig = (array) $config['db'];
$doctrineDbConfig['driver'] = strtolower($doctrineDbConfig['driver']);
if (!isset($doctrineDbConfig['dbname'])) {
$doctrineDbConfig['dbname'] = $doctrineDbConfig['database'];
}
if (!isset($doctrineDbConfig['host'])) {
$doctrineDbConfig['host'] = $doctrineDbConfig['hostname'];
}
if (!isset($doctrineDbConfig['user'])) {
$doctrineDbConfig['user'] = $doctrineDbConfig['username'];
}
$doctrineConfig = Setup::createAnnotationMetadataConfiguration($config['doctrine']['entity_path'], true);
$entityManager = DoctrineEntityManager::create($doctrineDbConfig, $doctrineConfig);
if (isset($config['doctrine']['initializers'])) {
$eventManager = $entityManager->getEventManager();
foreach ($config['doctrine']['initializers'] as $initializer) {
$eventClass = new DoctrineEvent(new $initializer(), $serviceLocator);
$eventManager->addEventListener(\Doctrine\ORM\Events::postLoad, $eventClass);
}
}
if ($serviceLocator->has('doctrine-profiler')) {
$profiler = $serviceLocator->get('doctrine-profiler');
$entityManager->getConfiguration()->setSQLLogger($profiler);
}
return $entityManager;
}
示例8: getEntityManager
/**
* @return EntityManager
*/
public function getEntityManager()
{
if (!$this->entityManager instanceof EntityManager) {
$this->entityManager = EntityManager::create($this->getConfiguration()->get('database'), Setup::createAnnotationMetadataConfiguration([$this->rootPath . '/src/Classes/Entities/', __DIR__ . '/Domain/Entities/'], true));
}
return $this->entityManager;
}
示例9: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$dbName = $input->getArgument('dbname');
$path = $input->getOption('path');
$extensionKey = $input->getOption('extension-key');
$connectionParams = array('dbname' => $dbName, 'user' => $input->getOption('user'), 'password' => $input->getOption('password'), 'host' => $input->getOption('host'), 'driver' => $input->getOption('driver'), 'port' => $input->getOption('port'));
$config = Setup::createAnnotationMetadataConfiguration(array('.'), false);
$em = EntityManager::create($connectionParams, $config);
$em->getConfiguration()->setMetadataDriverImpl(new \Doctrine\ORM\Mapping\Driver\DatabaseDriver($em->getConnection()->getSchemaManager()));
$cmf = new DisconnectedClassMetadataFactory();
$cmf->setEntityManager($em);
if (is_null($extensionKey)) {
$extensionKey = $dbName;
if (self::DEFAULT_PATH != $path) {
$extensionKey = array_pop(explode(DIRECTORY_SEPARATOR, $path));
}
}
$exporter = new ExtbaseExporter($cmf);
$exporter->setExtensionKey($extensionKey);
$exporter->setPath($input->getOption('path'));
self::mapDefaultInputOptions($exporter, $input);
$output->writeln(sprintf('Exporting database schema "<info>%s</info>".', $dbName));
$result = $exporter->exportJson();
foreach ($exporter->getLogs() as $log) {
$output->writeln($log);
}
return $result ? 0 : 1;
}
示例10: __construct
private function __construct()
{
$settings = Setup::getSettings();
$config = \Doctrine\ORM\Tools\Setup::createXMLMetadataConfiguration([__DIR__ . '/../Mapper', 'Bh/Mapper'], $settings['DevMode']);
$conn = array('driver' => 'pdo_mysql', 'user' => $settings['DbUser'], 'password' => $settings['DbPass'], 'dbname' => $settings['DbName']);
self::$entityManager = \Doctrine\ORM\EntityManager::create($conn, $config);
}
示例11: __construct
public function __construct($sm, $params = array())
{
$this->sm = $sm;
$path = $sm->get('pegase.core.path');
foreach ($params['entities_folders'] as $i => $f) {
$params['entities_folders'][$i] = $path->get_path($f);
}
$this->db_params = $params['database'];
$isDevMode = true;
$config = Setup::createAnnotationMetadataConfiguration($params['entities_folders'], $isDevMode);
$this->em = EntityManager::create($params['database'], $config);
/*
// on vérifie la validité des mappings
$validator = new SchemaValidator($this->em);
$errors = $validator->validateMapping();
if(count($errors) > 0) {
// Lots of errors!
echo implode("\n\n", $errors);
}
else
echo "Les mappings sont ok.\n";
*/
$this->schema = new Schema($sm, $this);
$this->database = new Database($sm, $this);
$this->entity = new Entity($sm, $this);
}
示例12: addEntityManager
/**
* This method is used to add an entity manager to the doctrine service.
* @param $id string The id you would like to store with the entity manager.
* @param ulfberht\module\doctrine\config $config The doctrine configuration for
* the entity manager.
* @return void
*/
public function addEntityManager($id, config $config)
{
$development = $config->develop ? true : false;
$cache = $config->enableCache ? new ArrayCache() : null;
//setup type of metadata reading
switch ($config->type) {
case 'annotation':
$docConfig = Setup::createAnnotationMetadataConfiguration($config->paths, $development, null, $cache);
break;
case 'xml':
$docConfig = Setup::createXMLMetadataConfiguration($config->paths, $development, null, $cache);
break;
case 'yaml':
$docConfig = Setup::createYAMLMetadataConfiguration($config->paths, $development, null, $cache);
break;
}
//setup caching
if (!is_null($cache)) {
$docConfig->setQueryCacheImpl($cache);
$docConfig->setMetadataCacheImpl($cache);
}
//setup database connection
$dbConnInfo = array('driver' => $config->database->driver, 'host' => $config->database->host, 'dbname' => $config->database->name, 'user' => $config->database->user, 'password' => $config->database->password);
//store entity manager
$this->_doctrineEntityMangers[$id] = EntityManager::create($dbConnInfo, $docConfig);
}
示例13: __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();
}
示例14: __construct
public function __construct()
{
$yamlParser = new Parser();
$dbParams = $yamlParser->parse(file_get_contents(__DIR__ . '/parameters.yml'));
$config = Setup::createAnnotationMetadataConfiguration(array(__DIR__ . '/../Entity'), true);
$this->em = EntityManager::create($dbParams['database'], $config);
}
示例15: __construct
/**
* @param array $database
* @throws \Exception
*/
public function __construct($database = [])
{
$this->db = $database;
foreach ($this->db as $key => $db) {
$this->allDb[$key] = function () use($db) {
$db['dev'] = isset($db['dev']) && $db['dev'] ? true : false;
if (isset($db['db_url'])) {
$dbParams = array('url' => $db['db_url']);
} else {
if (!isset($db['driver']) || !isset($db['user']) || !isset($db['pass']) || !isset($db['host']) || !isset($db['db'])) {
throw new \Exception('Missing arguments for doctrine constructor');
}
$dbParams = array('driver' => $this->getDriver($db['driver']), 'user' => $db['user'], 'password' => $db['pass'], 'host' => $db['host'], 'dbname' => $db['db'], 'charset' => isset($db['charset']) ? $db['charset'] : 'utf8');
}
$evm = new EventManager();
if (isset($db['prefix'])) {
$tablePrefix = new TablePrefix($db['prefix']);
$evm->addEventListener(Events::loadClassMetadata, $tablePrefix);
}
$config = Setup::createAnnotationMetadataConfiguration($db['path'], $db['dev']);
if (!$db['dev']) {
$config->setQueryCacheImpl($db['cache']);
$config->setResultCacheImpl($db['cache']);
$config->setMetadataCacheImpl($db['cache']);
}
if (isset($db['functions']) && !empty($db['functions'])) {
$config->setCustomDatetimeFunctions($db['functions']['customDatetimeFunctions']);
$config->setCustomNumericFunctions($db['functions']['customNumericFunctions']);
$config->setCustomStringFunctions($db['functions']['customStringFunctions']);
}
return EntityManager::create($dbParams, $config, $evm);
};
}
}