本文整理汇总了PHP中Doctrine\ORM\Tools\Setup::createAnnotationMetadataConfiguration方法的典型用法代码示例。如果您正苦于以下问题:PHP Setup::createAnnotationMetadataConfiguration方法的具体用法?PHP Setup::createAnnotationMetadataConfiguration怎么用?PHP Setup::createAnnotationMetadataConfiguration使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\Tools\Setup
的用法示例。
在下文中一共展示了Setup::createAnnotationMetadataConfiguration方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testExtractors
/**
* @dataProvider extractorsDataProvider
*
* @param $class
* @param $extractor
* @param $properties
*/
public function testExtractors($class, $extractor, $properties)
{
$config = Setup::createAnnotationMetadataConfiguration([__DIR__], true);
$entityManager = EntityManager::create(['driver' => 'pdo_sqlite'], $config);
/** @var TypeExtractorInterface $extractor */
$extractor = new $extractor($entityManager->getMetadataFactory());
$propertyInfo = new PropertyInfo([$extractor], []);
foreach ($properties as $property) {
$reflectionProperty = new \ReflectionProperty($class, $property['name']);
$expectedType = $property['type'];
/** @var Type[] $actualTypes */
$actualTypes = $propertyInfo->getTypes($reflectionProperty);
$actualType = $actualTypes[0];
if ($expectedType !== null) {
$this->assertEquals($expectedType, $actualType->getType());
$this->assertEquals($property['class'], $actualType->getClass());
$this->assertEquals($property['collection'], $actualType->isCollection());
if (isset($property['collectionType'])) {
$actualCollectionType = $actualType->getCollectionType();
$this->assertEquals($property['collectionType']['type'], $actualCollectionType->getType());
$this->assertEquals($property['collectionType']['class'], $actualCollectionType->getClass());
$this->assertEquals($property['collectionType']['collection'], $actualCollectionType->isCollection());
}
} else {
$this->assertNull($actualType);
}
}
}
示例2: getEntityManager
/**
* @return EntityManager
* @throws ServiceNotRegisteredException
*/
public static function getEntityManager()
{
if (ServiceLocator::$entityManager === null) {
ServiceLocator::$entityManager = EntityManager::create(['driver' => Config::DB_DRIVER, 'host' => Config::DB_HOST, 'dbname' => Config::DB_NAME, 'user' => Config::DB_USER, 'password' => Config::DB_PASS], Setup::createAnnotationMetadataConfiguration([__DIR__ . '/../Models'], Config::DEV_MODE, null, null, false));
}
return ServiceLocator::checkAndReturn(ServiceLocator::$entityManager);
}
示例3: __construct
public function __construct()
{
try {
$conn = array("driver" => "pdo_mysql", "host" => "localhost", "port" => "3306", "user" => "root", "password" => "", "dbname" => "controle_gastos");
/*
var_dump(__DIR__);
var_dump(PP);
exit;
*/
$loader = new \Doctrine\Common\ClassLoader("Entities", __DIR__);
$loader->register();
$config = Setup::createAnnotationMetadataConfiguration(array("../../" . __DIR__ . "/app/models"), false);
$em = EntityManager::create($conn, $config);
$cmf = new DisconnectedClassMetadataFactory();
$cmf->setEntityManager($em);
$em->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('set', 'string');
$em->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string');
$driver = new DatabaseDriver($em->getConnection()->getSchemaManager());
$em->getConfiguration()->setMetadataDriverImpl($driver);
$metadata = $cmf->getAllMetadata();
$generator = new EntityGenerator();
$generator->setGenerateAnnotations(true);
$generator->setGenerateStubMethods(true);
$generator->setRegenerateEntityIfExists(true);
$generator->setUpdateEntityIfExists(true);
$generator->generate($metadata, "../../" . __DIR__ . "/app/models");
} catch (\Exception $e) {
throw $e;
}
}
示例4: 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);
}
示例5: 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;
}
示例6: setUp
public function setUp()
{
// register our custom type
if (!Type::hasType('hstore')) {
Type::addType('hstore', 'EasyBib\\Doctrine\\Types\\Hstore');
}
$isDevMode = true;
$doctrineConfig = Setup::createAnnotationMetadataConfiguration(array(__DIR__ . '/Entity'), $isDevMode);
// database configuration parameters
$rootTestsFolder = dirname(dirname(dirname(dirname(__DIR__))));
$this->isTravis = getenv("TRAVIS");
if (file_exists($rootTestsFolder . '/db-config.php')) {
$dbConfig = (include $rootTestsFolder . '/db-config.php');
} elseif (false !== $this->isTravis) {
$dbConfig = (include $rootTestsFolder . '/db-config-travisci.php');
} else {
throw new \RuntimeException("No database configuration found.");
}
// create the entity manager
$this->em = EntityManager::create($dbConfig, $doctrineConfig);
// enable 'hstore'
$this->em->getConnection()->exec("CREATE EXTENSION IF NOT EXISTS hstore");
// register type with DBAL
$this->em->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('hstore', 'hstore');
// make the PersistentObject happy
PersistentObject::setObjectManager($this->em);
// create table
$this->setUpSchema($this->em);
}
示例7: __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);
};
}
}
示例8: buildEntityManagers
/**
* @param ApplicationInterface $app
*
* @throws \Doctrine\ORM\ORMException
* @throws \ObjectivePHP\Primitives\Exception
* @throws \ObjectivePHP\ServicesFactory\Exception
*/
public function buildEntityManagers(ApplicationInterface $app)
{
$entityManagers = $app->getConfig()->subset(Config\EntityManager::class);
foreach ($entityManagers as $connection => $params) {
if (isset($params['db'])) {
$params = $params['db'];
}
// normalize if needed
$entitiesPaths = $params['entities.locations'];
Collection::cast($entitiesPaths)->each(function (&$path) {
if (strpos($path, '/') !== 0) {
$path = getcwd() . '/' . $path;
}
});
// TODO: handle isDev depending on app config
$emConfig = Setup::createAnnotationMetadataConfiguration((array) $entitiesPaths, true);
$emConfig->setNamingStrategy(new UnderscoreNamingStrategy());
$em = EntityManager::create($params, $emConfig);
if (!empty($params['mapping_types']) && is_array($params['mapping_types'])) {
$platform = $em->getConnection()->getDatabasePlatform();
foreach ($params['mapping_types'] as $type => $mapping) {
if (!Type::hasType($type) && class_exists($mapping)) {
Type::addType($type, $mapping);
$mapping = $type;
}
$platform->registerDoctrineTypeMapping($type, $mapping);
}
}
// register entity manager as a service
$emServiceId = 'doctrine.em.' . Str::cast($connection)->lower();
$app->getServicesFactory()->registerService(['id' => $emServiceId, 'instance' => $em]);
$app->getServicesFactory()->registerService(['id' => 'db.connection.' . $connection, 'instance' => $em->getConnection()->getWrappedConnection()]);
}
}
示例9: init
/**
* @return void
*/
public function init()
{
if ($this->isInitialized()) {
return;
}
$context = $this->getApplication()->getContext();
$this->serviceConfig = $this->getServiceConfig();
$this->config = $this->getServiceConfig();
$this->eventManager = new EventManager();
$conn = $context->pluck('phpcrystal.phpcrystal.database')->toArray();
// database connection config
$isDevEnv = $context->getEnv() == 'dev';
$this->ormConfig = Setup::createAnnotationMetadataConfiguration([], $isDevEnv);
$this->ormConfig = new Configuration();
$cache = new ArrayCache();
$this->ormConfig->setMetadataCacheImpl($cache);
$driverImpl = $this->ormConfig->newDefaultAnnotationDriver([], false);
$this->ormConfig->setMetadataDriverImpl($driverImpl);
$this->ormConfig->setQueryCacheImpl($cache);
$this->ormConfig->setQueryCacheImpl($cache);
if (null != ($entityNSArray = $this->config->get('entityNamespaces'))) {
$this->ormConfig->setEntityNamespaces($entityNSArray);
}
// Proxy configuration
$this->ormConfig->setProxyDir($this->config->get('proxyDir'));
$this->ormConfig->setProxyNamespace($this->config->get('proxyNamespace'));
$this->entityManager = $this->createEntityManager($conn, $this->ormConfig, $this->eventManager);
$this->isInitialized = true;
return $this;
}
示例10: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
if (!GeometryEngineRegistry::has()) {
$this->markTestSkipped('This test requires a connection to a database.');
}
$engine = GeometryEngineRegistry::get();
if (!$engine instanceof PDOEngine) {
$this->markTestSkipped('This test currently only works with a PDO connection.');
}
$this->platform = $this->_conn->getDatabasePlatform();
$this->platform->registerDoctrineTypeMapping('geometry', 'binary');
$this->platform->registerDoctrineTypeMapping('linestring', 'binary');
$this->platform->registerDoctrineTypeMapping('multilinestring', 'binary');
$this->platform->registerDoctrineTypeMapping('multipoint', 'binary');
$this->platform->registerDoctrineTypeMapping('multipolygon', 'binary');
$this->platform->registerDoctrineTypeMapping('point', 'binary');
$this->platform->registerDoctrineTypeMapping('polygon', 'binary');
switch ($this->platform->getName()) {
case 'postgresql':
$this->_conn->executeQuery('CREATE EXTENSION IF NOT EXISTS postgis;');
break;
}
$this->fixtureLoader = new Loader();
$config = Setup::createAnnotationMetadataConfiguration([__DIR__ . '/Fixtures'], false);
$config->addCustomNumericFunction('EarthDistance', EarthDistanceFunction::class);
$this->em = EntityManager::create($this->_conn, $config, $this->platform->getEventManager());
$this->schemaTool = new SchemaTool($this->em);
$this->schemaTool->updateSchema([$this->em->getClassMetadata(Fixtures\GeometryEntity::class), $this->em->getClassMetadata(Fixtures\LineStringEntity::class), $this->em->getClassMetadata(Fixtures\MultiLineStringEntity::class), $this->em->getClassMetadata(Fixtures\MultiPointEntity::class), $this->em->getClassMetadata(Fixtures\MultiPolygonEntity::class), $this->em->getClassMetadata(Fixtures\PointEntity::class), $this->em->getClassMetadata(Fixtures\PolygonEntity::class)]);
$purger = new ORMPurger();
$this->ormExecutor = new ORMExecutor($this->em, $purger);
}
示例11: registerEntityManager
private function registerEntityManager()
{
$this->app->singleton('DoctrineOrm', function ($app) {
$config = $app['config']['doctrine::doctrine'];
$metadata = Setup::createAnnotationMetadataConfiguration($config['metadata'], $app['config']['app.debug'], $config['proxy']['directory'], $app[CacheManager::class]->getCache($config['cache_provider']), $config['simple_annotations']);
$metadata->addFilter('trashed', TrashedFilter::class);
$metadata->setAutoGenerateProxyClasses($config['proxy']['auto_generate']);
$metadata->setDefaultRepositoryClassName($config['repository']);
$metadata->setSQLLogger($config['logger']);
$metadata->setNamingStrategy($app->make(LaravelNamingStrategy::class));
if (isset($config['proxy']['namespace'])) {
$metadata->setProxyNamespace($config['proxy']['namespace']);
}
$eventManager = new EventManager();
$connection_config = $this->mapLaravelToDoctrineConfig($app['config']);
//load prefix listener
if (isset($connection_config['prefix'])) {
$tablePrefix = new TablePrefix($connection_config['prefix']);
$eventManager->addEventListener(Events::loadClassMetadata, $tablePrefix);
}
$eventManager->addEventListener(Events::onFlush, new SoftDeletableListener());
$entityManager = EntityManager::create($connection_config, $metadata, $eventManager);
$entityManager->getFilters()->enable('trashed');
return $entityManager;
});
//$this->app->alias('DoctrineOrm', EntityManagerInterface::class);
}
示例12: initDoctrine
private static function initDoctrine()
{
App::$inst->container->singleton('DoctrineConfig', function () {
$paths = array(APPLICATION_PATH . "/models/Entity");
$isDevMode = false;
$config = \Doctrine\ORM\Tools\Setup::createAnnotationMetadataConfiguration($paths, $isDevMode);
if (isset(App::$inst->config['resources']['doctrine']['proxiesPath'])) {
$config->setProxyDir(App::$inst->config['resources']['doctrine']['proxiesPath']);
} elseif (IS_SAVVIS) {
$config->setProxyDir(sprintf('/tmp/%s/proxies', App::$inst->config['resources']['doctrine']['dbal']['connection']['parameters']['dbname']));
} else {
$config->setProxyDir(APPLICATION_PATH . '/tmp/proxies');
}
$config->setProxyNamespace('Application\\tmp\\proxies');
$config->setAutoGenerateProxyClasses(true);
return $config;
});
App::$inst->container->singleton('em', function () {
$config = App::$inst->DoctrineConfig;
$entityManager = \Doctrine\ORM\EntityManager::create(App::$inst->config['resources']['doctrine']['dbal']['connection']['parameters'], $config);
return $entityManager;
});
App::$inst->cache = Bootstrap::initDoctrineCache(App::$inst->DoctrineConfig);
//init doctrine cache
}
示例13: boot
/**
* @throws \Doctrine\ORM\ORMException
*/
public function boot()
{
$this->serializer = SerializerBuilder::create()->setDebug($this->devMode)->build();
$this->entityFolder->create();
AnnotationRegistry::registerAutoloadNamespace('JMS\\Serializer\\Annotation', __DIR__ . '/../../../../vendor/jms/serializer/src');
$proxyDoctrineFolder = new Folder(sys_get_temp_dir() . '/doctrine');
$config = Setup::createAnnotationMetadataConfiguration([$this->entityFolder->absolute()], $this->isDevMode(), $proxyDoctrineFolder->absolute());
if ($this->cache !== null) {
$config->setQueryCacheImpl($this->getCache());
$config->setResultCacheImpl($this->getCache());
}
$this->entityManager = $this->createEntityManager($config);
$debugStack = new DebugStack();
$this->entityManager->getConnection()->getConfiguration()->setSQLLogger($debugStack);
if ($this->getFileCreation()->getContent() == 1) {
return;
}
if ($proxyDoctrineFolder->isFolder()) {
$proxyDoctrineFolder->removeFiles();
}
$tool = new SchemaTool($this->entityManager);
$metadatas = $this->entityManager->getMetadataFactory()->getAllMetadata();
$proxyDoctrineFolder->create();
$this->entityManager->getProxyFactory()->generateProxyClasses($metadatas, $proxyDoctrineFolder->absolute());
if ($this->cloudFoundryBoot->isInCloudFoundry()) {
$tool->updateSchema($metadatas);
} else {
$tool->createSchema($metadatas);
}
$this->getFileCreation()->setContent(1);
}
示例14: init
/**
* Executa as configurações iniciais e prepara o a entidade responsáveç
* da biblioteca escolhida para ORM.
*/
public function init()
{
$config = Config::getInstance();
$paths = [SYS_ROOT . 'App' . DS . 'Models' . DS];
$dev_mode = $config->get('database.debug');
$conn_params = $this->loadConfiguration();
$doctrine_config = Setup::createAnnotationMetadataConfiguration($paths, $dev_mode);
if ($config->get('cache.cache')) {
try {
$cache = Cache::getInstance();
if ($cache instanceof Cache) {
$doctrine_config->setResultCacheImpl($cache->getDriver());
}
} catch (\Exception $e) {
$error = new Error();
$error->log($e);
}
}
$proxy_dir = SYS_ROOT . 'App' . DS . 'Models' . DS . 'Proxies';
if (!is_dir($proxy_dir)) {
if (mkdir($proxy_dir)) {
$doctrine_config->setProxyDir($proxy_dir);
}
}
$prefix = $config->get('database.connection.table_prefix');
if ($prefix != '') {
$evm = new EventManager();
$table_prefix = new DoctrineTablePrefix($prefix);
$evm->addEventListener(Events::loadClassMetadata, $table_prefix);
$this->entityManager = EntityManager::create($conn_params, $doctrine_config, $evm);
} else {
$this->entityManager = EntityManager::create($conn_params, $doctrine_config);
}
}
示例15: 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;
}