Compare commits

...
5 Commits
Author SHA1 Message Date
Barry vd. Heuvel f77f5ae770 Disable where field
Maybe make it optional? Feels kind of bloated..
2014-04-25 13:47:00 +02:00
Barry vd. Heuvel 82ffa52d79 Merge pull request #77 from ukautz/feature-polymorphic
Added property methods for polymorphic relations
2014-04-22 14:29:06 +02:00
Ulrich Kautz d8ed55be7a Added property methods for polymorphic relations 2014-04-22 14:25:44 +02:00
Barry vd. Heuvel 16f77638f1 Move helpers to root
To get them in the namespace.
2014-03-20 16:20:31 +01:00
Barry vd. Heuvel 348ecb361c Fix helper files.
Fixes #72
2014-03-20 16:15:55 +01:00
2 changed files with 14 additions and 12 deletions
@@ -193,23 +193,25 @@ class GeneratorCommand extends Command {
} }
} }
foreach ($output as $ns => $body){
if ($ns == '__root') $ns = '';
$outputString .= "namespace $ns{\n";
$outputString .= $body;
$outputString .= "}\n\n";
}
//Include the helper file, if requested //Include the helper file, if requested
if(!empty($this->helpers)){ if(!empty($this->helpers)){
foreach($this->helpers as $helper){ foreach($this->helpers as $helper){
if (file_exists($helper)){ if (file_exists($helper)){
$output .= str_replace(array('<?php', '?>'), '', \File::get($helper)); $output['__root'] .= str_replace(array('<?php', '?>'), '', \File::get($helper));
} }
} }
} }
foreach ($output as $ns => $body){
if ($ns == '__root'){
$ns = '';
}
$outputString .= "namespace $ns{\n";
$outputString .= $body;
$outputString .= "}\n\n";
}
return $outputString; return $outputString;
} }
@@ -237,7 +237,7 @@ class ModelsCommand extends Command {
$this->setProperty($name, $type, true, true); $this->setProperty($name, $type, true, true);
$this->setMethod(Str::camel("where_".$name), '\Illuminate\Database\Query\Builder|\\'.get_class($model), array('$value')); //$this->setMethod(Str::camel("where_".$name), '\Illuminate\Database\Query\Builder|\\'.get_class($model), array('$value'));
} }
} }
} }
@@ -287,14 +287,14 @@ class ModelsCommand extends Command {
$begin = strpos($code, 'function('); $begin = strpos($code, 'function(');
$code = substr($code, $begin, strrpos($code, '}') - $begin + 1); $code = substr($code, $begin, strrpos($code, '}') - $begin + 1);
foreach(array('hasMany', 'belongsToMany', 'hasOne', 'belongsTo') as $relation){ foreach(array('hasMany', 'belongsToMany', 'hasOne', 'belongsTo', 'morphTo', 'morphMany', 'morphToMany') as $relation){
$search = '$this->'.$relation.'('; $search = '$this->'.$relation.'(';
if($pos = stripos($code, $search)){ if($pos = stripos($code, $search)){
$code = substr($code, $pos + strlen($search)); $code = substr($code, $pos + strlen($search));
$arguments = explode(',', substr($code, 0, stripos($code, ')'))); $arguments = explode(',', substr($code, 0, stripos($code, ')')));
//Remove quotes, ensure 1 \ in front of the model //Remove quotes, ensure 1 \ in front of the model
$returnModel = "\\".ltrim(trim($arguments[0], " \"'"), "\\"); $returnModel = "\\".ltrim(trim($arguments[0], " \"'"), "\\");
if($relation === "belongsToMany" or $relation === 'hasMany'){ if($relation === "belongsToMany" or $relation === 'hasMany' or $relation === 'morphMany' or $relation === 'morphToMany'){
//Collection or array of models (because Collection is Arrayable) //Collection or array of models (because Collection is Arrayable)
$this->setProperty($method, '\Illuminate\Database\Eloquent\Collection|'.$returnModel.'[]', true, null); $this->setProperty($method, '\Illuminate\Database\Eloquent\Collection|'.$returnModel.'[]', true, null);
}else{ }else{