Skip to content

Commit

Permalink
use stringifyList where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
AD7six committed Nov 14, 2014
1 parent c06be86 commit 90e5e9e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 25 deletions.
10 changes: 2 additions & 8 deletions src/Template/Bake/Model/entity.ctp
Expand Up @@ -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 %>
}
20 changes: 3 additions & 17 deletions src/Template/Bake/Model/table.ctp
Expand Up @@ -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 %>
}
Expand Down

0 comments on commit 90e5e9e

Please sign in to comment.