本文整理汇总了PHP中Doctrine\ORM\Tools\Setup::createConfiguration方法的典型用法代码示例。如果您正苦于以下问题:PHP Setup::createConfiguration方法的具体用法?PHP Setup::createConfiguration怎么用?PHP Setup::createConfiguration使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\Tools\Setup
的用法示例。
在下文中一共展示了Setup::createConfiguration方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
protected function setUp()
{
$pathToEntities = [__DIR__ . '/Entity'];
$isDevMode = true;
$connectionParams = array('user' => 'user', 'password' => 'password', 'driver' => 'pdo_sqlite', 'memory' => true);
$config = Setup::createConfiguration($isDevMode);
$driver = new AnnotationDriver(new AnnotationReader(), $pathToEntities);
AnnotationRegistry::registerLoader('class_exists');
$config->setMetadataDriverImpl($driver);
$this->em = EntityManager::create($connectionParams, $config);
/*
* Устанавливаем фикстуры, знаю что можно это сделать более универсально, но ... в данном контексте мне больше и не надо
*/
$conn = $this->em->getConnection();
$conn->exec("CREATE TABLE clients (id INTEGER PRIMARY KEY, name TEXT, surname TEXT);");
$conn->exec("CREATE TABLE authors (id INTEGER PRIMARY KEY, name TEXT, surname TEXT);");
$conn->exec("CREATE TABLE books (id INTEGER, owner_id INTEGER, name TEXT, surname TEXT, CONSTRAINT 'pk' PRIMARY KEY (id, owner_id));");
$conn->exec("INSERT INTO clients (name,surname) VALUES('Nikita','Sapogov')");
$conn->exec("INSERT INTO clients (name,surname) VALUES('Alex','Ivanov')");
$conn->exec("INSERT INTO clients (name,surname) VALUES('Sura','Soir')");
$conn->exec("INSERT INTO clients (name,surname) VALUES('Vasya','Poliakocv')");
$conn->exec("INSERT INTO books (id, owner_id, name) VALUES (1,1,'SuperBookNAme')");
$conn->exec("INSERT INTO books (id, owner_id, name) VALUES (2,15,'SuperBookNAme2')");
$conn->exec("INSERT INTO books (id, owner_id, name) VALUES (3,3,'SuperBookNAme3')");
}
示例2: 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;
}
示例3: register
public function register(Application $app)
{
$self = $this;
$app["orm.proxy_dir"] = NULL;
$app["orm.cache"] = NULL;
$app["orm.is_dev_mode"] = $app["debug"];
$app['orm.driver.configs'] = array();
$app["orm.chain_driver"] = $app->share(function () {
return new MappingDriverChain();
});
/**
* EN : create entity manager config
* FR : creer la configuration de l'entity mananger
*/
$app["orm.config"] = $app->share(function ($app) {
$config = Setup::createConfiguration($app["orm.is_dev_mode"], $app["orm.proxy_dir"], $app["orm.cache"]);
$config->setMetadataDriverImpl($app["orm.chain_driver"]);
if (isset($app["orm.logger"])) {
$config->setSQLLogger($app["orm.logger"]);
}
$config->addCustomDatetimeFunction("DATE", 'Mparaiso\\Doctrine\\ORM\\Functions\\Date');
return $config;
});
/**
* EN : create the entity manager
* FR : créer l'entity manager
*/
$app["orm.em"] = $app->share(function ($app) use($self) {
foreach ($app["orm.driver.configs"] as $key => $config) {
if (!is_array($config['paths'])) {
throw new Exception(' $config["paths"] must be an array of paths ');
}
if ($key == "default") {
$app["orm.chain_driver"]->setDefaultDriver($self->getDriver($config['type'], $config['paths'], $app["orm.config"]));
}
$app["orm.chain_driver"]->addDriver($self->getDriver($config['type'], $config['paths'], $app["orm.config"]), $config["namespace"]);
}
if (!isset($app["orm.connection"]) && $app["db"]) {
$app["orm.connection"] = $app["db"];
}
$em = EntityManager::create($app["orm.connection"], $app["orm.config"]);
return $em;
});
$app['orm.manager_registry'] = $app->share(function ($app) {
return new DoctrineManagerRegistry("manager_registry", array("default" => $app['orm.em']->getConnection()), array("default" => $app['orm.em']));
});
/* call this to install Doctrine orm's commands $app['orm.console.boot_commands']() */
$app['orm.console.boot_commands'] = $app->protect(function () use($app) {
if (isset($app["console"])) {
$em = $app['orm.em'];
/* @var $console \Symfony\Component\Console\Application */
$console = $app["console"];
$console->getHelperSet()->set(new EntityManagerHelper($em), "em");
$console->getHelperSet()->set(new ConnectionHelper($em->getConnection()), "db");
ConsoleRunner::addCommands($app["console"]);
$console->add(new ImportMappingDoctrineCommand());
$console->add(new LoadFixturesCommand());
}
});
}
示例4: hydrate
public function hydrate(Jarvis $app)
{
$app['doctrine.cache'] = function () {
return new VoidCache();
};
$app['doctrine.annotation.driver'] = function () {
return new AnnotationDriver(new AnnotationReader());
};
$app['entyMgr'] = function (Jarvis $app) : EntityManagerInterface {
$settings = $app['doctrine.settings'];
$cache = $app['doctrine.cache'];
$config = Setup::createConfiguration($settings['debug'], $settings['proxies_dir'], $cache);
$driver = $app['doctrine.annotation.driver'];
if (isset($settings['entities_paths'])) {
$driver->addPaths((array) $settings['entities_paths']);
}
AnnotationRegistry::registerLoader('class_exists');
$config->setMetadataDriverImpl($driver);
$config->setAutoGenerateProxyClasses($settings['debug']);
$config->setMetadataCacheImpl($cache);
$config->setResultCacheImpl($cache);
$config->setQueryCacheImpl($cache);
$entyMgr = EntityManager::create($settings['dbal'], $config);
if (isset($app['doctrine.orm.entyMgr.decorator']) && is_string($fqcn = $app['doctrine.orm.entyMgr.decorator']) && is_subclass_of($fqcn, EntityManagerDecorator::class)) {
$entyMgr = new $fqcn($entyMgr);
}
$entyMgr->getEventManager()->addEventListener([Events::preRemove, Events::postRemove, Events::prePersist, Events::postPersist, Events::preUpdate, Events::postUpdate, Events::postLoad, Events::preFlush, Events::onFlush, Events::postFlush, Events::onClear], new EventListener($app));
$app->broadcast(DoctrineReadyEvent::READY_EVENT, new DoctrineReadyEvent($entyMgr));
return $entyMgr;
};
$app['db_conn'] = function ($app) {
$app['entyMgr']->getConnection();
};
$app->lock(['entyMgr', 'db_conn', 'doctrine.annotation.driver']);
}
示例5: 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;
}
示例6: __construct
public function __construct($setConfigFiles = true)
{
if ($setConfigFiles) {
$this->configFile = __DIR__ . '/../../../config.php';
$this->localConfigFile = __DIR__ . '/../../../config.local.php';
}
parent::__construct();
$isDevMode = false;
$cache = new \Doctrine\Common\Cache\FilesystemCache(__DIR__ . '/../../tmp');
$config = Setup::createConfiguration($isDevMode, __DIR__ . '/../../tmp', $cache);
$config->setProxyDir(__DIR__ . '/../../tmp');
$config->setProxyNamespace('MyProject\\Proxies');
$config->setAutoGenerateProxyClasses(true);
$paths = [__DIR__ . '/../Entity'];
$driver = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver(new AnnotationReader(), $paths);
\Doctrine\Common\Annotations\AnnotationRegistry::registerLoader('class_exists');
$config->setMetadataDriverImpl($driver);
//$config->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger());
$conn = ['driver' => 'mysqli', 'host' => '127.0.0.1', 'user' => $this->databaseFactory->getUserName(), 'password' => $this->databaseFactory->getPassword(), 'dbname' => $this->databaseFactory->getDatabaseName()];
$this->entityManager = EntityManager::create($conn, $config);
$this->entityManager->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string');
\Doctrine\DBAL\Types\Type::addType('enum', StringType::class);
$this->entityManager->getConfiguration()->addCustomStringFunction('DATE', DateFunction::class);
$this->user = $this->entityManager->createQueryBuilder()->select('u')->from(Sources\Tests\Entity\User::class, 'u');
}
示例7: setUp
protected function setUp()
{
$pathToEntities = [__DIR__ . '/Entity'];
$isDevMode = true;
$dbPath = __DIR__ . "/db.db";
$connectionParams = array('user' => 'user', 'password' => 'password', 'driver' => 'pdo_sqlite', 'path' => $dbPath);
if (file_exists($dbPath)) {
unlink($dbPath);
}
$config = Setup::createConfiguration($isDevMode);
$driver = new AnnotationDriver(new AnnotationReader(), $pathToEntities);
AnnotationRegistry::registerLoader('class_exists');
$config->setMetadataDriverImpl($driver);
$this->em = EntityManager::create($connectionParams, $config);
/*
* Устанавливаем фикстуры, знаю что можно это сделать более универсально, но ... в данном контексте мне больше и не надо
*/
$conn = $this->em->getConnection();
/*
* ВНИМАНИЕ: Поля в таблице сделаны так, что сравниваются они не зависимо от регистра!
*/
$conn->exec("CREATE TABLE clients (id INTEGER PRIMARY KEY, name TEXT COLLATE NOCASE, surname TEXT COLLATE NOCASE);");
$conn->exec("INSERT INTO clients (name,surname) VALUES('Никита','Сапогов')");
$conn->exec("INSERT INTO clients (name,surname) VALUES('Валерий','Иванов')");
$conn->exec("INSERT INTO clients (name,surname) VALUES('Сурий','Мазур')");
$conn->exec("INSERT INTO clients (name,surname) VALUES('Вася','Корибасов Иван')");
}
示例8: __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);
}
示例9: registerDoctrine
/**
* @return Services
*/
protected function registerDoctrine() : Services
{
// LiveCycle Events
$this->getContainer()->share(EventManager::class, EventManager::class);
// Annotation Stuff
$this->getContainer()->share(Reader::class, function () {
return new AnnotationReader();
});
// Configuration
$this->getContainer()->share(Configuration::class, function () : Configuration {
$config = Setup::createConfiguration($this->getContainer()->get('debug'), null, $this->getContainer()->get(Cache::class));
$config->setMetadataDriverImpl($this->getContainer()->get(MappingDriver::class));
$config->setAutoGenerateProxyClasses($this->getContainer()->get('debug'));
// Shorthand Namespace for Annotation, Query and Repository Stuff
$config->addEntityNamespace('MyApp', 'MyApp\\Models');
return $config;
});
// Cache
$this->getContainer()->share(Cache::class, function () : Cache {
// (or no cache in this ArrayCache case)
return new ArrayCache();
});
// Doctrine! No Really! The EntityManager ;)
$this->getContainer()->share(EntityManagerInterface::class, function () : EntityManagerInterface {
return EntityManager::create($this->getContainer()->get('doctrine_connection'), $this->getContainer()->get(Configuration::class), $this->getContainer()->get(EventManager::class));
});
// Now lets wrap doctrine
$this->getContainer()->share(UserManager::class, function () {
return new UserManager($this->container->get(EntityManagerInterface::class));
});
return $this;
}
示例10: __construct
/**
* constructor
*/
public function __construct()
{
// load database configuration from CodeIgniter
require APPPATH . 'config/database.php';
$doctrineClassLoader = new ClassLoader('Doctrine', FCPATH . 'vendors');
$doctrineClassLoader->register();
$symfonyClassLoader = new ClassLoader('Symfony', FCPATH . 'vendors/Doctrine');
$symfonyClassLoader->register();
$entityClassLoader = new ClassLoader('Entity', APPPATH . 'models');
$entityClassLoader->register();
$config = Doctrine\ORM\Tools\Setup::createConfiguration(ENVIRONMENT !== 'production');
$driverImpl = new AnnotationDriver(new AnnotationReader(), [APPPATH . 'models']);
AnnotationRegistry::registerLoader('class_exists');
$config->setMetadataDriverImpl($driverImpl);
// Proxy configuration
$config->setProxyDir(APPPATH . 'models/Proxies');
$config->setProxyNamespace('Proxies');
if (ENVIRONMENT === 'production') {
// Set up caches
$cache = new ArrayCache();
$config->setMetadataCacheImpl($cache);
$config->setQueryCacheImpl($cache);
} else {
// Set up logger
// $logger = new EchoSQLLogger;
// $config->setSQLLogger($logger);
$config->setAutoGenerateProxyClasses(TRUE);
}
// Database connection information
$connectionOptions = array('driver' => $db[$active_group]['dbdriver'], 'user' => $db[$active_group]['username'], 'password' => $db[$active_group]['password'], 'host' => $db[$active_group]['hostname'], 'port' => $db[$active_group]['port'], 'dbname' => $db[$active_group]['database'], 'charset' => $db[$active_group]['char_set'], 'collation' => $db[$active_group]['dbcollat']);
// Create EntityManager
$this->em = EntityManager::create($connectionOptions, $config);
}
示例11: bootstrap
public static function bootstrap($dbConfig, $package, $applicationMode = 'development')
{
$packagePath = str_replace('\\', DIRECTORY_SEPARATOR, $package);
$paths = array(__DIR__ . '/../../../../../../../application/packages/' . $packagePath . '/models/entities');
$isDevMode = $applicationMode == 'development' ? true : false;
$dbParams = array('driver' => $dbConfig->driver, 'user' => $dbConfig->username, 'password' => $dbConfig->password, 'dbname' => $dbConfig->dbname);
if ($applicationMode == "development") {
$cache = new \Doctrine\Common\Cache\ArrayCache();
} else {
$cache = new \Doctrine\Common\Cache\ApcCache();
}
$config = Setup::createConfiguration($isDevMode);
$driver = new AnnotationDriver(new AnnotationReader(), $paths);
// registering noop annotation autoloader - allow all annotations by default
AnnotationRegistry::registerLoader('class_exists');
$config->setMetadataDriverImpl($driver);
$proxyDir = __DIR__ . '/../../../../../../../application/packages/' . $packagePath . '/models/proxies';
$proxyNamespace = $package . '\\models\\proxies\\';
$config->setProxyDir($proxyDir);
$config->setProxyNamespace($proxyNamespace);
$config->setMetadataCacheImpl($cache);
$config->setQueryCacheImpl($cache);
if ($applicationMode == "development") {
$config->setAutoGenerateProxyClasses(true);
} else {
$config->setAutoGenerateProxyClasses(false);
}
return EntityManager::create($dbParams, $config);
}
示例12: 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);
});
}
示例13: registerServices
public function registerServices(\Phalcon\DiInterface $di)
{
//registrando annotations
$this->registerAnnotationsFiles(['Column', 'Entity', 'GeneratedValue', 'HasLifecycleCallbacks', 'Id', 'PrePersist', 'PreUpdate', 'Table', 'ManyToOne', 'ManyToMany', 'JoinTable', 'JoinColumn']);
//configurando entity manager
$di->setShared('entityManager', function () use($di) {
$infraConfig = $di->get('Infrastructure\\Config');
// $doctrine_config = Setup::createAnnotationMetadataConfiguration($infraConfig['ormMapper'], $di->get('App\Config')['devmode']);
$config = Setup::createConfiguration($di->get('App\\Config')['devmode']);
$driver = new AnnotationDriver(new AnnotationReader(), $infraConfig['ormMapper']);
// registering noop annotation autoloader - allow all annotations by default
AnnotationRegistry::registerLoader('class_exists');
$config->setMetadataDriverImpl($driver);
$entityManager = EntityManager::create($infraConfig['databases'][0], $config);
$platform = $entityManager->getConnection()->getDatabasePlatform();
$platform->registerDoctrineTypeMapping('enum', 'string');
return $entityManager;
});
$di->setShared('api', function () use($di) {
$infraConfig = $di->get('Infrastructure\\Config');
return new Service\RESTClient($infraConfig['baseUrl']['api'], $infraConfig['credentials']);
});
$di->setShared('geocodeApi', function () use($di) {
return new Service\RESTClient('https://maps.googleapis.com/maps/api/geocode/json?&key=AIzaSyBwFWzpssaahZ7SfLZt6mv7PeZBFXImpmo&address=');
});
}
示例14: setUpBeforeClass
public static function setUpBeforeClass()
{
// bootstrap doctrine
self::$dbParams = array('driver' => 'pdo_sqlite', 'user' => 'root', 'password' => '', 'memory' => true);
self::$config = Setup::createConfiguration(true);
self::$config->setMetadataDriverImpl(new AnnotationDriver(new AnnotationReader()));
//self::$config->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger());
}
示例15: createFor
/**
* Creates the ORM configuration for the given set of entities.
*
* @param string[] $entityClasses
* @return \Doctrine\ORM\Configuration
*/
public function createFor(array $entityClasses)
{
$config = Setup::createConfiguration(true, null, new ArrayCache());
$driver = new AnnotationDriver($this->getAnnotationReader(), $this->getFilePathsForClassNames($entityClasses));
$driver = new EntityListDriverDecorator($driver, $entityClasses);
$config->setMetadataDriverImpl($driver);
return $config;
}