Add dir option and fix namespace for models

This commit is contained in:
Barry vd. Heuvel
2013-05-30 21:22:00 +02:00
parent 3ac68d5446
commit 3afc4a3ade
@@ -40,8 +40,8 @@ class ModelsCommand extends Command {
protected $properties = array(); protected $properties = array();
protected $methods = array(); protected $methods = array();
protected $write = false; protected $write = false;
protected $dir;
@@ -54,6 +54,7 @@ class ModelsCommand extends Command {
{ {
$filename = $this->option('filename'); $filename = $this->option('filename');
$this->write = $this->option('write'); $this->write = $this->option('write');
$this->dir = $this->option('dir');
$model = $this->argument('model'); $model = $this->argument('model');
$content = $this->generateDocs($model); $content = $this->generateDocs($model);
@@ -67,8 +68,6 @@ class ModelsCommand extends Command {
} }
} }
} }
@@ -94,6 +93,7 @@ class ModelsCommand extends Command {
{ {
return array( return array(
array('filename', 'F', InputOption::VALUE_OPTIONAL, 'The path to the helper file', '_ide_helper_models.php'), array('filename', 'F', InputOption::VALUE_OPTIONAL, 'The path to the helper file', '_ide_helper_models.php'),
array('dir', 'D', InputOption::VALUE_OPTIONAL, 'The model dir', app_path().'/models'),
array('write', 'W', InputOption::VALUE_NONE, 'Write to Model file'), array('write', 'W', InputOption::VALUE_NONE, 'Write to Model file'),
); );
} }
@@ -141,8 +141,12 @@ class ModelsCommand extends Command {
protected function loadModels(){ protected function loadModels(){
$dir = $this->dir;
if(!file_exists($dir)){
$dir = base_path().'/'.$dir;
}
$models = array(); $models = array();
foreach(ClassMapGenerator::createMap(app_path().'/models') as $model=> $path){ foreach(ClassMapGenerator::createMap($dir) as $model=> $path){
$models[] = $model; $models[] = $model;
} }
return $models; return $models;
@@ -305,6 +309,7 @@ class ModelsCommand extends Command {
$reflection = new \ReflectionClass($class); $reflection = new \ReflectionClass($class);
$namespace = $reflection->getNamespaceName(); $namespace = $reflection->getNamespaceName();
$classname = $reflection->getShortName();
$originalDoc = $reflection->getDocComment(); $originalDoc = $reflection->getDocComment();
$phpdoc = new DocBlock($reflection, new Context($namespace)); $phpdoc = new DocBlock($reflection, new Context($namespace));
@@ -359,8 +364,8 @@ class ModelsCommand extends Command {
if($originalDoc){ if($originalDoc){
$contents = str_replace($originalDoc, $docComment, $contents); $contents = str_replace($originalDoc, $docComment, $contents);
}else{ }else{
$needle = "class {$class}"; $needle = "class {$classname}";
$replace = "{$docComment}\nclass {$class}"; $replace = "{$docComment}\nclass {$classname}";
$pos = strpos($contents,$needle); $pos = strpos($contents,$needle);
if ($pos !== false) { if ($pos !== false) {
$contents = substr_replace($contents,$replace,$pos,strlen($needle)); $contents = substr_replace($contents,$replace,$pos,strlen($needle));
@@ -371,7 +376,7 @@ class ModelsCommand extends Command {
} }
} }
$output = "namespace {$namespace}{\n{$docComment}\n\tclass {$class} {}\n}\n\n"; $output = "namespace {$namespace}{\n{$docComment}\n\tclass {$classname} {}\n}\n\n";
return $output; return $output;
} }