Permalink
Browse files

Refactoring `Create` command and beginning implementation of adapter …

…generator.
  • Loading branch information...
1 parent 96ae2ff commit 9ede286f62eddf8f2af21aec2e56ee1f018742de @nateabele nateabele committed Feb 27, 2012
@@ -47,6 +47,13 @@ class Create extends \lithium\console\Command {
protected $_library = array();
/**
+ * Contains the list of `Create` sub-commands.
+ *
+ * @var array
+ */
+ protected $_commands = array();
+
+ /**
* Class initializer. Parses template and sets up params that need to be filled.
*
* @return void
@@ -56,6 +63,16 @@ protected function _init() {
$this->library = $this->library ?: true;
$defaults = array('prefix' => null, 'path' => null);
$this->_library = (array) Libraries::get($this->library) + $defaults;
+ $commands = Libraries::locate('command.create');
+
+ $this->_commands = array_combine($commands, array_map(
+ function($cmd) {
+ return str_replace('_', '-', Inflector::underscore(
+ substr($cmd, strrpos($cmd, '\\') + 1)
+ ));
+ },
+ $commands
+ ));
}
/**
@@ -65,7 +82,7 @@ protected function _init() {
* @return boolean
*/
public function run($command = null) {
- if ($command && !$this->request->args()) {
+ if ($command && !in_array($command, $this->_commands)) {
return $this->_default($command);
}
$this->request->shift();
@@ -0,0 +1,35 @@
+<?php
+/**
+ * Lithium: the most rad php framework
+ *
+ * @copyright Copyright 2012, Union of RAD (http://union-of-rad.org)
+ * @license http://opensource.org/licenses/bsd-license.php The BSD License
+ */
+
+namespace lithium\console\command\create;
+
+use lithium\util\Inflector;
+
+/**
+ * Generate a Model class in the `--library` namespace
+ *
+ * `li3 create model Posts`
+ * `li3 create --library=li3_plugin model Posts`
+ *
+ */
+class Adapter extends \lithium\console\command\Create {
+
+ public $class;
+
+ /**
+ * Get the class name for the model.
+ *
+ * @param string $request
+ * @return string
+ */
+ protected function _class($request) {
+ return Inflector::camelize(Inflector::pluralize($request->action));
+ }
+}
+
+?>
@@ -0,0 +1,6 @@
+namespace {:namespace};
+
+class {:class} extends {:parent} {
+
+{:methods}
+}

0 comments on commit 9ede286

Please sign in to comment.