本文整理汇总了PHP中Doctrine\ORM\Configuration::addEntityNamespace方法的典型用法代码示例。如果您正苦于以下问题:PHP Configuration::addEntityNamespace方法的具体用法?PHP Configuration::addEntityNamespace怎么用?PHP Configuration::addEntityNamespace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\Configuration
的用法示例。
在下文中一共展示了Configuration::addEntityNamespace方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testSetGetEntityNamespace
public function testSetGetEntityNamespace()
{
$this->configuration->addEntityNamespace('TestNamespace', __NAMESPACE__);
$this->assertSame(__NAMESPACE__, $this->configuration->getEntityNamespace('TestNamespace'));
$namespaces = array('OtherNamespace' => __NAMESPACE__);
$this->configuration->setEntityNamespaces($namespaces);
$this->assertSame($namespaces, $this->configuration->getEntityNamespaces());
$this->setExpectedException('Doctrine\\ORM\\ORMException');
$this->configuration->getEntityNamespace('NonExistingNamespace');
}
示例2: prepareMocks
/**
* @return array
*/
protected function prepareMocks()
{
$configuration = new Configuration();
$configuration->addEntityNamespace('Stub', 'Oro\\Bundle\\BatchBundle\\Tests\\Unit\\ORM\\Query\\Stub');
$classMetadata = new ClassMetadata('Entity');
$classMetadata->mapField(['fieldName' => 'a', 'columnName' => 'a']);
$classMetadata->mapField(['fieldName' => 'b', 'columnName' => 'b']);
$classMetadata->setIdentifier(['a']);
$platform = $this->getMockBuilder('Doctrine\\DBAL\\Platforms\\AbstractPlatform')->setMethods([])->disableOriginalConstructor()->getMockForAbstractClass();
$statement = $this->getMockBuilder('Doctrine\\DBAL\\Statement')->setMethods(['fetch', 'fetchColumn', 'closeCursor'])->disableOriginalConstructor()->getMock();
$driverConnection = $this->getMockBuilder('Doctrine\\DBAL\\Driver\\Connection')->setMethods(['query'])->disableOriginalConstructor()->getMockForAbstractClass();
$driverConnection->expects($this->any())->method('query')->will($this->returnValue($statement));
$driver = $this->getMockBuilder('Doctrine\\DBAL\\Driver')->setMethods(['connect', 'getDatabasePlatform'])->disableOriginalConstructor()->getMockForAbstractClass();
$driver->expects($this->any())->method('connect')->will($this->returnValue($driverConnection));
$driver->expects($this->any())->method('getDatabasePlatform')->will($this->returnValue($platform));
$connection = $this->getMockBuilder('Doctrine\\DBAL\\Connection')->setMethods(['getDatabasePlatform', 'executeQuery'])->setConstructorArgs([[], $driver])->getMock();
$connection->expects($this->any())->method('getDatabasePlatform')->will($this->returnValue($platform));
/** @var UnitOfWork $unitOfWork */
$unitOfWork = $this->getMockBuilder('UnitOfWork')->setMethods(['getEntityPersister'])->disableOriginalConstructor()->getMock();
$entityManager = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->setMethods(['getConfiguration', 'getClassMetadata', 'getConnection', 'getUnitOfWork'])->disableOriginalConstructor()->getMock();
$entityManager->expects($this->any())->method('getConfiguration')->will($this->returnValue($configuration));
$entityManager->expects($this->any())->method('getClassMetadata')->will($this->returnValue($classMetadata));
$entityManager->expects($this->any())->method('getConnection')->will($this->returnValue($connection));
$entityManager->expects($this->any())->method('getUnitOfWork')->will($this->returnValue($unitOfWork));
return [$entityManager, $connection, $statement];
}
示例3: setUp
protected function setUp()
{
if (!class_exists('\\Doctrine\\ORM\\Configuration')) {
$this->markTestSkipped('Doctrine is not available');
}
$config = new Configuration();
$config->setMetadataCacheImpl(new ArrayCache());
$config->setQueryCacheImpl(new ArrayCache());
$config->setProxyDir(__DIR__ . '/Proxies');
$config->setProxyNamespace('Boldtrn\\JsonbBundle\\Tests\\Proxies');
$config->setAutoGenerateProxyClasses(true);
$config->setMetadataDriverImpl($config->newDefaultAnnotationDriver(__DIR__ . '/Entities'));
$config->addEntityNamespace('E', 'Boldtrn\\JsonbBundle\\Tests\\Entities');
$config->setCustomStringFunctions(array('JSONB_AG' => 'Boldtrn\\JsonbBundle\\Query\\JsonbAtGreater', 'JSONB_HGG' => 'Boldtrn\\JsonbBundle\\Query\\JsonbHashGreaterGreater', 'JSONB_EX' => 'Boldtrn\\JsonbBundle\\Query\\JsonbExistence'));
$dbParams = array('driver' => 'pdo_pgsql', 'host' => 'localhost', 'port' => '5432', 'dbname' => 'jsonb_test', 'user' => 'postgres', 'password' => 'secret');
$this->entityManager = \Doctrine\ORM\EntityManager::create($dbParams, $config);
}
示例4: setUp
protected function setUp()
{
if (!class_exists('\\Doctrine\\ORM\\Configuration')) {
static::markTestSkipped('Doctrine is not available');
}
$config = new Configuration();
$config->setMetadataCacheImpl(new ArrayCache());
$config->setQueryCacheImpl(new ArrayCache());
$config->setProxyDir(__DIR__ . '/Proxies');
$config->setProxyNamespace('Boldtrn\\JsonbBundle\\Tests\\Proxies');
$config->setAutoGenerateProxyClasses(true);
$config->setMetadataDriverImpl($config->newDefaultAnnotationDriver(__DIR__ . '/Entities'));
$config->addEntityNamespace('E', 'Boldtrn\\JsonbBundle\\Tests\\Entities');
$config->setCustomStringFunctions(array('JSONB_AG' => 'Boldtrn\\JsonbBundle\\Query\\JsonbAtGreater', 'JSONB_HGG' => 'Boldtrn\\JsonbBundle\\Query\\JsonbHashGreaterGreater', 'JSONB_EX' => 'Boldtrn\\JsonbBundle\\Query\\JsonbExistence'));
$this->entityManager = EntityManager::create($this->dbParams, $config);
$this->connection = $this->entityManager->getConnection();
$this->setUpDBALTypes();
$tool = new SchemaTool($this->entityManager);
$classes = $this->entityManager->getMetaDataFactory()->getAllMetaData();
// Drop all classes and re-build them for each test case
$tool->dropSchema($classes);
$tool->createSchema($classes);
}
示例5: setUp
public function setUp()
{
parent::setUp();
//if (!in_array('sqlite', \PDO::getAvailableDrivers())) {
if (!extension_loaded('pdo_sqlite')) {
$this->markTestSkipped('This test requires the PHP extension "pdo_sqlite".');
}
// this is the same as AnnotationRegistry::registerFile()
require_once VENDOR_PATH . 'doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php';
// setup Annotation Driver
$driver = new AnnotationDriver(new AnnotationReader(), [__DIR__ . '/../../../tests/KochTest/Fixtures/Doctrine/Entity']);
$config = new Configuration();
$config->setMetadataDriverImpl($driver);
$config->addEntityNamespace('KochTest', 'KochTest\\Fixtures\\Doctrine\\Entity');
$config->setQueryCacheImpl(new ArrayCache());
$config->setProxyDir(__DIR__ . '/../../../tests/KochTest/Fixtures/Doctrine/Entity');
$config->setProxyNamespace('/KochTest/Fixtures/Doctrine/Entity');
$connectionParams = ['driver' => 'pdo_sqlite', 'memory' => true];
$em = EntityManager::create($connectionParams, $config);
$tool = new SchemaTool($em);
$tool->createSchema($em->getMetadataFactory()->getAllMetadata());
$this->entityManager = $em;
}
示例6: createEm
private static function createEm(Connection $conn)
{
$config = new Configuration();
$config->setProxyDir($proxyDir = sys_get_temp_dir() . '/PhpAnalyzerProxies/' . uniqid('em', true));
if (!is_dir($proxyDir) && false === @mkdir($proxyDir, 0777, true)) {
throw new \RuntimeException(sprintf('Could not create proxy directory "%s" for test entity manager.', $proxyDir));
}
$config->setProxyNamespace('Scrutinizer\\PhpAnalyzer\\Model\\Proxies');
if (false === Type::hasType(PhpTypeType::NAME)) {
Type::addType(PhpTypeType::NAME, 'Scrutinizer\\PhpAnalyzer\\Model\\Type\\PhpTypeType');
}
if (false === Type::hasType('string_case')) {
Type::addType('string_case', 'Scrutinizer\\PhpAnalyzer\\Model\\Type\\CaseSensitiveStringType');
}
if (false === Type::hasType('string_nocase')) {
Type::addType('string_nocase', 'Scrutinizer\\PhpAnalyzer\\Model\\Type\\CaseInsensitiveStringType');
}
$driver = new AnnotationDriver(new AnnotationReader(), array(__DIR__ . '/../Model'));
$config->setMetadataDriverImpl($driver);
$config->addEntityNamespace('PhpAnalyzer', 'Scrutinizer\\PhpAnalyzer\\Model');
$em = EntityManager::create($conn, $config);
$em->getEventManager()->addEventListener(array('prePersist'), new TestUuidListener());
return $em;
}
示例7: register
public function register(Application $app)
{
$app['EM.sql-logger.file'] = $app->share(function (Application $app) {
return $app['log.path'] . '/doctrine-log.log';
});
$app['EM.sql-logger.max-files'] = 5;
$app['EM.sql-logger'] = $app->share(function (Application $app) {
$logger = new $app['monolog.logger.class']('doctrine-logger');
$logger->pushHandler(new RotatingFileHandler($app['EM.sql-logger.file'], $app['EM.sql-logger.max-files']));
return new MonologSQLLogger($logger, 'yaml');
});
$app['EM.driver'] = $app->share(function (Application $app) {
AnnotationRegistry::registerFile($app['root.path'] . '/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php');
$annotationReader = new AnnotationReader();
$fileCacheReader = new FileCacheReader($annotationReader, $app['cache.path'] . '/doctrine', $app['debug']);
$driverChain = new MappingDriverChain();
DoctrineExtensions::registerAbstractMappingIntoDriverChainORM($driverChain, $fileCacheReader);
$annotationDriver = new AnnotationDriver($annotationReader, [$app['root.path'] . '/lib/Alchemy/Phrasea/Model/Entities']);
$driverChain->addDriver($annotationDriver, 'Alchemy\\Phrasea\\Model\\Entities');
return $driverChain;
});
$app['EM.config'] = $app->share(function (Application $app) {
$config = new ORMConfiguration();
if ($app->getEnvironment() === PhraseaApplication::ENV_DEV) {
$config->setSQLLogger($app['EM.sql-logger']);
}
$config->setMetadataCacheImpl($app['phraseanet.cache-service']->factory('ORMmetadata', $app['EM.opcode-cache-type'], $app['EM.opcode-cache-options']));
$config->setQueryCacheImpl($app['phraseanet.cache-service']->factory('ORMquery', $app['EM.opcode-cache-type'], $app['EM.opcode-cache-options']));
$config->setResultCacheImpl($app['phraseanet.cache-service']->factory('ORMresult', $app['EM.cache-type'], $app['EM.cache-options']));
$config->setAutoGenerateProxyClasses($app['debug']);
$config->setMetadataDriverImpl($app['EM.driver']);
$config->setProxyDir($app['root.path'] . '/resources/proxies');
$config->setProxyNamespace('Alchemy\\Phrasea\\Model\\Proxies');
$config->setAutoGenerateProxyClasses($app['debug']);
$config->addEntityNamespace('Phraseanet', 'Alchemy\\Phrasea\\Model\\Entities');
return $config;
});
$app['EM.opcode-cache-type'] = $app->share(function (Application $app) {
if ($app['configuration.store']->isSetup()) {
return $app['conf']->get(['main', 'opcodecache', 'type']);
}
return 'ArrayCache';
});
$app['EM.opcode-cache-options'] = $app->share(function (Application $app) {
if ($app['configuration.store']->isSetup()) {
return $app['conf']->get(['main', 'opcodecache', 'options']);
}
return [];
});
$app['EM.cache-type'] = $app->share(function (Application $app) {
if ($app['configuration.store']->isSetup()) {
return $app['conf']->get(['main', 'cache', 'type']);
}
return 'ArrayCache';
});
$app['EM.cache-options'] = $app->share(function (Application $app) {
if ($app['configuration.store']->isSetup()) {
return $app['conf']->get(['main', 'cache', 'options']);
}
return [];
});
$app['EM.events-manager'] = $app->share(function (Application $app) {
$evm = new EventManager();
$evm->addEventSubscriber(new TimestampableListener());
return $evm;
});
$app['EM.dbal-conf'] = $app->share(function (Application $app) {
if ('test' === $app->getEnvironment()) {
return $app['conf']->get(['main', 'database-test']);
}
return $app['conf']->get(['main', 'database']);
});
$app['dbal.provider'] = $app->share(function (Application $app) {
return new ConnectionProvider($app['EM.config'], $app['EM.events-manager'], isset($app['task-manager.logger']) ? $app['task-manager.logger'] : $app['monolog']);
});
$app['EM'] = $app->share(function (Application $app) {
try {
$em = EntityManager::create($app['EM.dbal-conf'], $app['EM.config'], $app['EM.events-manager']);
} catch (\Exception $e) {
throw new RuntimeException("Unable to create database connection", $e->getCode(), $e);
}
$platform = $em->getConnection()->getDatabasePlatform();
$types = ['blob' => 'Alchemy\\Phrasea\\Model\\Types\\Blob', 'enum' => 'Alchemy\\Phrasea\\Model\\Types\\Blob', 'longblob' => 'Alchemy\\Phrasea\\Model\\Types\\LongBlob', 'varbinary' => 'Alchemy\\Phrasea\\Model\\Types\\VarBinary', 'binary' => 'Alchemy\\Phrasea\\Model\\Types\\Binary', 'binary_string' => 'Alchemy\\Phrasea\\Model\\Types\\BinaryString'];
foreach ($types as $type => $class) {
if (!Type::hasType($type)) {
Type::addType($type, $class);
}
$platform->registerDoctrineTypeMapping($type, $type);
}
return $em;
});
$app['EM.native-query'] = $app->share(function ($app) {
return new NativeQueryProvider($app['EM']);
});
}
示例8: setupMetaInformationFactory
/**
* @return MetaInformationFactory
*/
private function setupMetaInformationFactory()
{
$ormConfiguration = new Configuration();
$ormConfiguration->addEntityNamespace('FSTest:ValidTestEntity', 'FS\\SolrBundle\\Tests\\Doctrine\\Mapper');
$ormConfiguration->addEntityNamespace('FSTest:EntityCore0', 'FS\\SolrBundle\\Tests\\Doctrine\\Mapper');
$ormConfiguration->addEntityNamespace('FSTest:EntityCore1', 'FS\\SolrBundle\\Tests\\Doctrine\\Mapper');
$knowNamespaces = new KnownNamespaceAliases();
$knowNamespaces->addEntityNamespaces($ormConfiguration);
$classnameResolver = new ClassnameResolver($knowNamespaces);
$reader = new AnnotationReader(new \Doctrine\Common\Annotations\AnnotationReader());
$metaFactory = new MetaInformationFactory($reader);
$metaFactory->setClassnameResolver($classnameResolver);
return $metaFactory;
}
示例9: setCustomMappingDriverChain
/**
* @param array $settings
* @param Configuration $configuration
*/
protected function setCustomMappingDriverChain(array $settings = [], Configuration $configuration)
{
$chain = new MappingDriverChain($configuration->getMetadataDriverImpl(), 'LaravelDoctrine');
foreach (array_get($settings, 'namespaces', []) as $alias => $namespace) {
if (is_string($alias)) {
$configuration->addEntityNamespace($alias, $namespace);
}
$chain->addNamespace($namespace);
}
$configuration->setMetadataDriverImpl($chain);
}
示例10: array
}
$cnf = PROJECT_DIRECTORY . '/config/namespaces.yml';
$temp = $yaml->parse(file_get_contents($cnf));
$namespaces = array();
if ($temp === null) {
throw new \Exception("Your namspaces config file " . $cnf . " is not properly configured.");
}
foreach ($temp as $namespace => $data) {
$namespaces[PROJECT_DIRECTORY . '/' . $data["path"]] = $namespace;
}
$temp = $yaml->parse(file_get_contents(PROJECT_DIRECTORY . '/app/config/parameters.yml'));
$cnf = $temp["parameters"];
$connectionOptions = array('driver' => $cnf["database_driver"], 'host' => $cnf["database_host"], 'password' => $cnf["database_password"], 'dbname' => $cnf["database_name"], 'user' => $cnf["database_user"], 'port' => $cnf["database_port"]);
$config = new Configuration();
$config->setMetadataDriverImpl(new SimplifiedYamlDriver($namespaces));
$config->setAutoGenerateProxyClasses(true);
$config->setProxyDir(PROJECT_DIRECTORY . '/config/doctrine/orm/Proxies');
$config->setProxyNamespace('Proxies');
foreach ($namespaces as $key => $namespace) {
$alias = $namespace;
$alias = preg_replace('/\\W/', '', $alias);
$alias = preg_replace('/Entity$/', '', $alias);
$config->addEntityNamespace($alias, $namespace);
}
$em = EntityManager::create($connectionOptions, $config);
if (array_key_exists('mapping_types', $dbcnf)) {
foreach ($dbcnf['mapping_types'] as $key => $value) {
$em->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping($key, $value);
}
}
$helperSet = new \Symfony\Component\Console\Helper\HelperSet(array('db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($em->getConnection()), 'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($em)));
示例11: register
public function register(Container $c)
{
parent::register($c);
$c['orm.options'] = array();
$c['orm.types'] = array();
$c['orm.proxies_dir'] = sys_get_temp_dir();
$c['orm.proxies_namespace'] = 'DoctrineProxy';
$c['orm.auto_generate_proxies'] = $c->factory(function ($c) {
return $c['debug'];
});
$c['orm.custom.functions.string'] = array();
$c['orm.custom.functions.numeric'] = array();
$c['orm.custom.functions.datetime'] = array();
$c['orm.custom.hydration_modes'] = array();
$c['orm.class_metadata_factory_name'] = 'Doctrine\\ORM\\Mapping\\ClassMetadataFactory';
$c['orm.default_repository_class'] = 'Doctrine\\ORM\\EntityRepository';
$c['orm.initialize'] = $c->protect(function () use($c) {
static $initialized = false;
if ($initialized) {
return;
}
$initialized = true;
if (!isset($c['orm.options'])) {
$c['orm.options'] = array('default' => array());
} elseif (!is_array(reset($c['orm.options']))) {
// Se o primeiro elemento do array de opções não for um array,
// muito provavelmente o usuário está colocando as options de
// uma única conexão, então usar como default
$c['orm.options'] = array('default' => $c['orm.options']);
}
$tmp = $c['orm.options'];
foreach ($tmp as $name => &$options) {
if (!isset($options['connection'])) {
throw new \LogicException("Missing 'connection' param in Doctrine ORM in {$name}.");
}
if (is_string($options['connection'])) {
$options['connection'] = $c['dbal.options'][$options['connection']];
} elseif (!is_array($options['connection']) && !$options['connection'] instanceof Connection) {
throw new \LogicException("Param 'connection' in {$name} must be a string, array or a Connection instance.");
}
}
$c['orm.options'] = $tmp;
$c['orm.defaultName'] = key($c['orm.options']);
});
$c['orm.ems'] = function ($c) {
$c['orm.initialize']();
$ems = new Container();
foreach ($c['orm.options'] as $name => $options) {
$config = $c['orm.configs'][$name];
$connection = $options['connection'];
$ems[$name] = function ($ems) use($connection, $config) {
return EntityManager::create($connection, $config);
};
}
return $ems;
};
$c['orm.configs'] = function ($c) {
$c['orm.initialize']();
$configs = new Container();
foreach ($c['orm.options'] as $name => $options) {
$configs[$name] = $config = new Configuration();
$config->setProxyDir($c['orm.proxies_dir']);
$config->setProxyNamespace($c['orm.proxies_namespace']);
$config->setAutoGenerateProxyClasses($c['orm.auto_generate_proxies']);
$config->setCustomStringFunctions($c['orm.custom.functions.string']);
$config->setCustomNumericFunctions($c['orm.custom.functions.numeric']);
$config->setCustomDatetimeFunctions($c['orm.custom.functions.datetime']);
$config->setCustomHydrationModes($c['orm.custom.hydration_modes']);
$config->setClassMetadataFactoryName($c['orm.class_metadata_factory_name']);
$config->setDefaultRepositoryClassName($c['orm.default_repository_class']);
$config->setEntityListenerResolver($c['orm.entity_listener_resolver']);
$config->setRepositoryFactory($c['orm.repository_factory']);
$config->setNamingStrategy($c['orm.strategy.naming']);
$config->setQuoteStrategy($c['orm.strategy.quote']);
$chain = new MappingDriverChain();
$config->setMetadataDriverImpl($chain);
foreach ((array) $options['mappings'] as $entity) {
if (!is_array($entity)) {
throw new \InvalidArgumentException("The 'orm.options' option 'mappings' should be an array of arrays.");
}
if (isset($entity['alias'])) {
$config->addEntityNamespace($entity['alias'], $entity['namespace']);
}
switch ($entity['type']) {
case 'annotation':
if (isset($c['annotation.reader'])) {
$driver = new AnnotationDriver($c['annotation.reader'], (array) $entity['path']);
} else {
$simple = isset($entity['use_simple_annotation_reader']) ? $entity['use_simple_annotation_reader'] : true;
$driver = $config->newDefaultAnnotationDriver((array) $entity['path'], $simple);
}
break;
case 'yml':
$driver = new YamlDriver($entity['path']);
break;
case 'simple_yml':
$driver = new SimplifiedYamlDriver(array($entity['path'] => $entity['namespace']));
break;
case 'xml':
$driver = new XmlDriver($entity['path']);
//.........这里部分代码省略.........