/** * XML Handler * * @param string $db database name * @param string $table table name * @param string $crlf line separator * * @return string containing XML code lines, separated by "\n" */ private function _handleNHibernateXMLBody($db, $table, $crlf) { $lines = array(); $lines[] = '<?xml version="1.0" encoding="utf-8" ?' . '>'; $lines[] = '<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" ' . 'namespace="' . ExportCodegen::cgMakeIdentifier($db) . '" ' . 'assembly="' . ExportCodegen::cgMakeIdentifier($db) . '">'; $lines[] = ' <class ' . 'name="' . ExportCodegen::cgMakeIdentifier($table) . '" ' . 'table="' . ExportCodegen::cgMakeIdentifier($table) . '">'; $result = $GLOBALS['dbi']->query(sprintf("DESC %s.%s", PMA_Util::backquote($db), PMA_Util::backquote($table))); if ($result) { while ($row = $GLOBALS['dbi']->fetchRow($result)) { $tableProperty = new TableProperty($row); if ($tableProperty->isPK()) { $lines[] = $tableProperty->formatXml(' <id name="#ucfirstName#" type="#dotNetObjectType#"' . ' unsaved-value="0">' . "\n" . ' <column name="#name#" sql-type="#type#"' . ' not-null="#notNull#" unique="#unique#"' . ' index="PRIMARY"/>' . "\n" . ' <generator class="native" />' . "\n" . ' </id>'); } else { $lines[] = $tableProperty->formatXml(' <property name="#ucfirstName#"' . ' type="#dotNetObjectType#">' . "\n" . ' <column name="#name#" sql-type="#type#"' . ' not-null="#notNull#" #indexName#/>' . "\n" . ' </property>'); } } $GLOBALS['dbi']->freeResult($result); } $lines[] = ' </class>'; $lines[] = '</hibernate-mapping>'; return implode("\n", $lines); }
/** * Test for ExportCodegen::cgMakeIdentifier * * @return void */ public function testCgMakeIdentifier() { $this->assertEquals('_Ⅲfoo', ExportCodegen::cgMakeIdentifier('Ⅲ{}96`{}foo', true)); $this->assertEquals('TestⅢ', ExportCodegen::cgMakeIdentifier('`98testⅢ{}96`{}', true)); $this->assertEquals('testⅢ', ExportCodegen::cgMakeIdentifier('`98testⅢ{}96`{}', false)); }
/** * Formats a string * * @param string $text string to be formatted * * @return string formatted text */ function format($text) { $text = str_replace("#ucfirstName#", ExportCodegen::cgMakeIdentifier($this->name), $text); $text = str_replace("#dotNetPrimitiveType#", $this->getDotNetPrimitiveType(), $text); $text = str_replace("#dotNetObjectType#", $this->getDotNetObjectType(), $text); $text = str_replace("#type#", $this->getPureType(), $text); $text = str_replace("#notNull#", $this->isNotNull(), $text); $text = str_replace("#unique#", $this->isUnique(), $text); return $text; }