本文整理汇总了PHP中ActiveRecord::instantiate方法的典型用法代码示例。如果您正苦于以下问题:PHP ActiveRecord::instantiate方法的具体用法?PHP ActiveRecord::instantiate怎么用?PHP ActiveRecord::instantiate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ActiveRecord
的用法示例。
在下文中一共展示了ActiveRecord::instantiate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: instantiate
/**
* @see ActiveRecord::instantiate()
*/
public function instantiate($attributes)
{
$res = parent::instantiate($attributes);
/*
* We have to set some properties by hand
*/
if (isset($attributes['COLUMN_TYPE'])) {
// Size / scale
if (DataType::check($attributes['COLUMN_TYPE'], DataType::SUPPORTS_SIZE)) {
if (preg_match('/^\\w+\\((\\d+)(,\\d+)?\\)/', $attributes['COLUMN_TYPE'], $result)) {
$res->size = (int) $result[1];
if (isset($result[2]) && DataType::check($attributes['COLUMN_TYPE'], DataType::SUPPORTS_SCALE)) {
$res->scale = (int) substr($result[2], 1);
}
}
} elseif (DataType::check($attributes['COLUMN_TYPE'], DataType::SUPPORTS_VALUES)) {
if (preg_match('/^\\w+\\(\'([^\\)]+)\'\\)/', $attributes['COLUMN_TYPE'], $result)) {
$res->setValues(implode("\n", (array) explode("','", $result[1])));
}
}
// Unsigned
if (preg_match('/ unsigned$/', $attributes['COLUMN_TYPE'])) {
$res->attribute = 'unsigned';
} elseif (preg_match('/ unsigned zerofill$/', $attributes['COLUMN_TYPE'])) {
$res->attribute = 'unsigned zerofill';
} elseif ($attributes['COLUMN_TYPE'] == 'timestamp') {
if (strtolower($attributes['EXTRA']) == 'on update current_timestamp') {
$res->attribute = 'on update current_timestamp';
}
}
}
return $res;
}
示例2: instantiate
/**
* @see ActiveRecord::instantiate()
*/
public function instantiate($attributes)
{
$res = parent::instantiate($attributes);
$res->table = Table::model()->findByAttributes(array('TABLE_SCHEMA' => $attributes['TABLE_SCHEMA'], 'TABLE_NAME' => $attributes['TABLE_NAME']));
$match = '/^\\s+constraint `' . $attributes['CONSTRAINT_NAME'] . '` .+?$/im';
if (preg_match($match, $res->table->getShowCreateTable(), $result)) {
if (preg_match('/on delete (CASCADE|NO ACTION|SET NULL|RESTRICT)/i', $result[0], $result2)) {
$res->onDelete = $result2[1];
}
if (preg_match('/on update (CASCADE|NO ACTION|SET NULL|RESTRICT)/i', $result[0], $result2)) {
$res->onUpdate = $result2[1];
}
}
return $res;
}
示例3: instantiate
/**
* @see ActiveRecord::instantiate()
*/
public function instantiate($attributes)
{
$res = parent::instantiate($attributes);
// Check options
if (isset($attributes['CREATE_OPTIONS'])) {
$options = strtolower($attributes['CREATE_OPTIONS']);
} else {
$options = null;
}
if (strpos($options, 'checksum=1') !== false) {
$res->optionChecksum = $res->originalOptionChecksum = '1';
}
if (strpos($options, 'delay_key_write=1') !== false) {
$res->optionDelayKeyWrite = $res->originalOptionDelayKeyWrite = '1';
}
if (strpos($options, 'pack_keys=1') !== false) {
$res->optionPackKeys = $res->originalOptionPackKeys = '1';
} elseif (strpos($options, 'pack_keys=0') !== false) {
$res->optionPackKeys = $res->originalOptionPackKeys = '0';
}
// Comment
if (isset($attributes['TABLE_COMMENT'])) {
if (isset($attributes['ENGINE']) && $attributes['ENGINE'] == 'InnoDB') {
$search = 'InnoDB free: \\d+ ..?$';
if (preg_match('/^' . $search . '/', $attributes['TABLE_COMMENT'])) {
$res->comment = '';
} elseif (preg_match('/; ' . $search . '/', $attributes['TABLE_COMMENT'], $result)) {
$res->comment = str_replace($result[0], '', $attributes['TABLE_COMMENT']);
} else {
$res->comment = $attributes['TABLE_COMMENT'];
}
} else {
$res->comment = $attributes['TABLE_COMMENT'];
}
}
$res->originalAttributes['comment'] = $res->comment;
return $res;
}