本文整理汇总了PHP中RedBeanPHP\OODBBean::moveMeta方法的典型用法代码示例。如果您正苦于以下问题:PHP OODBBean::moveMeta方法的具体用法?PHP OODBBean::moveMeta怎么用?PHP OODBBean::moveMeta使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RedBeanPHP\OODBBean
的用法示例。
在下文中一共展示了OODBBean::moveMeta方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: modifySchema
/**
* Modifies the table to fit the bean data.
* Given a property and a value and the bean, this method will
* adjust the table structure to fit the requirements of the property and value.
* This may include adding a new column or widening an existing column to hold a larger
* or different kind of value. This method employs the writer to adjust the table
* structure in the database. Schema updates are recorded in meta properties of the bean.
*
* This method will also apply indexes, unique constraints and foreign keys.
*
* @param OODBBean $bean bean to get cast data from and store meta in
* @param string $property property to store
* @param mixed $value value to store
*
* @return void
*/
private function modifySchema(OODBBean $bean, $property, $value)
{
$doFKStuff = FALSE;
$table = $bean->getMeta('type');
$columns = $this->writer->getColumns($table);
$columnNoQ = $this->writer->esc($property, TRUE);
if (!$this->oodb->isChilled($bean->getMeta('type'))) {
if ($bean->getMeta("cast.{$property}", -1) !== -1) {
//check for explicitly specified types
$cast = $bean->getMeta("cast.{$property}");
$typeno = $this->getTypeFromCast($cast);
} else {
$cast = FALSE;
$typeno = $this->writer->scanType($value, TRUE);
}
if (isset($columns[$this->writer->esc($property, TRUE)])) {
//Is this property represented in the table ?
if (!$cast) {
//rescan without taking into account special types >80
$typeno = $this->writer->scanType($value, FALSE);
}
$sqlt = $this->writer->code($columns[$this->writer->esc($property, TRUE)]);
if ($typeno > $sqlt) {
//no, we have to widen the database column type
$this->writer->widenColumn($table, $property, $typeno);
$bean->setMeta('buildreport.flags.widen', TRUE);
$doFKStuff = TRUE;
}
} else {
$this->writer->addColumn($table, $property, $typeno);
$bean->setMeta('buildreport.flags.addcolumn', TRUE);
$doFKStuff = TRUE;
}
if ($doFKStuff) {
if (strrpos($columnNoQ, '_id') === strlen($columnNoQ) - 3) {
$destinationColumnNoQ = substr($columnNoQ, 0, strlen($columnNoQ) - 3);
$indexName = "index_foreignkey_{$table}_{$destinationColumnNoQ}";
$this->writer->addIndex($table, $indexName, $columnNoQ);
$typeof = $bean->getMeta("sys.typeof.{$destinationColumnNoQ}", $destinationColumnNoQ);
$isLink = $bean->getMeta('sys.buildcommand.unique', FALSE);
//Make FK CASCADING if part of exclusive list (dependson=typeof) or if link bean
$isDep = $bean->moveMeta('sys.buildcommand.fkdependson') === $typeof || is_array($isLink);
$result = $this->writer->addFK($table, $typeof, $columnNoQ, 'id', $isDep);
//If this is a link bean and all unique columns have been added already, then apply unique constraint
if (is_array($isLink) && !count(array_diff($isLink, array_keys($this->writer->getColumns($table))))) {
$this->writer->addUniqueConstraint($table, $bean->moveMeta('sys.buildcommand.unique'));
$bean->setMeta("sys.typeof.{$destinationColumnNoQ}", NULL);
}
}
}
}
}