Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
working on generators
  • Loading branch information
Scott Davis committed Jun 30, 2009
1 parent 4053a9e commit 8890041
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 20 deletions.
10 changes: 7 additions & 3 deletions bin/generate
Expand Up @@ -23,8 +23,12 @@


case 'model':
//Generator::model();
echo "HI NOT YET!";
if(isset($argv[3])) {
$parent = $argv[3];
}else{
$parent = '';
}
Generator::model($argv[2], $parent);
break;


Expand All @@ -34,7 +38,7 @@
echo "maybe tomarrow";
break;
case 'unit':
echo 'some day';
Generator::unit_test($argv[2]);
break;

}
Expand Down
54 changes: 50 additions & 4 deletions generators/lib/generator.php
Expand Up @@ -74,12 +74,58 @@ public static function route($path) {
public static function r404($path) {
copy(FileUtils::join(TEMPLATE_PATH, 'r404.tmpl'), $path);
}
/**
* Creates a Nimble Unit Test Case
* @param string $name name of test
*/

public static function unit_test($name) {
$class_name = Inflector::classify($name);
$path = FileUtils::join(NIMBLE_ROOT, 'test', 'unit');

$string = "<?php \n";
$string .= " /**\n * @package unit_test\n * */\n";
$string .= " class {$class_name} extends NimblePHPUnitTestCase";
$string .= " { \n\n";
$string .= " }\n";
$string .= "?>";

FileUtils::mkdir_p($path);
$file = fopen(FileUtils::join($path, $class_name . 'Test.php'), "w");
fwrite($file, $string);
fclose($path);
}

/**
* Creates a model class with option of a parent to extend
* @param string $name the name of the class
* @param string $parent the parent class you with to extend with this model
*
*/
public static function model($name, $parent='') {
$class_name = Inflector::classify($name);
$path = FileUtils::join(NIMBLE_ROOT, 'app', 'model', $class_name . '.php');
$string = "<?php \n";
$string .= " /**\n * @package model\n * */\n";
$string .= " class {$class_name}";
if(!empty($parent)) {
$string .= "extends $parent";
}
$string .= " { \n\n";
$string .= " }\n";
$string .= "?>";

$file = fopen($path, "w");
fwrite($file, $string);
fclose($path);

}

/**
* Creates a controller and its associated views ex. add, create, update, show, index, delete
* @todo need to add name space support
* @param string $name - suffix you want the name the controller
*/
* Creates a controller and its associated views ex. add, create, update, show, index, delete
* @todo need to add name space support
* @param string $name - suffix you want the name the controller
*/
public static function controller($name) {
$class_name = Inflector::classify($name);
$path_name = FileUtils::join(NIMBLE_ROOT, 'app', 'controller', $class_name . 'Controller.php');
Expand Down
24 changes: 12 additions & 12 deletions lib/base.php
Expand Up @@ -21,17 +21,17 @@ class Nimble

function __construct()
{
$this->url = (isset($_GET['url'])) ? trim($_GET['url'], '/') : '';
/** set default configs */
$this->config['title_seperator'] = ':';
$this->config['default_layout'] = '';
$this->config['uri'] = str_replace(basename($_SERVER['PHP_SELF']), '', $_SERVER['PHP_SELF']);
$this->page_title = '';
if(!$this->test_mode) {
if(isset($_SESSION) && !isset($_SESSION['flashes'])) {
$_SESSION['flashes'] = array();
$this->url = (isset($_GET['url'])) ? trim($_GET['url'], '/') : '';
/** set default configs */
$this->config['title_seperator'] = ':';
$this->config['default_layout'] = '';
$this->config['uri'] = str_replace(basename($_SERVER['PHP_SELF']), '', $_SERVER['PHP_SELF']);
$this->page_title = '';
if(!$this->test_mode) {
if(isset($_SESSION) && !isset($_SESSION['flashes'])) {
$_SESSION['flashes'] = array();
}
}
}
}

/**
Expand Down Expand Up @@ -86,9 +86,9 @@ public function dispatch($test=false)
$_SERVER['REQUEST_METHOD'] = strtoupper($_POST['_method']);
}

// test to see if its a valid route
/** test to see if its a valid route */
if (preg_match($conf[0], $this->url, $matches) && $_SERVER['REQUEST_METHOD'] == $conf[3]){
// Only declared variables in URL regex
/** Only declared variables in URL regex */
$matches = $this->parse_urls_args($matches);
$this->klass = new $conf[1]();
/** set the layout tempalte to the default */
Expand Down
2 changes: 1 addition & 1 deletion lib/controller.php
Expand Up @@ -62,7 +62,7 @@ public function load_plugins() {
* @param string $method The controller action that is being invoked.
*/
public function run_before_filters($method) {
$this->run_filters('before', $method);
$this->run_filters('before', $method);
}

/**
Expand Down

0 comments on commit 8890041

Please sign in to comment.