本文整理汇总了PHP中Migration::extractPath方法的典型用法代码示例。如果您正苦于以下问题:PHP Migration::extractPath方法的具体用法?PHP Migration::extractPath怎么用?PHP Migration::extractPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Migration
的用法示例。
在下文中一共展示了Migration::extractPath方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: extractPath
function extractPath($data, $path = null)
{
if (empty($path)) {
return $data;
}
if (is_object($data)) {
$data = get_object_vars($data);
}
if (!is_array($path)) {
if (!class_exists('String')) {
App::import('Core', 'String');
}
$parts = String::tokenize($path, '.', '{', '}');
} else {
$parts = $path;
}
if (!is_array($data)) {
return array();
}
$tmp = array();
if (empty($parts) || !is_array($parts)) {
return array();
}
$key = reset($parts);
$tmpPath = array_slice($parts, 1);
if (is_numeric($key) && intval($key) > 0 || $key === '0') {
if (isset($data[intval($key)])) {
$tmp[intval($key)] = $data[intval($key)];
} else {
return array();
}
} elseif ($key === '{n}') {
foreach ($data as $j => $val) {
if (is_int($j)) {
$tmp[$j] = $val;
}
}
} elseif ($key === '{s}') {
foreach ($data as $j => $val) {
if (is_string($j)) {
$tmp[$j] = $val;
}
}
} elseif (false !== strpos($key, '{') && false !== strpos($key, '}')) {
$pattern = substr($key, 1, -1);
foreach ($data as $j => $val) {
if (preg_match('/^' . $pattern . '/s', $j) !== 0) {
$tmp[$j] = $val;
}
}
} else {
if (isset($data[$key])) {
$tmp[$key] = $data[$key];
} else {
return array();
}
}
$res = array();
if (!empty($tmpPath)) {
foreach ($tmp as $key => $val) {
$res2 = Migration::extractPath($val, $tmpPath);
foreach ($res2 as $key2 => $val2) {
$res[$key . '.' . $key2] = $val2;
}
}
} else {
return $tmp;
}
return $res;
}
示例2: prepDataForMigration
function prepDataForMigration($exclude = array())
{
// $this->LocalModel, $this->entry, $this->targetInstance
// $Model, $entry, $targetInstance,
$settings = $this->LocalModel->migrationSettings();
$exclude = array_merge($exclude, array($this->LocalModel->primaryKey), $settings['excludeFields']);
$fullName = $this->LocalModel->getFullName();
$alias = $this->LocalModel->alias;
$entry = $this->entry;
$assoc = $this->LocalModel->getMigratedAssociations();
if (!empty($assoc)) {
foreach ($assoc as $name => $opt) {
$paths = array();
if (!empty($opt['path'])) {
$paths = Migration::extractPath($entry[$alias], $opt['path']);
} elseif (!empty($opt['foreignKey']) && array_key_exists($opt['foreignKey'], $entry[$alias])) {
$paths = array($opt['foreignKey'] => $entry[$alias][$opt['foreignKey']]);
}
//debug($paths);
if (!empty($paths)) {
$AssocModel = Migration::getLocalModel($opt['className']);
foreach ($paths as $path => $local_id) {
$removed = false;
$remote_id = $AssocModel->getRemoteId($local_id, $this->targetInstance);
if (is_null($remote_id)) {
if (isset($opt['unsetLevel'])) {
$entry[$alias] = Set::remove($entry[$alias], implode('.', array_slice(explode('.', $path), 0, $opt['unsetLevel'])));
$removed = true;
}
if (!empty($opt['autoTrack'])) {
$entry['MigrationTracking'][$opt['className']][$local_id] = 1;
}
if (!empty($opt['autoSelect'])) {
$this->Batch->Process->autoSelect[] = array('model' => $opt['className'], 'local_id' => $local_id);
}
$entry['MigrationMissing'][] = array('model' => $opt['className'], 'local_id' => $local_id);
}
if (!$removed) {
$entry[$alias] = Set::insert($entry[$alias], $path, $remote_id);
}
}
}
}
//debug($assoc);
}
//debug($entry[$alias]);
$raw = $this->LocalModel->getRawEntry($entry);
$data = $raw[$alias];
$data = array_diff_key($data, array_flip($exclude));
$entry['MigrationData'] = $data;
return $entry;
}