Fixes to relationship building and added support for new schema options.
This commit is contained in:
parent
be20cf3b45
commit
1bbc5b15ee
@ -278,12 +278,16 @@ END;
|
||||
$build = '';
|
||||
foreach ($templates as $name => $options) {
|
||||
|
||||
if (is_array($options)) {
|
||||
if (is_array($options) && !empty($options)) {
|
||||
$optionsPhp = $this->arrayToPhpArrayCode($options);
|
||||
|
||||
$build .= "\t\t\$this->loadTemplate('" . $name . "', " . $optionsPhp . ");\n";
|
||||
} else {
|
||||
$build .= "\t\t\$this->loadTemplate('" . $options . "');\n";
|
||||
if (isset($templates[0])) {
|
||||
$build .= "\t\t\$this->loadTemplate('" . $options . "');\n";
|
||||
} else {
|
||||
$build .= "\t\t\$this->loadTemplate('" . $name . "');\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -294,40 +298,30 @@ END;
|
||||
{
|
||||
$build = '';
|
||||
foreach ($actAs as $name => $options) {
|
||||
$optionsPhp = $this->arrayToPhpArrayCode($options);
|
||||
|
||||
$build .= "\t\t\$this->actAs('" . $name . "', " . $optionsPhp . ");\n";
|
||||
if (is_array($options) && !empty($options)) {
|
||||
$optionsPhp = $this->arrayToPhp($options);
|
||||
|
||||
$build .= "\t\t\$this->actAs('" . $name . "', " . $optionsPhp . ");\n";
|
||||
} else {
|
||||
if (isset($actAs[0])) {
|
||||
$build .= "\t\t\$this->actAs('" . $options . "');\n";
|
||||
} else {
|
||||
$build .= "\t\t\$this->actAs('" . $name . "');\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $build;
|
||||
}
|
||||
|
||||
protected function arrayToPhpArrayCode($array)
|
||||
protected function arrayToPhp(array $array)
|
||||
{
|
||||
$build = 'array(';
|
||||
ob_start();
|
||||
var_export($array);
|
||||
$php = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
foreach ($array as $key => $value) {
|
||||
if (is_array($value)) {
|
||||
$build .= $this->arrayToPhpArrayCode($value);
|
||||
} else {
|
||||
$build .= "'" . $key . "' => ";
|
||||
if (is_integer($value)) {
|
||||
$build .= "$value";
|
||||
} else if (is_string($value)) {
|
||||
$build .= "'" . $value . "'";
|
||||
} else if (is_bool($value)) {
|
||||
$build .= $value ? "true":"false";
|
||||
}
|
||||
|
||||
$build .= ", ";
|
||||
}
|
||||
}
|
||||
|
||||
$build = substr($build, 0, strlen($build) - 2);
|
||||
|
||||
$build .= ')';
|
||||
|
||||
return $build;
|
||||
return $php;
|
||||
}
|
||||
|
||||
public function buildAttributes(array $attributes)
|
||||
|
@ -298,14 +298,24 @@ class Doctrine_Import_Schema
|
||||
$relations = $properties['relations'];
|
||||
|
||||
foreach ($relations as $alias => $relation) {
|
||||
|
||||
$class = isset($relation['class']) ? $relation['class']:$alias;
|
||||
|
||||
$relation['local'] = isset($relation['local']) ? $relation['local']:Doctrine::tableize($class) . '_id';
|
||||
$relation['foreign'] = isset($relation['foreign']) ? $relation['foreign']:'id';
|
||||
// Attempt to guess the local and foreign
|
||||
if (isset($relation['refClass'])) {
|
||||
$relation['local'] = isset($relation['local']) ? $relation['local']:Doctrine::tableize($name) . '_id';
|
||||
$relation['foreign'] = isset($relation['foreign']) ? $relation['foreign']:Doctrine::tableize($class) . '_id';
|
||||
} else {
|
||||
$relation['local'] = isset($relation['local']) ? $relation['local']:Doctrine::tableize($class) . '_id';
|
||||
$relation['foreign'] = isset($relation['foreign']) ? $relation['foreign']:'id';
|
||||
}
|
||||
|
||||
$relation['alias'] = isset($relation['alias']) ? $relation['alias'] : $alias;
|
||||
$relation['class'] = $class;
|
||||
|
||||
if (isset($relation['refClass'])) {
|
||||
$relation['type'] = 'many';
|
||||
}
|
||||
|
||||
if (isset($relation['type']) && $relation['type']) {
|
||||
$relation['type'] = $relation['type'] === 'one' ? Doctrine_Relation::ONE:Doctrine_Relation::MANY;
|
||||
} else {
|
||||
@ -317,8 +327,26 @@ class Doctrine_Import_Schema
|
||||
}
|
||||
|
||||
if(isset($relation['refClass']) && !empty($relation['refClass']) && (!isset($array[$relation['refClass']]['relations']) || empty($array[$relation['refClass']]['relations']))) {
|
||||
$array[$relation['refClass']]['relations'][$className] = array('local' => $relation['local'], 'foreign' => $relation['foreign'], 'ignore' => true);
|
||||
$array[$relation['refClass']]['relations'][$relation['class']] = array('local' => $relation['local'], 'foreign' => $relation['foreign'], 'ignore' => true);
|
||||
|
||||
if (!isset($array[$relation['refClass']]['relations'][$className]['local'])) {
|
||||
$array[$relation['refClass']]['relations'][$className]['local'] = $relation['local'];
|
||||
}
|
||||
|
||||
if (!isset($array[$relation['refClass']]['relations'][$className]['foreign'])) {
|
||||
$array[$relation['refClass']]['relations'][$className]['foreign'] = $relation['foreign'];
|
||||
}
|
||||
|
||||
$array[$relation['refClass']]['relations'][$className]['ignore'] = true;
|
||||
|
||||
if (!isset($array[$relation['refClass']]['relations'][$relation['class']]['local'])) {
|
||||
$array[$relation['refClass']]['relations'][$relation['class']]['local'] = $relation['local'];
|
||||
}
|
||||
|
||||
if (!isset($array[$relation['refClass']]['relations'][$relation['class']]['foreign'])) {
|
||||
$array[$relation['refClass']]['relations'][$relation['class']]['foreign'] = $relation['foreign'];
|
||||
}
|
||||
|
||||
$array[$relation['refClass']]['relations'][$relation['class']]['ignore'] = true;
|
||||
|
||||
if(isset($relation['foreignAlias'])) {
|
||||
$array[$relation['class']]['relations'][$relation['foreignAlias']] = array('type'=>$relation['type'],'local'=>$relation['foreign'],'foreign'=>$relation['local'],'refClass'=>$relation['refClass'],'class'=>$className);
|
||||
|
Loading…
x
Reference in New Issue
Block a user