Skip to content
Permalink
Browse files

Fix additional, pointless and sometimes harmful inflections.

Since CakePHP 3.0's conventions are that most things are plural, we
don't need to be pluralizing things as people will be thinking in terms
of plural forms. Removing this code from bake makes it much easier to
accomodate names like menus without incorrectly inflecting them.

Fixes #4647
  • Loading branch information...
markstory committed Sep 26, 2014
1 parent 42d4921 commit 8303b8348f069cac18781619cca3c7b25c5ab5cd
@@ -23,16 +23,6 @@
*/
trait ConventionsTrait {
/**
* Creates the proper controller plural name for the specified controller class name
*
* @param string $name Controller class name
* @return string Controller plural name
*/
protected function _controllerName($name) {
return Inflector::pluralize(Inflector::camelize($name));
}
/**
* Creates a fixture name
*
@@ -43,16 +33,6 @@ protected function _fixtureName($name) {
return Inflector::underscore($name);
}
/**
* Creates the proper model camelized name (plural) for the specified name
*
* @param string $name Name
* @return string Camelized and plural model name
*/
protected function _modelName($name) {
return Inflector::pluralize(Inflector::camelize($name));
}
/**
* Creates the proper entity name (singular) for the specified name
*
@@ -81,7 +61,7 @@ protected function _modelKey($name) {
*/
protected function _modelNameFromKey($key) {
$key = str_replace('_id', '', $key);
return $this->_modelName($key);
return Inflector::pluralize(Inflector::classify($key));
}
/**
@@ -213,7 +213,7 @@ public function all($name = null) {
$this->{$task}->connection = $this->connection;
}
$name = $this->_modelName($name);
$name = $this->_camelize($name);
$this->Model->bake($name);
$this->Controller->bake($name);
@@ -51,12 +51,12 @@ public function main($name = null) {
if (empty($name)) {
$this->out('Possible controllers based on your current database:');
foreach ($this->listAll() as $table) {
$this->out('- ' . $this->_controllerName($table));
$this->out('- ' . $this->_camelize($table));
}
return true;
}
$controller = $this->_controllerName($name);
$controller = $this->_camelize($name);
$this->bake($controller);
}
@@ -101,7 +101,7 @@ public function main($name = null) {
if (empty($name)) {
$this->out('Choose a fixture to bake from the following:');
foreach ($this->Model->listAll() as $table) {
$this->out('- ' . $this->_modelName($table));
$this->out('- ' . $this->_camelize($table));
}
return true;
}
@@ -110,7 +110,7 @@ public function main($name = null) {
if (isset($this->params['table'])) {
$table = $this->params['table'];
}
$model = $this->_modelName($name);
$model = $this->_camelize($name);
$this->bake($model, $table);
}
@@ -81,12 +81,12 @@ public function main($name = null) {
if (empty($name)) {
$this->out('Choose a model to bake from the following:');
foreach ($this->listAll() as $table) {
$this->out('- ' . $this->_modelName($table));
$this->out('- ' . $this->_camelize($table));
}
return true;
}
$this->bake($this->_modelName($name));
$this->bake($this->_camelize($name));
}
/**
@@ -263,7 +263,7 @@ public function findHasMany($model, array $associations) {
$foreignKey = $this->_modelKey($tableName);
foreach ($this->listAll() as $otherTable) {
$otherModel = $this->getTableObject($this->_modelName($otherTable), $otherTable);
$otherModel = $this->getTableObject($this->_camelize($otherTable), $otherTable);
$otherSchema = $otherModel->schema();
// Exclude habtm join tables.
@@ -323,7 +323,7 @@ public function findBelongsToMany($model, array $associations) {
$assocTable = substr($otherTable, 0, $otherOffset);
}
if ($assocTable && in_array($assocTable, $tables)) {
$habtmName = $this->_modelName($assocTable);
$habtmName = $this->_camelize($assocTable);
$assoc = [
'alias' => $habtmName,
'foreignKey' => $foreignKey,
@@ -549,7 +549,7 @@ public function getCounterCache($model) {
$counterCache = [];
foreach ($belongsTo['belongsTo'] as $otherTable) {
$otherAlias = $otherTable['alias'];
$otherModel = $this->getTableObject($this->_modelName($otherAlias), Inflector::underscore($otherAlias));
$otherModel = $this->getTableObject($this->_camelize($otherAlias), Inflector::underscore($otherAlias));
try {
$otherSchema = $otherModel->schema();
@@ -665,7 +665,7 @@ public function listAll() {
$this->_modelNames = [];
$this->_tables = $this->_getAllTables();
foreach ($this->_tables as $table) {
$this->_modelNames[] = $this->_modelName($table);
$this->_modelNames[] = $this->_camelize($table);
}
return $this->_tables;
}
@@ -709,7 +709,7 @@ public function getTable($name) {
if (isset($this->params['table'])) {
return $this->params['table'];
}
return Inflector::tableize($name);
return Inflector::underscore($name);
}
/**
@@ -108,7 +108,7 @@ public function main($name = null, $template = null, $action = null) {
$this->out('Possible tables to bake views for based on your current database:');
$this->Model->connection = $this->connection;
foreach ($this->Model->listAll() as $table) {
$this->out('- ' . $this->_controllerName($table));
$this->out('- ' . $this->_camelize($table));
}
return true;
}
@@ -149,7 +149,7 @@ public function main($name = null, $template = null, $action = null) {
* @return void
*/
public function model($table) {
$tableName = $this->_controllerName($table);
$tableName = $this->_camelize($table);
$plugin = null;
if (!empty($this->params['plugin'])) {
$plugin = $this->params['plugin'] . '.';
@@ -165,7 +165,7 @@ public function model($table) {
* @return void
*/
public function controller($table, $controller = null) {
$tableName = $this->_controllerName($table);
$tableName = $this->_camelize($table);
if (empty($controller)) {
$controller = $tableName;
}
@@ -91,7 +91,7 @@ public function testAllWithModelName() {
$this->Shell->connection = '';
$this->Shell->params = [];
$this->Shell->all('Comment');
$this->Shell->all('Comments');
}
/**
@@ -325,7 +325,7 @@ public function testMainIntoAll() {
*/
public static function nameVariations() {
return array(
array('BakeArticles'), array('BakeArticle'), array('bake_article'), array('bake_articles')
array('BakeArticles'), array('bake_articles')
);
}
@@ -150,7 +150,7 @@ public function testMainWithTableOption() {
->method('createFile')
->with($filename, $this->stringContains("public \$table = 'comments';"));
$this->Task->main('article');
$this->Task->main('articles');
}
/**
@@ -168,7 +168,7 @@ public function testMainWithPluginModel() {
->method('createFile')
->with($filename, $this->stringContains('class ArticlesFixture'));
$this->Task->main('TestPlugin.Article');
$this->Task->main('TestPlugin.Articles');
}
/**
@@ -280,7 +280,7 @@ public function testBake() {
$this->stringContains('public $records'),
$this->logicalNot($this->stringContains('public $import'))
));
$result = $this->Task->main('Article');
$result = $this->Task->main('Articles');
}
/**
@@ -124,9 +124,6 @@ public function testListAllConnection() {
* @return void
*/
public function testGetTable() {
$result = $this->Task->getTable('BakeArticle');
$this->assertEquals('bake_articles', $result);
$result = $this->Task->getTable('BakeArticles');
$this->assertEquals('bake_articles', $result);
@@ -1008,7 +1005,7 @@ public function testMainWithNamedModel() {
*/
public static function nameVariations() {
return array(
array('BakeArticles'), array('BakeArticle'), array('bake_article'), array('bake_articles')
array('BakeArticles'), array('bake_articles')
);
}
@@ -226,7 +226,7 @@ public function testModel() {
$this->assertEquals('Articles', $this->Task->modelName);
$this->Task->model('NotThere');
$this->assertEquals('NotTheres', $this->Task->modelName);
$this->assertEquals('NotThere', $this->Task->modelName);
}
/**
@@ -629,7 +629,7 @@ public function testMainWithPluginName() {
* @return void
*/
public static function nameVariations() {
return [['ViewTaskComments'], ['ViewTaskComment'], ['view_task_comment']];
return [['ViewTaskComments'], ['view_task_comments']];
}
/**

0 comments on commit 8303b83

Please sign in to comment.
You can’t perform that action at this time.