本文整理汇总了PHP中CRUD::getTopLevelClass方法的典型用法代码示例。如果您正苦于以下问题:PHP CRUD::getTopLevelClass方法的具体用法?PHP CRUD::getTopLevelClass怎么用?PHP CRUD::getTopLevelClass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRUD
的用法示例。
在下文中一共展示了CRUD::getTopLevelClass方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: init
/**
* Inicia a anlise de um objeto
* @return void
*/
public function init()
{
$ref = new ReflectionClass($this->object);
$parentClassesArray = array($ref);
while ($ref->getParentClass()->getName() != CRUD::getTopLevelClass()) {
$ref = $ref->getParentClass();
$parentClassesArray[] = $ref;
}
$parentClassesArray = array_reverse($parentClassesArray);
foreach ($parentClassesArray as $ref) {
/*@var $ref ReflectionClass */
foreach ($ref->getProperties() as $prop) {
/* @var $prop ReflectionProperty */
$this->readDocComment($prop);
}
}
$this->initCheck = true;
}
示例2: createTable
/**
* Cria a tabela no banco conforme os dados da tabela, se vc precisa alterar a estrutura
* da tabela, ou use um Gerenciador de BD para alterála (lembre-se de atualizar
* o PHPDoc)
*
*/
public function createTable($topLevelClass = "", $onDelete = "SET NULL", $onUpdate = "CASCADE")
{
$pkStr = "";
if (empty($topLevelClass)) {
$topLevelClass = CRUD::getTopLevelClass();
}
$sqlToSave = "";
$ref = new ReflectionClass($this->DAO_Object);
$parentClassesArray = array($ref);
while ($ref->getParentClass()->getName() != $topLevelClass) {
$ref = $ref->getParentClass();
$parentClassesArray[] = $ref;
}
$parentClassesArray = array_reverse($parentClassesArray);
foreach ($parentClassesArray as $ref) {
//caso tenha superClasses
$superTableName = $this->buildTableName($ref->getName());
/*******************************************************************
* GERAÇÃO DE SUPER-TABELAS
* gera as tabelas das classes pais
******************************************************************/
$sql = "";
$sql .= "CREATE TABLE IF NOT EXISTS `" . Connection::getDataBaseName() . "`.`" . $superTableName . "` (";
$fks = "";
foreach ($this->buildTableColumns($ref->getName()) as $column) {
if (count($column) <= 2) {
continue;
}
$sql .= "`" . $column[0] . "` " . $column[2] . " ";
$cont = 0;
foreach ($column as $columnDetail) {
if ($cont > 2) {
$sql .= $columnDetail . " ";
}
++$cont;
}
if (class_exists($column[1])) {
try {
$onDeleteConst = $ref->getConstant(self::ON_DELETE_CLASS_CONST);
$onUpdateConst = $ref->getConstant(self::ON_UPDATE_CLASS_CONST);
if ($onDeleteConst) {
$onDelete = $onDeleteConst;
}
if ($onUpdateConst) {
$onUpdate = $onUpdateConst;
}
} catch (Exception $ex) {
}
$fks .= ", CONSTRAINT `fk_" . $ref->getName() . "_" . $column[0] . "`\r\n\t\t\t\t\t FOREIGN KEY (`" . $column[0] . "` )\r\n\t\t\t\t\t REFERENCES `" . Connection::getDataBaseName() . "`.`" . $this->buildTableName($column[1]) . "` (`id` )\r\n\t\t\t\t\t ON DELETE {$onDelete}\r\n\t\t\t\t\t ON UPDATE {$onUpdate}";
}
$sql .= " ,\r\n";
}
// varre o array de chaves primárias para criar abaixo
if (!empty($this->pkArray)) {
$pkStr = ",";
foreach ($this->pkArray as $pk) {
$pkStr .= "`{$pk}`, ";
}
$pkStr = substr($pkStr, 0, -2);
}
$sql .= " PRIMARY KEY (`" . self::PRIMARY_KEY_NAME . "`{$pkStr})";
if (!empty($fks)) {
$sql .= $fks;
}
if ($ref->getParentClass() && $ref->getParentClass()->getName() != $topLevelClass) {
//caso tenha uma classe pai faz as FK
$sql .= "\r\n\t\t\t\t , CONSTRAINT `fk_" . $ref->getParentClass()->getName() . "_" . $ref->getName() . "`\r\n\t\t\t\t FOREIGN KEY (`id` )\r\n\t\t\t\t REFERENCES `" . Connection::getDataBaseName() . "`.`" . $this->buildTableName($ref->getParentClass()->getName()) . "` (`id` )\r\n\t\t\t\t ON DELETE CASCADE\r\n\t\t\t\t ON UPDATE CASCADE\r\n\t\t\t";
}
$sql .= ") ENGINE=" . Connection::getEngine() . " DEFAULT CHARSET=" . Connection::getCharset() . ";";
//mysqli_query(CRUD::getConn() , $sql);
$r = CRUD::executeQuery($sql);
if (!$r) {
echo "<h1>A tabela: " . $this->getDbTable() . " não pode ser criada</h1>";
echo "<code>" . $sql . "<c/ode>";
} else {
echo 'Tabela "' . $superTableName . '" Criada com sucesso ! <br />';
}
$sqlToSave .= $sql . "\n\n";
var_dump($sqlToSave);
}
$this->writeCreatesSql($sqlToSave);
}