Skip to content
This repository
Browse code

Refactoring `Create` command and beginning implementation of adapter …

…generator.
  • Loading branch information...
commit 9ede286f62eddf8f2af21aec2e56ee1f018742de 1 parent 96ae2ff
Nate Abele nateabele authored
19 console/command/Create.php
@@ -47,6 +47,13 @@ class Create extends \lithium\console\Command {
47 47 protected $_library = array();
48 48
49 49 /**
  50 + * Contains the list of `Create` sub-commands.
  51 + *
  52 + * @var array
  53 + */
  54 + protected $_commands = array();
  55 +
  56 + /**
50 57 * Class initializer. Parses template and sets up params that need to be filled.
51 58 *
52 59 * @return void
@@ -56,6 +63,16 @@ protected function _init() {
56 63 $this->library = $this->library ?: true;
57 64 $defaults = array('prefix' => null, 'path' => null);
58 65 $this->_library = (array) Libraries::get($this->library) + $defaults;
  66 + $commands = Libraries::locate('command.create');
  67 +
  68 + $this->_commands = array_combine($commands, array_map(
  69 + function($cmd) {
  70 + return str_replace('_', '-', Inflector::underscore(
  71 + substr($cmd, strrpos($cmd, '\\') + 1)
  72 + ));
  73 + },
  74 + $commands
  75 + ));
59 76 }
60 77
61 78 /**
@@ -65,7 +82,7 @@ protected function _init() {
65 82 * @return boolean
66 83 */
67 84 public function run($command = null) {
68   - if ($command && !$this->request->args()) {
  85 + if ($command && !in_array($command, $this->_commands)) {
69 86 return $this->_default($command);
70 87 }
71 88 $this->request->shift();
35 console/command/create/Adapter.php
... ... @@ -0,0 +1,35 @@
  1 +<?php
  2 +/**
  3 + * Lithium: the most rad php framework
  4 + *
  5 + * @copyright Copyright 2012, Union of RAD (http://union-of-rad.org)
  6 + * @license http://opensource.org/licenses/bsd-license.php The BSD License
  7 + */
  8 +
  9 +namespace lithium\console\command\create;
  10 +
  11 +use lithium\util\Inflector;
  12 +
  13 +/**
  14 + * Generate a Model class in the `--library` namespace
  15 + *
  16 + * `li3 create model Posts`
  17 + * `li3 create --library=li3_plugin model Posts`
  18 + *
  19 + */
  20 +class Adapter extends \lithium\console\command\Create {
  21 +
  22 + public $class;
  23 +
  24 + /**
  25 + * Get the class name for the model.
  26 + *
  27 + * @param string $request
  28 + * @return string
  29 + */
  30 + protected function _class($request) {
  31 + return Inflector::camelize(Inflector::pluralize($request->action));
  32 + }
  33 +}
  34 +
  35 +?>
6 console/command/create/template/adapter.txt.php
... ... @@ -0,0 +1,6 @@
  1 +namespace {:namespace};
  2 +
  3 +class {:class} extends {:parent} {
  4 +
  5 +{:methods}
  6 +}

0 comments on commit 9ede286

Please sign in to comment.
Something went wrong with that request. Please try again.