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 = '';
|
$build = '';
|
||||||
foreach ($templates as $name => $options) {
|
foreach ($templates as $name => $options) {
|
||||||
|
|
||||||
if (is_array($options)) {
|
if (is_array($options) && !empty($options)) {
|
||||||
$optionsPhp = $this->arrayToPhpArrayCode($options);
|
$optionsPhp = $this->arrayToPhpArrayCode($options);
|
||||||
|
|
||||||
$build .= "\t\t\$this->loadTemplate('" . $name . "', " . $optionsPhp . ");\n";
|
$build .= "\t\t\$this->loadTemplate('" . $name . "', " . $optionsPhp . ");\n";
|
||||||
} else {
|
} else {
|
||||||
|
if (isset($templates[0])) {
|
||||||
$build .= "\t\t\$this->loadTemplate('" . $options . "');\n";
|
$build .= "\t\t\$this->loadTemplate('" . $options . "');\n";
|
||||||
|
} else {
|
||||||
|
$build .= "\t\t\$this->loadTemplate('" . $name . "');\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -294,42 +298,32 @@ END;
|
|||||||
{
|
{
|
||||||
$build = '';
|
$build = '';
|
||||||
foreach ($actAs as $name => $options) {
|
foreach ($actAs as $name => $options) {
|
||||||
$optionsPhp = $this->arrayToPhpArrayCode($options);
|
if (is_array($options) && !empty($options)) {
|
||||||
|
$optionsPhp = $this->arrayToPhp($options);
|
||||||
|
|
||||||
$build .= "\t\t\$this->actAs('" . $name . "', " . $optionsPhp . ");\n";
|
$build .= "\t\t\$this->actAs('" . $name . "', " . $optionsPhp . ");\n";
|
||||||
}
|
|
||||||
|
|
||||||
return $build;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function arrayToPhpArrayCode($array)
|
|
||||||
{
|
|
||||||
$build = 'array(';
|
|
||||||
|
|
||||||
foreach ($array as $key => $value) {
|
|
||||||
if (is_array($value)) {
|
|
||||||
$build .= $this->arrayToPhpArrayCode($value);
|
|
||||||
} else {
|
} else {
|
||||||
$build .= "'" . $key . "' => ";
|
if (isset($actAs[0])) {
|
||||||
if (is_integer($value)) {
|
$build .= "\t\t\$this->actAs('" . $options . "');\n";
|
||||||
$build .= "$value";
|
} else {
|
||||||
} else if (is_string($value)) {
|
$build .= "\t\t\$this->actAs('" . $name . "');\n";
|
||||||
$build .= "'" . $value . "'";
|
}
|
||||||
} else if (is_bool($value)) {
|
|
||||||
$build .= $value ? "true":"false";
|
|
||||||
}
|
|
||||||
|
|
||||||
$build .= ", ";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$build = substr($build, 0, strlen($build) - 2);
|
|
||||||
|
|
||||||
$build .= ')';
|
|
||||||
|
|
||||||
return $build;
|
return $build;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function arrayToPhp(array $array)
|
||||||
|
{
|
||||||
|
ob_start();
|
||||||
|
var_export($array);
|
||||||
|
$php = ob_get_contents();
|
||||||
|
ob_end_clean();
|
||||||
|
|
||||||
|
return $php;
|
||||||
|
}
|
||||||
|
|
||||||
public function buildAttributes(array $attributes)
|
public function buildAttributes(array $attributes)
|
||||||
{
|
{
|
||||||
$build = "\n";
|
$build = "\n";
|
||||||
|
@ -298,14 +298,24 @@ class Doctrine_Import_Schema
|
|||||||
$relations = $properties['relations'];
|
$relations = $properties['relations'];
|
||||||
|
|
||||||
foreach ($relations as $alias => $relation) {
|
foreach ($relations as $alias => $relation) {
|
||||||
|
|
||||||
$class = isset($relation['class']) ? $relation['class']:$alias;
|
$class = isset($relation['class']) ? $relation['class']:$alias;
|
||||||
|
|
||||||
|
// 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['local'] = isset($relation['local']) ? $relation['local']:Doctrine::tableize($class) . '_id';
|
||||||
$relation['foreign'] = isset($relation['foreign']) ? $relation['foreign']:'id';
|
$relation['foreign'] = isset($relation['foreign']) ? $relation['foreign']:'id';
|
||||||
|
}
|
||||||
|
|
||||||
$relation['alias'] = isset($relation['alias']) ? $relation['alias'] : $alias;
|
$relation['alias'] = isset($relation['alias']) ? $relation['alias'] : $alias;
|
||||||
$relation['class'] = $class;
|
$relation['class'] = $class;
|
||||||
|
|
||||||
|
if (isset($relation['refClass'])) {
|
||||||
|
$relation['type'] = 'many';
|
||||||
|
}
|
||||||
|
|
||||||
if (isset($relation['type']) && $relation['type']) {
|
if (isset($relation['type']) && $relation['type']) {
|
||||||
$relation['type'] = $relation['type'] === 'one' ? Doctrine_Relation::ONE:Doctrine_Relation::MANY;
|
$relation['type'] = $relation['type'] === 'one' ? Doctrine_Relation::ONE:Doctrine_Relation::MANY;
|
||||||
} else {
|
} 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']))) {
|
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'])) {
|
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);
|
$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