本文整理汇总了PHP中Propel\Generator\Util\QuickBuilder::setSchema方法的典型用法代码示例。如果您正苦于以下问题:PHP QuickBuilder::setSchema方法的具体用法?PHP QuickBuilder::setSchema怎么用?PHP QuickBuilder::setSchema使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Propel\Generator\Util\QuickBuilder
的用法示例。
在下文中一共展示了QuickBuilder::setSchema方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
public function setUp()
{
if (!class_exists('\\ChildTable')) {
$schema = <<<EOF
<database name="composite_number_range_test">
<table name="parent_table">
<column name="id" required="true" primaryKey="true" autoIncrement="true" type="INTEGER" />
<column name="name" type="VARCHAR" required="false" />
</table>
<table name="child_table">
<column name="id" required="true" primaryKey="true" autoIncrement="true" type="INTEGER" />
<column name="name" type="VARCHAR" size="50" required="false" />
<behavior name="\\APinnecke\\CompositeNumberRange\\CompositeNumberRangeBehavior">
<parameter name="foreignTable" value="parent_table"/>
</behavior>
</table>
</database>
EOF;
$builder = new QuickBuilder();
$builder->setPlatform(new MysqlPlatform());
$builder->setSchema($schema);
$builder->build('mysql:host=127.0.0.1;dbname=' . getenv('DB_NAME'), getenv('DB_USER'), getenv('DB_PASS'), new MysqlAdapter());
}
$this->parent = new \ParentTable();
$this->parent->setName('test');
$this->parent->save();
$this->parent2 = new \ParentTable();
$this->parent2->setName('test2');
$this->parent2->save();
\ChildTableQuery::create()->deleteAll();
\ParentTableSequenceQuery::create()->deleteAll();
}
开发者ID:apinnecke,项目名称:composite-number-range-behavior,代码行数:32,代码来源:CompositeNumberRangeBehaviorTest.php
示例2: applyXml
/**
* @param string $xml
*
* @return Database|boolean
*/
public function applyXml($xml, $changeRequired = false)
{
$this->readDatabase();
$builder = new QuickBuilder();
$builder->setIdentifierQuoting(true);
$builder->setPlatform($this->database->getPlatform());
$builder->setSchema($xml);
$database = $builder->getDatabase();
$database->setSchema('migration');
$database->setPlatform($this->database->getPlatform());
$diff = DatabaseComparator::computeDiff($this->database, $database);
if (false === $diff) {
if ($changeRequired) {
throw new BuildException(sprintf("No changes in schema to current database: \nSchema database:\n%s\n\nCurrent Database:\n%s", $database, $this->database));
}
return false;
}
$sql = $this->database->getPlatform()->getModifyDatabaseDDL($diff);
$this->con->beginTransaction();
if (!$sql) {
throw new BuildException(sprintf('Ooops. There is a diff between current database and schema xml but no SQL has been generated. Change: %s', $diff));
}
$statements = SqlParser::parseString($sql);
foreach ($statements as $statement) {
try {
$stmt = $this->con->prepare($statement);
$stmt->execute();
} catch (\Exception $e) {
throw new BuildException(sprintf("Can not execute SQL: \n%s\nFrom database: \n%s\n\nTo database: \n%s\n", $statement, $this->database, $database), null, $e);
}
}
$this->con->commit();
return $database;
}
示例3: setUp
public function setUp()
{
if (!class_exists('\\Issue656TestObject')) {
$schema = <<<EOF
<database>
<table name="issue_656_test_object">
<column name="ID" type="INTEGER" size="10" sqlType="int(10) unsigned" primaryKey="true" required="true" autoIncrement="true"/>
<column name="Name" type="VARCHAR" size="45" required="true"/>
</table>
<table name="issue_656_test_object_from" isCrossRef="true">
<column name="From" type="INTEGER" size="10" sqlType="int(10) unsigned" primaryKey="true" required="true"/>
<column name="To" type="INTEGER" size="10" sqlType="int(10) unsigned" primaryKey="true" required="true"/>
<foreign-key name="fk_test_object_from" foreignTable="issue_656_test_object">
<reference local="From" foreign="ID"/>
</foreign-key>
<foreign-key name="fk_test_object_to" foreignTable="issue_656_test_object">
<reference local="To" foreign="ID"/>
</foreign-key>
</table>
</database>
EOF;
$builder = new QuickBuilder();
$builder->setSchema($schema);
$builder->buildClasses(null, true);
}
}
示例4: applyXml
/**
* @param string $xml
*
* @return Database
*/
public function applyXml($xml)
{
$this->readDatabase();
$builder = new QuickBuilder();
$builder->setPlatform($this->database->getPlatform());
$builder->setSchema($xml);
$database = $builder->getDatabase();
$database->setSchema('migration');
$database->setPlatform($this->database->getPlatform());
$diff = DatabaseComparator::computeDiff($this->database, $database);
if (false === $diff) {
return null;
}
$sql = $this->database->getPlatform()->getModifyDatabaseDDL($diff);
$this->con->beginTransaction();
$statements = SqlParser::parseString($sql);
foreach ($statements as $statement) {
try {
$stmt = $this->con->prepare($statement);
$stmt->execute();
} catch (\Exception $e) {
$this->con->rollBack();
throw new BuildException(sprintf("Can not execute SQL: \n%s\nFrom database: \n%s\n\nTo database: \n%s\n", $statement, $this->database, $database), null, $e);
}
}
$this->con->commit();
return $database;
}
示例5: migrate
/**
* Migrates the database.
*
* @param string $schema xml schema
*/
public function migrate($schema)
{
$builder = new QuickBuilder();
$platform = $this->getPlatform();
$builder->setPlatform($platform);
$builder->setParser($this->getParser($this->con));
$builder->getParser()->setPlatform($platform);
$builder->setSchema($schema);
$builder->updateDB($this->con);
}
示例6: setUp
public function setUp()
{
parent::setUp();
$schema = file_get_contents(__DIR__ . '/../Resources/acl_schema.xml');
if (!class_exists('Propel\\Bundle\\PropelBundle\\Model\\Acl\\Map\\AclClassTableMap')) {
$classTargets = array('tablemap', 'object', 'query');
} else {
$classTargets = array();
}
$builder = new QuickBuilder();
$builder->setSchema($schema);
$this->con = $builder->build($dsn = null, $user = null, $pass = null, $adapter = null, $classTargets);
}
示例7: setUp
public function setUp()
{
if (!class_exists('\\Base\\Issue1033Book')) {
$schema = <<<EOF
<database>
<table name="Issue1033Book">
<column name="id" required="true" primaryKey="true" autoIncrement="true" type="INTEGER" description="Book Id" />
<column name="title" type="VARCHAR" required="true" description="Book Title" primaryString="true" />
</table>
</database>
EOF;
$builder = new QuickBuilder();
$builder->setSchema($schema);
$builder->buildClasses(null, true);
}
}
示例8: setUp
public function setUp()
{
if (!class_exists('TableWithStateMachineBehavior')) {
$schema = <<<EOF
<database name="state_machine_behavior" defaultIdMethod="native">
<table name="table_with_state_machine_behavior">
<column name="id" required="true" primaryKey="true" autoIncrement="true" type="INTEGER" />
<behavior name="state_machine">
<parameter name="states" value="draft, unpublished, published" />
<parameter name="initial_state" value="draft" />
<parameter name="transition" value="draft to published with publish" />
<parameter name="transition" value="published to unpublished with unpublish" />
<parameter name="transition" value="unpublished to published with publish" />
<parameter name="state_column" value="state" />
</behavior>
</table>
<table name="table_with_state_machine_behavior_with_custom_column">
<column name="id" required="true" primaryKey="true" autoIncrement="true" type="INTEGER" />
<behavior name="state_machine">
<parameter name="states" value="draft, published, not_yEt_published, flagged" />
<parameter name="initial_state" value="draft" />
<parameter name="transition" value="draft to published with publish" />
<parameter name="transition" value="published to not_yet_published with unpublish" />
<parameter name="transition" value="not_yEt_published to published with publish" />
<parameter name="transition" value="not_yEt_published to flagged with flag_for_publish" />
<parameter name="transition" value="flagged to published with publish" />
<parameter name="state_column" value="my_state" />
</behavior>
</table>
</database>
EOF;
$builder = new QuickBuilder();
$config = $builder->getConfig();
$builder->setConfig($config);
$builder->setSchema($schema);
$builder->build();
}
}
示例9: testValidateReturnsTrueForValidSchema
public function testValidateReturnsTrueForValidSchema()
{
$schema = <<<EOF
<database name="bookstore">
<table name="book">
<column name="id" required="true" primaryKey="true" autoIncrement="true" type="INTEGER" />
<column name="title" type="VARCHAR" size="100" primaryString="true" />
</table>
</database>
EOF;
$builder = new QuickBuilder();
$builder->setSchema($schema);
$database = $builder->getDatabase();
$appData = new AppData();
$appData->addDatabase($database);
$validator = new SchemaValidator($appData);
$this->assertTrue($validator->validate());
}
示例10: dropForeignKey
/**
* Drop the foreign key in the `_user` table and check whether it generates
* the correct `DROP` SQL.
*/
private function dropForeignKey()
{
$this->readDatabase();
$updatedSchema = '
<database name="reverse-bookstore" identifierQuoting="true">
<table name="issue617_user">
<vendor type="mysql">
<parameter name="Engine" value="InnoDB"/>
<parameter name="Charset" value="utf8"/>
</vendor>
<column name="id" type="INTEGER" required="true" primaryKey="true" autoIncrement="true" />
<column name="full_name" type="VARCHAR" size="50" required="true" />
</table>
<table name="issue617_group">
<vendor type="mysql">
<parameter name="Engine" value="InnoDB"/>
<parameter name="Charset" value="utf8"/>
</vendor>
<column name="id" type="INTEGER" required="true" primaryKey="true" autoIncrement="true" />
<column name="name" type="VARCHAR" size="50" required="true" />
</table>
</database>
';
$this->updatedBuilder = new QuickBuilder();
$this->updatedBuilder->setIdentifierQuoting(true);
$this->updatedBuilder->setPlatform($this->database->getPlatform());
$this->updatedBuilder->setSchema($updatedSchema);
$diff = DatabaseComparator::computeDiff($this->database, $this->updatedBuilder->getDatabase());
$sql = $this->database->getPlatform()->getModifyDatabaseDDL($diff);
$expected = '
ALTER TABLE `issue617_user` DROP FOREIGN KEY `issue617_user_fk_5936b3`;
DROP INDEX `issue617_user_fi_5936b3` ON `issue617_user`;
ALTER TABLE `issue617_user`
DROP `group_id`;
';
$this->assertContains($expected, $sql);
$this->updateSchema($this->updatedBuilder->getDatabase());
}
示例11: setUp
public function setUp()
{
$schema = <<<SCHEMA
<database name="users" defaultIdMethod="native" namespace="Propel\\Bundle\\PropelBundle\\Tests\\Fixtures\\Model">
<table name="user">
<column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true" />
<column name="username" type="varchar" size="255" primaryString="true" />
<column name="algorithm" type="varchar" size="50" />
<column name="salt" type="varchar" size="255" />
<column name="password" type="varchar" size="255" />
<column name="expires_at" type="timestamp" />
<column name="roles" type="array" />
</table>
</database>
SCHEMA;
$builder = new QuickBuilder();
$builder->setSchema($schema);
$classTargets = array('tablemap', 'object', 'query', 'querystub');
$this->con = $builder->build($dsn = null, $user = null, $pass = null, $adapter = null, $classTargets);
}
示例12: testNamespace
public function testNamespace()
{
$schema = <<<EOF
<?xml version="1.0" encoding="utf-8"?>
<database name="default" defaultIdMethod="native" namespace="Tests\\Issue730\\">
<table name="issue730_group" idMethod="native" phpName="Group">
<column name="id" phpName="Id" type="INTEGER" primaryKey="true" required="true"/>
<column name="name" phpName="Name" type="VARCHAR" size="100" required="true"/>
</table>
<table name="issue730_department_group" idMethod="native" phpName="Group" namespace="\\Tests\\Issue730\\Department">
<column name="id" phpName="Id" type="INTEGER" primaryKey="true" autoIncrement="true" required="true"/>
<column name="name" type="VARCHAR" size="100" required="true"/>
<column name="group_id" phpName="GroupId" type="INTEGER"/>
<foreign-key foreignTable="issue730_group" phpName="Group" refPhpName="DepartmentGroup">
<reference local="group_id" foreign="id"/>
</foreign-key>
</table>
</database>
EOF;
$quickBuilder = new QuickBuilder();
$quickBuilder->setSchema($schema);
$quickBuilder->setIdentifierQuoting(true);
$platform = new SqlitePlatform();
$quickBuilder->setPlatform($platform);
$quickBuilder->build();
$groupA = new \Tests\Issue730\Group();
$groupA->setName('groupA');
$departmentGroup = new \Tests\Issue730\Department\Group();
$departmentGroup->setName('my department');
$departmentGroup->setGroup($groupA);
$this->assertEquals($groupA, $departmentGroup->getGroup());
$departmentGroups = $groupA->getDepartmentGroups();
$this->assertCount(1, $departmentGroups);
$this->assertEquals($departmentGroup, $departmentGroups->getFirst());
$groupA->save();
$departmentGroups = \Tests\Issue730\Department\GroupQuery::create()->filterByGroup($groupA)->find();
$this->assertCount(1, $departmentGroups);
$this->assertEquals($departmentGroup, $departmentGroups->getFirst());
$this->assertEquals('my department', $departmentGroups->getFirst()->getName());
}
示例13: testLoadDelegatedOnPrimaryKey
public function testLoadDelegatedOnPrimaryKey()
{
$schema = <<<XML
<database name="default" package="vendor.bundles.Propel.Bundle.PropelBundle.Tests.Fixtures.DataFixtures.Loader" namespace="Propel\\Bundle\\PropelBundle\\Tests\\Fixtures\\DataFixtures\\Loader" defaultIdMethod="native">
<table name="yaml_delegate_on_primary_key_person" phpName="YamlDelegateOnPrimaryKeyPerson">
<column name="id" type="integer" primaryKey="true" autoIncrement="true" />
<column name="name" type="varchar" size="255" />
</table>
<table name="yaml_delegate_on_primary_key_author" phpName="YamlDelegateOnPrimaryKeyAuthor">
<column name="id" type="integer" primaryKey="true" autoIncrement="false" />
<column name="count_books" type="integer" defaultValue="0" required="true" />
<behavior name="delegate">
<parameter name="to" value="yaml_delegate_on_primary_key_person" />
</behavior>
<foreign-key foreignTable="yaml_delegate_on_primary_key_person" onDelete="RESTRICT" onUpdate="CASCADE">
<reference local="id" foreign="id" />
</foreign-key>
</table>
</database>
XML;
$fixtures = <<<YAML
Propel\\Bundle\\PropelBundle\\Tests\\Fixtures\\DataFixtures\\Loader\\YamlDelegateOnPrimaryKeyPerson:
yaml_delegate_on_primary_key_person_1:
name: "Some Persons Name"
Propel\\Bundle\\PropelBundle\\Tests\\Fixtures\\DataFixtures\\Loader\\YamlDelegateOnPrimaryKeyAuthor:
yaml_delegate_on_primary_key_author_1:
id: yaml_delegate_on_primary_key_person_1
count_books: 7
YAML;
$filename = $this->getTempFile($fixtures);
$builder = new QuickBuilder();
$builder->setSchema($schema);
$con = $builder->build();
$loader = new YamlDataLoader(__DIR__ . '/../../Fixtures/DataFixtures/Loader', array());
$loader->load(array($filename), 'default');
$authors = \Propel\Bundle\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlDelegateOnPrimaryKeyAuthorQuery::create()->find($con);
$this->assertCount(1, $authors);
$author = $authors[0];
$person = $author->getYamlDelegateOnPrimaryKeyPerson();
$this->assertInstanceOf('Propel\\Bundle\\PropelBundle\\Tests\\Fixtures\\DataFixtures\\Loader\\YamlDelegateOnPrimaryKeyPerson', $person);
}
示例14: setupInitSchema
/**
* Setups the initial schema.
*/
private function setupInitSchema()
{
/*
* Create issue617 tables with foreign keys
*/
$schema = '
<database name="bookstore">
<table name="issue617_user">
<vendor type="mysql">
<parameter name="Engine" value="InnoDB"/>
<parameter name="Charset" value="utf8"/>
</vendor>
<column name="id" type="INTEGER" required="true" primaryKey="true" autoIncrement="true" />
<column name="full_name" type="VARCHAR" size="50" required="true" />
<!-- this column (and FK) will be removed from schema, but not from DB on migrate -->
<column name="group_id" type="INTEGER" />
<foreign-key foreignTable="issue617_group" onDelete="setnull">
<reference local="group_id" foreign="id" />
</foreign-key>
</table>
<table name="issue617_group">
<vendor type="mysql">
<parameter name="Engine" value="InnoDB"/>
<parameter name="Charset" value="utf8"/>
</vendor>
<column name="id" type="INTEGER" required="true" primaryKey="true" autoIncrement="true" />
<column name="name" type="VARCHAR" size="50" required="true" />
</table>
</database>
';
$builder = new QuickBuilder();
$builder->setPlatform($this->database->getPlatform());
$builder->setSchema($schema);
$diff = DatabaseComparator::computeDiff($this->database, $builder->getDatabase());
$sql = $this->database->getPlatform()->getModifyDatabaseDDL($diff);
$expected = '
CREATE TABLE `issue617_user`
(
`id` INTEGER NOT NULL AUTO_INCREMENT,
`full_name` VARCHAR(50) NOT NULL,
`group_id` INTEGER,
PRIMARY KEY (`id`),
INDEX `issue617_user_fi_5936b3` (`group_id`),
CONSTRAINT `issue617_user_fk_5936b3`
FOREIGN KEY (`group_id`)
REFERENCES `issue617_group` (`id`)
ON DELETE SET NULL
) ENGINE=InnoDB CHARACTER SET=\'utf8\';
CREATE TABLE `issue617_group`
(
`id` INTEGER NOT NULL AUTO_INCREMENT,
`name` VARCHAR(50) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB CHARACTER SET=\'utf8\';
';
$this->assertContains($expected, $sql);
$this->updateSchema($builder->getDatabase());
}
示例15: testToArrayKeyTypePreDefined
public function testToArrayKeyTypePreDefined()
{
$schema = <<<EOF
<database name="test" namespace="MyNameSpace">
<table name="test_key_type_table">
<column name="id_key_type" required="true" primaryKey="true" autoIncrement="true" type="INTEGER" />
<column name="name_key_type" type="VARCHAR" />
</table>
</database>
EOF;
$builder = new QuickBuilder();
$builder->setSchema($schema);
$builder->getConfig()->setBuildProperty('defaultKeyType', 'studlyPhpName');
$builder->buildClasses();
$expectedKeys = array('idKeyType', 'nameKeyType');
$object = new TestKeyTypeTable();
$this->assertEquals($expectedKeys, array_keys($object->toArray()), 'toArray() returns an associative array with pre-defined key type in properties.');
}