-
Notifications
You must be signed in to change notification settings - Fork 238
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
808 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
/** | ||
* Lithium: the most rad php framework | ||
* | ||
* @copyright Copyright 2009, Union of RAD (http://union-of-rad.org) | ||
* @license http://opensource.org/licenses/bsd-license.php The BSD License | ||
*/ | ||
|
||
namespace lithium\tests\cases\console\command\build; | ||
|
||
use \lithium\console\command\build\Test; | ||
|
||
class TestTest extends \lithium\test\Unit { | ||
|
||
public function testRun() { | ||
|
||
|
||
} | ||
|
||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
<?php | ||
/** | ||
* Lithium: the most rad php framework | ||
* | ||
* @copyright Copyright 2009, Union of RAD (http://union-of-rad.org) | ||
* @license http://opensource.org/licenses/bsd-license.php The BSD License | ||
*/ | ||
|
||
namespace lithium\console\command; | ||
|
||
use \lithium\core\Libraries; | ||
use \lithium\util\String; | ||
|
||
/** | ||
* The `build` command allows you to rapidly develop your models, views, controllers, and tests | ||
* by generating the minimum code necessary to test and run your application. | ||
* | ||
*/ | ||
class Build extends \lithium\console\Command { | ||
|
||
/** | ||
* Controls the interactive nature of the command | ||
* When true, the command will ask questions and expect answers to generate the result | ||
* When false, the command will do it's best to determine the result to generate | ||
* | ||
* @var boolean | ||
*/ | ||
public $i = false; | ||
|
||
/** | ||
* Name of library to use | ||
* | ||
*/ | ||
public $library = 'app'; | ||
|
||
/** | ||
* The template to use to generate the file | ||
* | ||
*/ | ||
public $template = null; | ||
|
||
/** | ||
* Class Constrcutor | ||
* | ||
* @param string $config | ||
*/ | ||
public function __construct($config = array()) { | ||
$this->template = strtolower(join('', array_slice(explode("\\", get_class($this)), -1))); | ||
parent::__construct($config); | ||
} | ||
|
||
/** | ||
* Run the build command. Takes `$command` and delegates to `$command::$method` | ||
* | ||
* @param string $command | ||
* @param string $method | ||
* @return void | ||
*/ | ||
public function run($command = null, $method = 'run') { | ||
if (!$command) { | ||
return $this->interactive(); | ||
} | ||
$class = Libraries::locate('command.build', $command); | ||
$command = new $class(array('request' => $this->request->shift(2))); | ||
|
||
if (!method_exists($command, $method)) { | ||
array_unshift($command->request->params['args'], $method); | ||
$method = 'run'; | ||
} | ||
return $command->invokeMethod($method, $command->request->params['args']); | ||
} | ||
|
||
/** | ||
* Ask questions and use answers to build | ||
* | ||
* @return void | ||
*/ | ||
public function interactive() { | ||
|
||
} | ||
|
||
/** | ||
* Get the namespace | ||
* | ||
* @param string $name | ||
* @return string | ||
*/ | ||
protected function _namespace($name) { | ||
$nameToSpace = array( | ||
'model' => 'models', 'view' => 'views', 'controller' => 'controllers', | ||
'command' => 'extensions.command', 'adapter' => 'extensions.adapter', | ||
'helper' => 'extensions.helper' | ||
); | ||
if (isset($nameToSpace[$name])) { | ||
$name = $nameToSpace[$name]; | ||
} | ||
return str_replace('.', '\\', $name); | ||
} | ||
|
||
/** | ||
* Save a template with the current params. Writes file to `Build::$path` | ||
* | ||
* @param string $template | ||
* @param string $params | ||
* @return boolean | ||
*/ | ||
protected function _save($template, $params = array()) { | ||
$file = Libraries::locate('command.build.template', $template, array( | ||
'filter' => false, 'type' => 'file', 'suffix' => '.txt.php', | ||
)); | ||
if (!$file || is_array($file)) { | ||
return false; | ||
} | ||
|
||
$contents = file_get_contents($file); | ||
$result = String::insert($contents, $params); | ||
$library = Libraries::get($this->library); | ||
|
||
if (!empty($library['path'])) { | ||
$path = dirname($library['path']) . str_replace('\\', '/', | ||
"\\{$params['namespace']}\\{$params['class']}" | ||
); | ||
$file = str_replace('//', '/', "{$path}.php"); | ||
$directory = dirname($file); | ||
|
||
if (!is_dir($directory)) { | ||
if (!mkdir($directory, 0755, true)) { | ||
return false; | ||
} | ||
} | ||
return file_put_contents($file, "<?php\n\n{$result}\n\n?>"); | ||
} | ||
return false; | ||
} | ||
} | ||
|
||
?> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.