Skip to content

Commit

Permalink
Add method to split plugin and class names up.
Browse files Browse the repository at this point in the history
Refs #3512
  • Loading branch information
markstory committed May 17, 2014
1 parent 6c0d52a commit 7818aa8
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/Console/Command/Task/BakeTask.php
Expand Up @@ -80,12 +80,6 @@ public function getPath() {
* @return void
*/
public function main() {
foreach ($this->args as $i => $arg) {
if (strpos($arg, '.')) {
list($this->params['plugin'], $this->args[$i]) = pluginSplit($arg);
break;
}
}
if (isset($this->params['plugin'])) {
$this->plugin = $this->params['plugin'];
}
Expand All @@ -94,6 +88,22 @@ public function main() {
}
}

/**
* Handles splitting up the plugin prefix and classname.
*
* Sets the plugin parameter and plugin property.
*
* @param string $name The name to possibly split.
* @return string The name without the plugin prefix.
*/
protected function _getName($name) {
if (strpos($name, '.')) {
list($plugin, $name) = pluginSplit($name);
$this->plugin = $this->params['plugin'] = $plugin;
}
return $name;
}

/**
* Get the option parser for this task.
*
Expand Down
1 change: 1 addition & 0 deletions src/Console/Command/Task/ControllerTask.php
Expand Up @@ -46,6 +46,7 @@ class ControllerTask extends BakeTask {
*/
public function main($name = null) {
parent::main();
$name = $this->_getName($name);

if (empty($name)) {
$this->out(__d('cake_console', 'Possible controllers based on your current database:'));
Expand Down
1 change: 1 addition & 0 deletions src/Console/Command/Task/FixtureTask.php
Expand Up @@ -92,6 +92,7 @@ public function getOptionParser() {
*/
public function main($name = null) {
parent::main();
$name = $this->_getName($name);

if (empty($name)) {
$this->out(__d('cake_console', 'Choose a fixture to bake from the following:'));
Expand Down
1 change: 1 addition & 0 deletions src/Console/Command/Task/ModelTask.php
Expand Up @@ -77,6 +77,7 @@ class ModelTask extends BakeTask {
*/
public function main($name = null) {
parent::main();
$name = $this->_getName($name);

if (empty($name)) {
$this->out(__d('cake_console', 'Choose a model to bake from the following:'));
Expand Down
1 change: 1 addition & 0 deletions src/Console/Command/Task/SimpleBakeTask.php
Expand Up @@ -77,6 +77,7 @@ public function main($name = null) {
if (empty($name)) {
return $this->error('You must provide a name to bake a ' . $this->name());
}
$name = $this->_getName($name);
$name = Inflector::camelize($name);
$this->bake($name);
$this->bakeTest($name);
Expand Down
1 change: 1 addition & 0 deletions src/Console/Command/Task/ViewTask.php
Expand Up @@ -109,6 +109,7 @@ public function main($name = null, $template = null, $action = null) {
}
return true;
}
$name = $this->_getName($name);

$controller = null;
if (!empty($this->params['controller'])) {
Expand Down

1 comment on commit 7818aa8

@angelxmoreno
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome!

Please sign in to comment.