Browse Source

use stringifyList where possible

AD7six 11 years ago
parent
commit
90e5e9e79b
2 changed files with 5 additions and 25 deletions
  1. 2 8
      src/Template/Bake/Model/entity.ctp
  2. 3 17
      src/Template/Bake/Model/table.ctp

+ 2 - 8
src/Template/Bake/Model/entity.ctp

@@ -37,18 +37,12 @@ class <%= $name %> extends Entity {
 
 <% endif %>
 <% if (!empty($hidden)): %>
-<%
-$hidden = array_map(function($el) { return "'$el'"; }, $hidden);
-%>
+
 /**
  * Fields that are excluded from JSON an array versions of the entity.
  *
  * @var array
  */
-	protected $_hidden = [
-		<%= implode(",\n\t\t", $hidden) %>
-
-	];
-
+	protected $_hidden = [<%= $this->Bake->stringifyList($hidden)];
 <% endif %>
 }

+ 3 - 17
src/Template/Bake/Model/table.ctp

@@ -40,32 +40,18 @@ class <%= $name %>Table extends Table {
 		$this->displayField('<%= $displayField %>');
 <% endif %>
 <% if (!empty($primaryKey)): %>
-<%
-$key = array_map(function($el) { return "'$el'"; }, (array)$primaryKey);
-%>
 <% if (count($primaryKey) > 1): %>
-		$this->primaryKey([<%= implode(', ', $key) %>]);
+		$this->primaryKey([<%= $this->Bake->stringifyList($(array)$primaryKey, ['indent' => false]) %>]);
 <% else: %>
-		$this->primaryKey(<%= current($key) %>);
+		$this->primaryKey('<%= current((array)$primaryKey) %>');
 <% endif %>
 <% endif %>
 <% foreach ($behaviors as $behavior => $behaviorData): %>
 		$this->addBehavior('<%= $behavior %>'<%= $behaviorData ? ", [" . implode(', ', $behaviorData) . ']' : '' %>);
 <% endforeach %>
-<% $firstAssoc = true; %>
 <% foreach ($associations as $type => $assocs): %>
 <% foreach ($assocs as $assoc): %>
-<% if ($firstAssoc): %>
-<%= "\n" %>
-<% $firstAssoc = false; %>
-<% endif %>
-		$this-><%= $type %>('<%= $assoc['alias'] %>', [
-<% foreach ($assoc as $key => $val): %>
-<% if ($key !== 'alias'): %>
-			<%= "'$key' => '$val',\n" %>
-<% endif %>
-<% endforeach %>
-		]);
+		$this-><%= $type %>('<%= $assoc['alias'] %>', [<?% $this->Bake->stringifyList($assoc, ['indent' => 3]) %>]);
 <% endforeach %>
 <% endforeach %>
 	}