本文整理汇总了PHP中Propel\Generator\Model\Table::setDatabase方法的典型用法代码示例。如果您正苦于以下问题:PHP Table::setDatabase方法的具体用法?PHP Table::setDatabase怎么用?PHP Table::setDatabase使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Propel\Generator\Model\Table
的用法示例。
在下文中一共展示了Table::setDatabase方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _before
/**
* @return void
*/
protected function _before()
{
$config = new QuickGeneratorConfig();
$table = new Table('Foo');
$column = new Column('testColumn', PropelTypes::INTEGER);
$table->addColumn($column);
$table->setNamespace('Unit\\Spryker\\Zed\\Propel\\Business\\Builder\\QueryBuilder');
$table->setDatabase(new Database('TestDB', new DefaultPlatform()));
foreach ($this->getFilesToGenerate() as $fileName => $builderClass) {
$builder = new $builderClass($table);
$builder->setGeneratorConfig($config);
$this->writePropelFile($builder, $fileName);
}
}
示例2: addTable
/**
* Adds a new table to this database.
*
* @param Table|array $table
* @return Table
*/
public function addTable($table)
{
if (!$table instanceof Table) {
$tbl = new Table();
$tbl->setDatabase($this);
$tbl->setSchema($this->getSchema());
$tbl->loadMapping($table);
return $this->addTable($tbl);
}
$table->setDatabase($this);
if (isset($this->tablesByName[$table->getName()])) {
throw new EngineException(sprintf('Table "%s" declared twice', $table->getName()));
}
if (null === $table->getSchema()) {
$table->setSchema($this->getSchema());
}
$this->tables[] = $table;
$this->tablesByName[$table->getName()] = $table;
$this->tablesByLowercaseName[strtolower($table->getName())] = $table;
$this->tablesByPhpName[$table->getPhpName()] = $table;
$this->computeTableNamespace($table);
if (null === $table->getPackage()) {
$table->setPackage($this->getPackage());
}
return $table;
}
示例3: testGetBaseClassesFromDatabase
public function testGetBaseClassesFromDatabase()
{
$database = $this->getDatabaseMock('bookstore');
$database->expects($this->once())->method('getBaseClass')->will($this->returnValue('BaseObject'));
$table = new Table();
$table->setDatabase($database);
$this->assertSame('BaseObject', $table->getBaseClass());
}
示例4: testAppendXmlNamespaceWithAutoPackage
public function testAppendXmlNamespaceWithAutoPackage()
{
$schema = <<<EOF
<?xml version="1.0"?>
<table name="test" namespace="\\testNs"/>
EOF;
$doc = new DOMDocument('1.0');
$doc->formatOutput = true;
$config = new GeneratorConfig();
$config->setBuildProperties(array('propel.namespace.autoPackage' => 'true'));
$appData = new AppData();
$appData->setGeneratorConfig($config);
$db = new Database('testDb');
$db->setAppData($appData);
$table = new Table('test');
$table->setDatabase($db);
$table->setNamespace('\\testNs');
$table->appendXml($doc);
$xmlstr = trim($doc->saveXML());
$this->assertSame($schema, $xmlstr);
$schema = <<<EOF
<?xml version="1.0"?>
<table name="test" namespace="\\testNs" package="testPkg"/>
EOF;
$doc = new DOMDocument('1.0');
$doc->formatOutput = true;
$table->setPackage('testPkg');
$table->appendXml($doc);
$xmlstr = trim($doc->saveXML());
$this->assertSame($schema, $xmlstr);
}
示例5: testReverseDiffHasModifiedIndices
public function testReverseDiffHasModifiedIndices()
{
$table = new Table();
$table->setDatabase(new Database('foo', new DefaultPlatform()));
$fromIndex = new Index('i1');
$fromIndex->setTable($table);
$toIndex = new Index('i1');
$toIndex->setTable($table);
$diff = $this->createTableDiff();
$diff->addModifiedIndex('i1', $fromIndex, $toIndex);
$reverseDiff = $diff->getReverseDiff();
$this->assertTrue($reverseDiff->hasModifiedIndices());
$this->assertSame(['i1' => [$toIndex, $fromIndex]], $reverseDiff->getModifiedIndices());
}
示例6: addTable
/**
* An utility method to add a new table from an xml attribute.
*/
public function addTable($data)
{
if ($data instanceof Table) {
$tbl = $data;
// alias
if (isset($this->tablesByName[$tbl->getName()])) {
throw new EngineException(sprintf('Table "%s" declared twice', $tbl->getName()));
}
$tbl->setDatabase($this);
if ($tbl->getSchema() === null) {
$tbl->setSchema($this->getSchema());
}
$this->tableList[] = $tbl;
$this->tablesByName[$tbl->getName()] = $tbl;
$this->tablesByLowercaseName[strtolower($tbl->getName())] = $tbl;
$this->tablesByPhpName[$tbl->getPhpName()] = $tbl;
if (strpos($tbl->getNamespace(), '\\') === 0) {
$tbl->setNamespace(substr($tbl->getNamespace(), 1));
} elseif ($namespace = $this->getNamespace()) {
if ($tbl->getNamespace() === null) {
$tbl->setNamespace($namespace);
} else {
$tbl->setNamespace($namespace . '\\' . $tbl->getNamespace());
}
}
if ($tbl->getPackage() === null) {
$tbl->setPackage($this->getPackage());
}
return $tbl;
} else {
$tbl = new Table();
$tbl->setDatabase($this);
$tbl->setSchema($this->getSchema());
$tbl->loadFromXML($data);
return $this->addTable($tbl);
// call self w/ different param
}
}
示例7: parseTables
protected function parseTables(&$tableWraps, Database $database, Table $filterTable = null)
{
$stmt = null;
$params = [];
$sql = "\n SELECT c.oid, c.relname, n.nspname\n FROM pg_class c join pg_namespace n on (c.relnamespace=n.oid)\n WHERE c.relkind = 'r'\n AND n.nspname NOT IN ('information_schema','pg_catalog')\n AND n.nspname NOT LIKE 'pg_temp%'\n AND n.nspname NOT LIKE 'pg_toast%'";
if ($filterTable) {
if ($schema = $filterTable->getSchema()) {
$sql .= ' AND n.nspname = ?';
$params[] = $schema;
}
$sql .= ' AND c.relname = ?';
$params[] = $filterTable->getCommonName();
} else {
if (!$database->getSchema()) {
$stmt = $this->dbh->query('SELECT schema_name FROM information_schema.schemata');
$searchPath = [];
while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
$searchPath[] = $row['schema_name'];
}
foreach ($searchPath as &$path) {
$params[] = $path;
$path = '?';
}
$searchPath = implode(', ', $searchPath);
$sql .= "\n AND n.nspname IN ({$searchPath})";
} elseif ($database->getSchema()) {
$sql .= "\n AND n.nspname = ?";
$params[] = $database->getSchema();
}
}
$sql .= "\n ORDER BY relname";
$stmt = $this->dbh->prepare($sql);
$stmt->execute($params);
// First load the tables (important that this happen before filling out details of tables)
while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
$name = $row['relname'];
$namespaceName = $row['nspname'];
if ($name == $this->getMigrationTable()) {
continue;
}
$oid = $row['oid'];
$table = new Table($name);
if ('public' !== $namespaceName) {
$table->setSchema($namespaceName);
}
$table->setIdMethod($database->getDefaultIdMethod());
$table->setDatabase($database);
if (!$database->hasTable($table->getName())) {
$database->addTable($table);
// Create a wrapper to hold these tables and their associated OID
$wrap = new \stdClass();
$wrap->table = $table;
$wrap->oid = $oid;
$tableWraps[] = $wrap;
}
}
}