本文整理汇总了PHP中Doctrine\ORM\Tools\SchemaTool::createSchema方法的典型用法代码示例。如果您正苦于以下问题:PHP SchemaTool::createSchema方法的具体用法?PHP SchemaTool::createSchema怎么用?PHP SchemaTool::createSchema使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\Tools\SchemaTool
的用法示例。
在下文中一共展示了SchemaTool::createSchema方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: doSetUpBeforeClass
public static function doSetUpBeforeClass()
{
self::$st = new SchemaTool(self::$em);
self::$st->createSchema([self::$em->getClassMetadata(Language::clazz())]);
self::$st->createSchema([self::$em->getClassMetadata(TranslationToken::clazz())]);
self::$st->createSchema([self::$em->getClassMetadata(LanguageTranslationToken::clazz())]);
}
示例2: setUpSchema
public function setUpSchema(array $classes)
{
foreach ($classes as $k => $class) {
$classes[$k] = $this->em->getClassMetadata($class);
}
$this->dropSchemas($classes);
$this->createdSchemas = array_merge($this->createdSchemas, $classes);
$this->schemaTool->createSchema($classes);
}
示例3: setUpSchema
/**
* Create the schema!
*
* @return void
*/
public function setUpSchema(EntityManager $em)
{
$this->classes = array($em->getClassMetadata('EasyBib\\Doctrine\\Types\\Test\\Entity\\Note'));
$this->tool = new SchemaTool($em);
if (false === $this->isTravis) {
return;
}
$this->tool->createSchema($this->classes);
}
示例4: setUpBeforeClass
public static function setUpBeforeClass()
{
$em = self::getEntityManager();
$metaData = $em->getMetadataFactory()->getAllMetadata();
self::$schemaTool = new SchemaTool($em);
self::$schemaTool->dropSchema($metaData);
self::$schemaTool->createSchema($metaData);
static::prepareTestData($em);
}
示例5: createSchema
public function createSchema($table)
{
foreach (self::$classes as $meta) {
if ($table === $meta->getTableName() || ".{$table}" === substr($meta->getTableName(), -strlen(".{$table}"))) {
self::$tool->dropSchema([$meta]);
self::$tool->createSchema([$meta]);
}
}
}
示例6: setUp
protected function setUp()
{
parent::setUp();
if (!isset(static::$_sharedConn)) {
static::$_sharedConn = $this->_getDefaultConnection();
}
$this->_em = $this->_getTestEntityManager(static::$_sharedConn);
$this->_schemaTool = new \Doctrine\ORM\Tools\SchemaTool($this->_em);
$this->_schemaTool->createSchema($this->_em->getMetadataFactory()->getAllMetadata());
}
示例7: setUpBeforeClass
public static function setUpBeforeClass()
{
static::$kernel = static::createKernel();
static::$kernel->boot();
self::$em = static::$kernel->getContainer()->get('doctrine')->getManager();
self::$tool = new SchemaTool(self::$em);
self::$userClasses = [self::$em->getClassMetaData('Sulu\\Bundle\\TestBundle\\Entity\\TestContact'), self::$em->getClassMetaData('Sulu\\Bundle\\TestBundle\\Entity\\TestUser')];
self::$tool->dropSchema(self::$userClasses);
self::$tool->createSchema(self::$userClasses);
static::$kernel->getContainer()->set('sulu_security.user_repository', static::$kernel->getContainer()->get('test_user_provider'));
}
示例8: fire
/**
* Execute the console command.
*
* @return void
*/
public function fire()
{
if ($this->option('sql')) {
$this->info('Outputting create query:');
$sql = $this->tool->getCreateSchemaSql($this->metadata->getAllMetadata());
$this->info(implode(';' . PHP_EOL, $sql));
} else {
$this->info('Creating database schema...');
$this->tool->createSchema($this->metadata->getAllMetadata());
$this->info('Schema has been created!');
}
}
示例9: doSetUpBeforeClass
/**
* {@inheritdoc}
*/
public static function doSetUpBeforeClass()
{
static::$schemaTool = new SchemaTool(static::$em);
static::$schemaTool->dropSchema(static::getTablesMetadata());
static::$schemaTool->createSchema(static::getTablesMetadata());
static::$encoder = static::$container->get('security.encoder_factory');
static::$user = new User();
static::$user->setEmail('test@test.com');
static::$user->setPassword(static::$encoder->getEncoder(static::$user)->encodePassword('1234', static::$user->getSalt()));
static::$user->setUsername('testUser');
$entityPermissionCategory = new PermissionCategory();
$entityPermissionCategory->setName('backend_user');
$entityPermissionCategory->setTechnicalName('backend_user');
static::$em->persist($entityPermissionCategory);
$entityPermission = new Permission();
$entityPermission->setRoleName('IS_AUTHENTICATED_FULLY');
$entityPermission->setDescription('IS_AUTHENTICATED_FULLY');
$entityPermission->setName('IS_AUTHENTICATED_FULLY');
$entityPermission->setCategory($entityPermissionCategory);
$entityPermission2 = new Permission();
$entityPermission2->setRoleName('ROLE_MANAGE_PERMISSIONS');
$entityPermission2->setDescription('ROLE_MANAGE_PERMISSIONS');
$entityPermission2->setName('ROLE_MANAGE_PERMISSIONS');
$entityPermission2->setCategory($entityPermissionCategory);
$entityPermission3 = new Permission();
$entityPermission3->setRoleName('ROLE_ACCESS_BACKEND_TOOLS_SECURITY_SECTION');
$entityPermission3->setDescription('ROLE_ACCESS_BACKEND_TOOLS_SECURITY_SECTION');
$entityPermission3->setName('ROLE_ACCESS_BACKEND_TOOLS_SECURITY_SECTION');
$entityPermission3->setCategory($entityPermissionCategory);
$entityPermission4 = new Permission();
$entityPermission4->setRoleName('ROLE_MANAGE_USER_PROFILES');
$entityPermission4->setDescription('ROLE_MANAGE_USER_PROFILES');
$entityPermission4->setName('ROLE_MANAGE_USER_PROFILES');
$entityPermission4->setCategory($entityPermissionCategory);
static::$em->persist($entityPermission);
static::$em->persist($entityPermission2);
static::$em->persist($entityPermission3);
static::$em->persist($entityPermission4);
static::$em->flush();
$group = new Group();
$group->setRefName('BACKEND-USER');
$group->setName('backend-user');
$group->addPermission($entityPermission);
$group->addPermission($entityPermission2);
$group->addPermission($entityPermission3);
$group->addPermission($entityPermission4);
static::$user->addToGroup($group);
static::$em->persist($group);
static::$em->persist(static::$user);
static::$em->flush();
}
示例10: testCreateReturnsRestServiceEntityWithControllerServiceNamePopulated
/**
* @see https://github.com/zfcampus/zf-apigility/issues/18
*/
public function testCreateReturnsRestServiceEntityWithControllerServiceNamePopulated()
{
$serviceManager = $this->getApplication()->getServiceManager();
$em = $serviceManager->get('doctrine.entitymanager.orm_default');
$tool = new SchemaTool($em);
$res = $tool->createSchema($em->getMetadataFactory()->getAllMetadata());
// Create DB
$resourceDefinition = array("objectManager" => "doctrine.entitymanager.orm_default", "serviceName" => "Artist", "entityClass" => "Db\\Entity\\Artist", "routeIdentifierName" => "artist_id", "entityIdentifierName" => "id", "routeMatch" => "/db-test/artist");
// Verify ORM is working
$artist = new \Db\Entity\Artist();
$artist->setName('TestInsert');
$artist->setCreatedAt(new \Datetime());
$em->persist($artist);
$em->flush();
$found = $em->getRepository('Db\\Entity\\Artist')->find($artist->getId());
$this->assertInstanceOf('Db\\Entity\\Artist', $found);
$this->resource = $serviceManager->get('ZF\\Apigility\\Doctrine\\Admin\\Model\\DoctrineRestServiceResource');
$this->resource->setModuleName('DbApi');
$entity = $this->resource->create($resourceDefinition);
$this->assertInstanceOf('ZF\\Apigility\\Doctrine\\Admin\\Model\\DoctrineRestServiceEntity', $entity);
$controllerServiceName = $entity->controllerServiceName;
$this->assertNotEmpty($controllerServiceName);
$this->assertContains('DbApi\\V1\\Rest\\Artist\\Controller', $controllerServiceName);
// $serviceManager = ServiceManagerFactory::getServiceManager();
// $config = $serviceManager->get('Config');
// $routerConfig = isset($config['router']) ? $config['router'] : array();
// $router = HttpRouter::factory($routerConfig);
// $routeMatch = new RouteMatch(array('controller' => $controllerServiceName));
// $event = new MvcEvent();
// $event->setRouter($router);
// $event->setRouteMatch($routeMatch);
// $this->getRequest()->setMethod('GET');
$request = $this->getRequest();
$request->setMethod('GET');
$request->getHeaders()->addHeaders(array('Accept' => 'application/json'));
$x = $this->dispatch('/db-api/artist');
$this->resource->delete('DbApi\\V1\\Rest\\Artist\\Controller');
print_r($x);
return;
// $controller->setEvent($event);
// $controller->setServiceLocator($serviceManager);
// $routeMatch = new RouteMatch(array('controller' => $controllerServiceName));
// print_r($config);
// print_r(get_class_methods($router));
$this->resource->delete('DbApi\\V1\\Rest\\Artist\\Controller');
return;
// $controller = new $controllerServiceName;
// $request = new Request();
$query = array();
$query[] = array('type' => 'eq', 'field' => 'id', 'value' => $found->getId());
// Fetch test runs
$routeMatch->setParam('action', 'index');
$result = $controller->dispatch($this->request);
$response = $controller->getResponse();
// $this->assertEquals(200, $response->getStatusCode());
$hal = $response->getBody();
$renderer = $this->getServiceLocator()->get('ZF\\Hal\\JsonRenderer');
$data = json_decode($renderer->render($hal), true);
print_r($data);
}
示例11: setUp
public function setUp()
{
parent::setUp();
$schemaTool = new SchemaTool($this->entityManager);
$schemaTool->createSchema(array($this->entityManager->getClassMetadata('Pagerfanta\\Tests\\Adapter\\DoctrineORM\\User'), $this->entityManager->getClassMetadata('Pagerfanta\\Tests\\Adapter\\DoctrineORM\\Group'), $this->entityManager->getClassMetadata('Pagerfanta\\Tests\\Adapter\\DoctrineORM\\Person')));
$this->user1 = $user = new User();
$this->user2 = $user2 = new User();
$group1 = new Group();
$group2 = new Group();
$group3 = new Group();
$user->groups[] = $group1;
$user->groups[] = $group2;
$user->groups[] = $group3;
$user2->groups[] = $group1;
$author1 = new Person();
$author1->name = 'Foo';
$author1->biography = 'Baz bar';
$author2 = new Person();
$author2->name = 'Bar';
$author2->biography = 'Bar baz';
$this->entityManager->persist($user);
$this->entityManager->persist($user2);
$this->entityManager->persist($group1);
$this->entityManager->persist($group2);
$this->entityManager->persist($group3);
$this->entityManager->persist($author1);
$this->entityManager->persist($author2);
$this->entityManager->flush();
}
示例12: testDoctrineService
public function testDoctrineService()
{
$serviceManager = $this->getApplication()->getServiceManager();
$em = $serviceManager->get('doctrine.entitymanager.orm_default');
$tool = new SchemaTool($em);
$res = $tool->createSchema($em->getMetadataFactory()->getAllMetadata());
// Create DB
$resourceDefinition = array("objectManager" => "doctrine.entitymanager.orm_default", "serviceName" => "Artist", "entityClass" => "Db\\Entity\\Artist", "routeIdentifierName" => "artist_id", "entityIdentifierName" => "id", "routeMatch" => "/db-test/artist");
$this->resource = $serviceManager->get('ZF\\Apigility\\Doctrine\\Admin\\Model\\DoctrineRestServiceResource');
$this->resource->setModuleName('DbApi');
$entity = $this->resource->create($resourceDefinition);
$this->assertInstanceOf('ZF\\Apigility\\Doctrine\\Admin\\Model\\DoctrineRestServiceEntity', $entity);
$controllerServiceName = $entity->controllerServiceName;
$this->assertNotEmpty($controllerServiceName);
$this->assertContains('DbApi\\V1\\Rest\\Artist\\Controller', $controllerServiceName);
$filter = new FilterChain();
$filter->attachByName('WordCamelCaseToUnderscore')->attachByName('StringToLower');
$em = $serviceManager->get('doctrine.entitymanager.orm_default');
$metadataFactory = $em->getMetadataFactory();
$entityMetadata = $metadataFactory->getMetadataFor("Db\\Entity\\Artist");
foreach ($entityMetadata->associationMappings as $mapping) {
switch ($mapping['type']) {
case 4:
$rpcServiceResource = $serviceManager->get('ZF\\Apigility\\Doctrine\\Admin\\Model\\DoctrineRpcServiceResource');
$rpcServiceResource->setModuleName('DbApi');
$rpcServiceResource->create(array('service_name' => 'Artist' . $mapping['fieldName'], 'route' => '/db-test/artist[/:parent_id]/' . $filter($mapping['fieldName']) . '[/:child_id]', 'http_methods' => array('GET', 'PUT', 'POST'), 'options' => array('target_entity' => $mapping['targetEntity'], 'source_entity' => $mapping['sourceEntity'], 'field_name' => $mapping['fieldName']), 'selector' => 'custom selector'));
break;
default:
break;
}
}
}
示例13: dropAndCreateSchema
private function dropAndCreateSchema()
{
$schemaTool = new SchemaTool($this->getEntityManager());
$metadata = $this->getEntityManager()->getMetadataFactory()->getAllMetadata();
$schemaTool->dropSchema($metadata);
$schemaTool->createSchema($metadata);
}
示例14: 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;
}
示例15: adminRefreshDatabaseAction
public function adminRefreshDatabaseAction(Request $request, Application $app)
{
$conn = $app['db'];
$em = $app['doctrine.orm.entity_manager'];
$params = $conn->getParams();
$name = isset($params['path']) ? $params['path'] : (isset($params['dbname']) ? $params['dbname'] : false);
try {
$conn->getSchemaManager()->dropDatabase($name);
$conn->getSchemaManager()->createDatabase($name);
$conn->close();
} catch (\Exception $e) {
return 1;
}
$classes = [];
foreach ($app['authbucket_oauth2.model'] as $class) {
$classes[] = $em->getClassMetadata($class);
}
PersistentObject::setObjectManager($em);
$tool = new SchemaTool($em);
$tool->dropSchema($classes);
$tool->createSchema($classes);
$purger = new ORMPurger();
$executor = new ORMExecutor($em, $purger);
$loader = new Loader();
$loader->loadFromDirectory(__DIR__ . '/../DataFixtures/ORM');
$executor->execute($loader->getFixtures());
return $app->redirect($app['url_generator']->generate('index'));
}