Skip to content

Commit

Permalink
Applying patch from 'rafaelbandeira3' fixing formatting of generated …
Browse files Browse the repository at this point in the history
…code to better follow cake coding standards. Fixes #5754

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8082 3807eeeb-6ff5-0310-8944-8be069107fe0
  • Loading branch information
markstory committed Mar 8, 2009
1 parent 965b8e9 commit 1497fdd
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 58 deletions.
100 changes: 50 additions & 50 deletions cake/console/libs/tasks/model.php
Expand Up @@ -570,13 +570,13 @@ function bake($name, $associations = array(), $validate = array(), $primaryKey
$belongsToCount = count($associations['belongsTo']);

for ($i = 0; $i < $belongsToCount; $i++) {
$out .= "\t\t\t'{$associations['belongsTo'][$i]['alias']}' => ";
$out .= "array('className' => '{$associations['belongsTo'][$i]['className']}',\n";
$out .= "\t\t\t\t\t\t\t\t'foreignKey' => '{$associations['belongsTo'][$i]['foreignKey']}',\n";
$out .= "\t\t\t\t\t\t\t\t'conditions' => '',\n";
$out .= "\t\t\t\t\t\t\t\t'fields' => '',\n";
$out .= "\t\t\t\t\t\t\t\t'order' => ''\n";
$out .= "\t\t\t)";
$out .= "\t\t'{$associations['belongsTo'][$i]['alias']}' => array(\n";
$out .= "\t\t\t'className' => '{$associations['belongsTo'][$i]['className']}',\n";
$out .= "\t\t\t'foreignKey' => '{$associations['belongsTo'][$i]['foreignKey']}',\n";
$out .= "\t\t\t'conditions' => '',\n";
$out .= "\t\t\t'fields' => '',\n";
$out .= "\t\t\t'order' => ''\n";
$out .= "\t\t)";
if ($i + 1 < $belongsToCount) {
$out .= ",";
}
Expand All @@ -591,14 +591,14 @@ function bake($name, $associations = array(), $validate = array(), $primaryKey
$hasOneCount = count($associations['hasOne']);

for ($i = 0; $i < $hasOneCount; $i++) {
$out .= "\t\t\t'{$associations['hasOne'][$i]['alias']}' => ";
$out .= "array('className' => '{$associations['hasOne'][$i]['className']}',\n";
$out .= "\t\t\t\t\t\t\t\t'foreignKey' => '{$associations['hasOne'][$i]['foreignKey']}',\n";
$out .= "\t\t\t\t\t\t\t\t'dependent' => false,\n";
$out .= "\t\t\t\t\t\t\t\t'conditions' => '',\n";
$out .= "\t\t\t\t\t\t\t\t'fields' => '',\n";
$out .= "\t\t\t\t\t\t\t\t'order' => ''\n";
$out .= "\t\t\t)";
$out .= "\t\t'{$associations['hasOne'][$i]['alias']}' => array(\n";
$out .= "\t\t\t'className' => '{$associations['hasOne'][$i]['className']}',\n";
$out .= "\t\t\t'foreignKey' => '{$associations['hasOne'][$i]['foreignKey']}',\n";
$out .= "\t\t\t'dependent' => false,\n";
$out .= "\t\t\t'conditions' => '',\n";
$out .= "\t\t\t'fields' => '',\n";
$out .= "\t\t\t'order' => ''\n";
$out .= "\t\t)";
if ($i + 1 < $hasOneCount) {
$out .= ",";
}
Expand All @@ -613,19 +613,19 @@ function bake($name, $associations = array(), $validate = array(), $primaryKey
$hasManyCount = count($associations['hasMany']);

for ($i = 0; $i < $hasManyCount; $i++) {
$out .= "\t\t\t'{$associations['hasMany'][$i]['alias']}' => ";
$out .= "array('className' => '{$associations['hasMany'][$i]['className']}',\n";
$out .= "\t\t\t\t\t\t\t\t'foreignKey' => '{$associations['hasMany'][$i]['foreignKey']}',\n";
$out .= "\t\t\t\t\t\t\t\t'dependent' => false,\n";
$out .= "\t\t\t\t\t\t\t\t'conditions' => '',\n";
$out .= "\t\t\t\t\t\t\t\t'fields' => '',\n";
$out .= "\t\t\t\t\t\t\t\t'order' => '',\n";
$out .= "\t\t\t\t\t\t\t\t'limit' => '',\n";
$out .= "\t\t\t\t\t\t\t\t'offset' => '',\n";
$out .= "\t\t\t\t\t\t\t\t'exclusive' => '',\n";
$out .= "\t\t\t\t\t\t\t\t'finderQuery' => '',\n";
$out .= "\t\t\t\t\t\t\t\t'counterQuery' => ''\n";
$out .= "\t\t\t)";
$out .= "\t\t'{$associations['hasMany'][$i]['alias']}' => array(\n";
$out .= "\t\t\t'className' => '{$associations['hasMany'][$i]['className']}',\n";
$out .= "\t\t\t'foreignKey' => '{$associations['hasMany'][$i]['foreignKey']}',\n";
$out .= "\t\t\t'dependent' => false,\n";
$out .= "\t\t\t'conditions' => '',\n";
$out .= "\t\t\t'fields' => '',\n";
$out .= "\t\t\t'order' => '',\n";
$out .= "\t\t\t'limit' => '',\n";
$out .= "\t\t\t'offset' => '',\n";
$out .= "\t\t\t'exclusive' => '',\n";
$out .= "\t\t\t'finderQuery' => '',\n";
$out .= "\t\t\t'counterQuery' => ''\n";
$out .= "\t\t)";
if ($i + 1 < $hasManyCount) {
$out .= ",";
}
Expand All @@ -639,21 +639,21 @@ function bake($name, $associations = array(), $validate = array(), $primaryKey
$hasAndBelongsToManyCount = count($associations['hasAndBelongsToMany']);

for ($i = 0; $i < $hasAndBelongsToManyCount; $i++) {
$out .= "\t\t\t'{$associations['hasAndBelongsToMany'][$i]['alias']}' => ";
$out .= "array('className' => '{$associations['hasAndBelongsToMany'][$i]['className']}',\n";
$out .= "\t\t\t\t\t\t'joinTable' => '{$associations['hasAndBelongsToMany'][$i]['joinTable']}',\n";
$out .= "\t\t\t\t\t\t'foreignKey' => '{$associations['hasAndBelongsToMany'][$i]['foreignKey']}',\n";
$out .= "\t\t\t\t\t\t'associationForeignKey' => '{$associations['hasAndBelongsToMany'][$i]['associationForeignKey']}',\n";
$out .= "\t\t\t\t\t\t'unique' => true,\n";
$out .= "\t\t\t\t\t\t'conditions' => '',\n";
$out .= "\t\t\t\t\t\t'fields' => '',\n";
$out .= "\t\t\t\t\t\t'order' => '',\n";
$out .= "\t\t\t\t\t\t'limit' => '',\n";
$out .= "\t\t\t\t\t\t'offset' => '',\n";
$out .= "\t\t\t\t\t\t'finderQuery' => '',\n";
$out .= "\t\t\t\t\t\t'deleteQuery' => '',\n";
$out .= "\t\t\t\t\t\t'insertQuery' => ''\n";
$out .= "\t\t\t)";
$out .= "\t\t'{$associations['hasAndBelongsToMany'][$i]['alias']}' => array(\n";
$out .= "\t\t\t'className' => '{$associations['hasAndBelongsToMany'][$i]['className']}',\n";
$out .= "\t\t\t'joinTable' => '{$associations['hasAndBelongsToMany'][$i]['joinTable']}',\n";
$out .= "\t\t\t'foreignKey' => '{$associations['hasAndBelongsToMany'][$i]['foreignKey']}',\n";
$out .= "\t\t\t'associationForeignKey' => '{$associations['hasAndBelongsToMany'][$i]['associationForeignKey']}',\n";
$out .= "\t\t\t'unique' => true,\n";
$out .= "\t\t\t'conditions' => '',\n";
$out .= "\t\t\t'fields' => '',\n";
$out .= "\t\t\t'order' => '',\n";
$out .= "\t\t\t'limit' => '',\n";
$out .= "\t\t\t'offset' => '',\n";
$out .= "\t\t\t'finderQuery' => '',\n";
$out .= "\t\t\t'deleteQuery' => '',\n";
$out .= "\t\t\t'insertQuery' => ''\n";
$out .= "\t\t)";
if ($i + 1 < $hasAndBelongsToManyCount) {
$out .= ",";
}
Expand Down Expand Up @@ -718,7 +718,7 @@ function bakeTest($className, $useTable = null, $associations = array()) {
$out .= "\tfunction test{$className}Find() {\n";
$out .= "\t\t\$this->{$className}->recursive = -1;\n";
$out .= "\t\t\$results = \$this->{$className}->find('first');\n\t\t\$this->assertTrue(!empty(\$results));\n\n";
$out .= "\t\t\$expected = array('$className' => array(\n$results\n\t\t\t));\n";
$out .= "\t\t\$expected = array('$className' => array(\n$results\n\t\t));\n";
$out .= "\t\t\$this->assertEqual(\$results, \$expected);\n";
$out .= "\t}\n";
$out .= "}\n";
Expand Down Expand Up @@ -862,7 +862,7 @@ function fixture($model, $useTable = null) {
$type = $value;
$value = array('type'=> $type);
}
$col = "\t\t\t'{$field}' => array('type'=>'" . $value['type'] . "', ";
$col = "\t\t'{$field}' => array('type'=>'" . $value['type'] . "', ";

switch ($value['type']) {
case 'integer':
Expand Down Expand Up @@ -898,11 +898,11 @@ function fixture($model, $useTable = null) {
$insert .= "feugiat in taciti enim proin nibh, tempor dignissim, rhoncus duis vestibulum nunc mattis convallis.'";
break;
}
$records[] = "\t\t\t'$field' => $insert";
$records[] = "\t\t'$field' => $insert";
unset($value['type']);
$col .= join(', ', $schema->__values($value));
} else {
$col = "\t\t\t'indexes' => array(";
$col = "\t\t'indexes' => array(";
$props = array();
foreach ((array)$value as $key => $index) {
$props[] = "'{$key}' => array(".join(', ', $schema->__values($index)).")";
Expand All @@ -914,11 +914,11 @@ function fixture($model, $useTable = null) {
}
$out .= join(",\n", $cols);
}
$out .= "\n\t\t\t);\n";
$out .= "\n\t);\n";
}
}
$records = join(",\n", $records);
$out .= "\tvar \$records = array(array(\n$records\n\t\t\t));\n";
$out .= "\tvar \$records = array(array(\n$records\n\t));\n";
$out .= "}\n";
$path = TESTS . DS . 'fixtures' . DS;
if (isset($this->plugin)) {
Expand All @@ -930,7 +930,7 @@ function fixture($model, $useTable = null) {
$content = "<?php \n/* SVN FILE: $header$ */\n/* ". $model ." Fixture generated on: " . date('Y-m-d H:m:s') . " : ". time() . "*/\n{$out}?>";
$this->out("\nBaking test fixture for $model...");
if ($this->createFile($path . $filename, $content)) {
return $records;
return str_replace("\t\t", "\t\t\t", $records);
}
return false;
}
Expand Down
9 changes: 5 additions & 4 deletions cake/libs/model/model.php
Expand Up @@ -280,10 +280,11 @@ class Model extends Overloadable {
* @access private
*/
var $__associationKeys = array(
'belongsTo' => array('className', 'foreignKey', 'conditions', 'fields', 'order', 'counterCache'),
'hasOne' => array('className', 'foreignKey','conditions', 'fields','order', 'dependent'),
'hasMany' => array('className', 'foreignKey', 'conditions', 'fields', 'order', 'limit', 'offset', 'dependent', 'exclusive', 'finderQuery', 'counterQuery'),
'hasAndBelongsToMany' => array('className', 'joinTable', 'with', 'foreignKey', 'associationForeignKey', 'conditions', 'fields', 'order', 'limit', 'offset', 'unique', 'finderQuery', 'deleteQuery', 'insertQuery'));
'belongsTo' => array('className', 'foreignKey', 'conditions', 'fields', 'order', 'counterCache'),
'hasOne' => array('className', 'foreignKey','conditions', 'fields','order', 'dependent'),
'hasMany' => array('className', 'foreignKey', 'conditions', 'fields', 'order', 'limit', 'offset', 'dependent', 'exclusive', 'finderQuery', 'counterQuery'),
'hasAndBelongsToMany' => array('className', 'joinTable', 'with', 'foreignKey', 'associationForeignKey', 'conditions', 'fields', 'order', 'limit', 'offset', 'unique', 'finderQuery', 'deleteQuery', 'insertQuery')
);
/**
* Holds provided/generated association key names and other data for all associations.
*
Expand Down
8 changes: 4 additions & 4 deletions cake/libs/model/schema.php
Expand Up @@ -331,11 +331,11 @@ function write($object, $options = array()) {
$type = $value;
$value = array('type'=> $type);
}
$col = "\t\t\t'{$field}' => array('type' => '" . $value['type'] . "', ";
$col = "\t\t'{$field}' => array('type' => '" . $value['type'] . "', ";
unset($value['type']);
$col .= join(', ', $this->__values($value));
} else {
$col = "\t\t\t'indexes' => array(";
$col = "\t\t'indexes' => array(";
$props = array();
foreach ((array)$value as $key => $index) {
$props[] = "'{$key}' => array(".join(', ', $this->__values($index)).")";
Expand All @@ -347,15 +347,15 @@ function write($object, $options = array()) {
}
$out .= join(",\n", $cols);
}
$out .= "\n\t\t);\n";
$out .= "\n\t);\n";
}
}
$out .="}\n";


$File =& new File($path . DS . $file, true);
$header = '$Id';
$content = "<?php \n/* SVN FILE: $header$ */\n/* ". $name ." schema generated on: " . date('Y-m-d H:m:s') . " : ". time() . "*/\n{$out}?>";
$content = "<?php \n/* SVN FILE: {$header}$ */\n/* {$name} schema generated on: " . date('Y-m-d H:m:s') . " : ". time() . "*/\n{$out}?>";
$content = $File->prepare($content);
if ($File->write($content)) {
return $content;
Expand Down

0 comments on commit 1497fdd

Please sign in to comment.