@@ -7,27 +7,27 @@ |
||
| 7 | 7 | |
| 8 | 8 | class TemplateLoader { |
| 9 | 9 | |
| 10 | - protected $fs; |
|
| 10 | + protected $fs; |
|
| 11 | 11 | |
| 12 | - protected $loaded; |
|
| 12 | + protected $loaded; |
|
| 13 | 13 | |
| 14 | - public function __construct(Filesystem $fs) |
|
| 15 | - { |
|
| 16 | - $this->fs = $fs; |
|
| 17 | - $this->loaded = []; |
|
| 18 | - } |
|
| 14 | + public function __construct(Filesystem $fs) |
|
| 15 | + { |
|
| 16 | + $this->fs = $fs; |
|
| 17 | + $this->loaded = []; |
|
| 18 | + } |
|
| 19 | 19 | |
| 20 | - public function load($name) |
|
| 21 | - { |
|
| 22 | - if(! isset($this->loaded[$name])){ |
|
| 23 | - $path = __DIR__ . "/../../templates/{$name}.wnt"; |
|
| 24 | - try { |
|
| 25 | - $this->loaded[$name] = $this->fs->get($path); |
|
| 26 | - } catch(\Exception $e) { |
|
| 27 | - throw new TemplateException("Unable to read the file '{$path}'"); |
|
| 28 | - } |
|
| 29 | - } |
|
| 30 | - return new Template($this, $this->loaded[$name]); |
|
| 31 | - } |
|
| 20 | + public function load($name) |
|
| 21 | + { |
|
| 22 | + if(! isset($this->loaded[$name])){ |
|
| 23 | + $path = __DIR__ . "/../../templates/{$name}.wnt"; |
|
| 24 | + try { |
|
| 25 | + $this->loaded[$name] = $this->fs->get($path); |
|
| 26 | + } catch(\Exception $e) { |
|
| 27 | + throw new TemplateException("Unable to read the file '{$path}'"); |
|
| 28 | + } |
|
| 29 | + } |
|
| 30 | + return new Template($this, $this->loaded[$name]); |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | 33 | } |
| 34 | 34 | \ No newline at end of file |
@@ -5,58 +5,58 @@ |
||
| 5 | 5 | |
| 6 | 6 | class Template { |
| 7 | 7 | |
| 8 | - protected $loader; |
|
| 9 | - |
|
| 10 | - protected $text; |
|
| 11 | - |
|
| 12 | - protected $data; |
|
| 13 | - |
|
| 14 | - protected $compiled; |
|
| 15 | - |
|
| 16 | - protected $dirty; |
|
| 17 | - |
|
| 18 | - public function __construct(TemplateLoader $loader, $text) |
|
| 19 | - { |
|
| 20 | - $this->loader = $loader; |
|
| 21 | - $this->text = $text; |
|
| 22 | - $this->compiled = ''; |
|
| 23 | - $this->data = []; |
|
| 24 | - $this->dirty = true; |
|
| 25 | - } |
|
| 26 | - |
|
| 27 | - public function clean() |
|
| 28 | - { |
|
| 29 | - $this->data = []; |
|
| 30 | - $this->dirty = false; |
|
| 31 | - return $this; |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - public function with($data = []) |
|
| 35 | - { |
|
| 36 | - if($data) |
|
| 37 | - $this->dirty = true; |
|
| 38 | - foreach ($data as $key => $value) { |
|
| 39 | - $this->data[$key] = $value; |
|
| 40 | - } |
|
| 41 | - return $this; |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - public function get() |
|
| 45 | - { |
|
| 46 | - if($this->dirty){ |
|
| 47 | - $this->compile(); |
|
| 48 | - $this->dirty = false; |
|
| 49 | - } |
|
| 50 | - return $this->compiled; |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - public function compile() |
|
| 54 | - { |
|
| 55 | - $this->compiled = $this->text; |
|
| 56 | - foreach($this->data as $key => $value){ |
|
| 57 | - $this->compiled = str_replace('{{' . $key . '}}', $value, $this->compiled); |
|
| 58 | - } |
|
| 59 | - return $this; |
|
| 60 | - } |
|
| 8 | + protected $loader; |
|
| 9 | + |
|
| 10 | + protected $text; |
|
| 11 | + |
|
| 12 | + protected $data; |
|
| 13 | + |
|
| 14 | + protected $compiled; |
|
| 15 | + |
|
| 16 | + protected $dirty; |
|
| 17 | + |
|
| 18 | + public function __construct(TemplateLoader $loader, $text) |
|
| 19 | + { |
|
| 20 | + $this->loader = $loader; |
|
| 21 | + $this->text = $text; |
|
| 22 | + $this->compiled = ''; |
|
| 23 | + $this->data = []; |
|
| 24 | + $this->dirty = true; |
|
| 25 | + } |
|
| 26 | + |
|
| 27 | + public function clean() |
|
| 28 | + { |
|
| 29 | + $this->data = []; |
|
| 30 | + $this->dirty = false; |
|
| 31 | + return $this; |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + public function with($data = []) |
|
| 35 | + { |
|
| 36 | + if($data) |
|
| 37 | + $this->dirty = true; |
|
| 38 | + foreach ($data as $key => $value) { |
|
| 39 | + $this->data[$key] = $value; |
|
| 40 | + } |
|
| 41 | + return $this; |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + public function get() |
|
| 45 | + { |
|
| 46 | + if($this->dirty){ |
|
| 47 | + $this->compile(); |
|
| 48 | + $this->dirty = false; |
|
| 49 | + } |
|
| 50 | + return $this->compiled; |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + public function compile() |
|
| 54 | + { |
|
| 55 | + $this->compiled = $this->text; |
|
| 56 | + foreach($this->data as $key => $value){ |
|
| 57 | + $this->compiled = str_replace('{{' . $key . '}}', $value, $this->compiled); |
|
| 58 | + } |
|
| 59 | + return $this; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | 62 | } |
| 63 | 63 | \ No newline at end of file |
@@ -3,11 +3,11 @@ |
||
| 3 | 3 | |
| 4 | 4 | class RouteCommand extends BaseCommand { |
| 5 | 5 | |
| 6 | - protected $signature = 'wn:route |
|
| 6 | + protected $signature = 'wn:route |
|
| 7 | 7 | {resource : Name of the resource.} |
| 8 | 8 | {--controller= : Name of the RESTful controller.}'; |
| 9 | 9 | |
| 10 | - protected $description = 'Generates RESTful routes.'; |
|
| 10 | + protected $description = 'Generates RESTful routes.'; |
|
| 11 | 11 | |
| 12 | 12 | public function handle() |
| 13 | 13 | { |
@@ -3,7 +3,7 @@ discard block |
||
| 3 | 3 | |
| 4 | 4 | class ModelCommand extends BaseCommand { |
| 5 | 5 | |
| 6 | - protected $signature = 'wn:model |
|
| 6 | + protected $signature = 'wn:model |
|
| 7 | 7 | {name : Name of the model.} |
| 8 | 8 | {--fillable= : the fillable fields.} |
| 9 | 9 | {--dates= : date fields.} |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | {--force= : override the existing files} |
| 19 | 19 | '; |
| 20 | 20 | |
| 21 | - protected $description = 'Generates a model class for a RESTfull resource'; |
|
| 21 | + protected $description = 'Generates a model class for a RESTfull resource'; |
|
| 22 | 22 | |
| 23 | 23 | public function handle() |
| 24 | 24 | { |
@@ -42,9 +42,9 @@ discard block |
||
| 42 | 42 | |
| 43 | 43 | protected function getAsArrayFields($arg, $isOption = true) |
| 44 | 44 | { |
| 45 | - $arg = ($isOption) ? $this->option($arg) : $this->argument($arg); |
|
| 45 | + $arg = ($isOption) ? $this->option($arg) : $this->argument($arg); |
|
| 46 | 46 | if(is_string($arg)){ |
| 47 | - $arg = explode(',', $arg); |
|
| 47 | + $arg = explode(',', $arg); |
|
| 48 | 48 | } else if(! is_array($arg)) { |
| 49 | 49 | $arg = []; |
| 50 | 50 | } |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | |
| 56 | 56 | protected function getNamespace() |
| 57 | 57 | { |
| 58 | - return str_replace(' ', '\\', ucwords(str_replace('/', ' ', $this->option('path')))); |
|
| 58 | + return str_replace(' ', '\\', ucwords(str_replace('/', ' ', $this->option('path')))); |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | protected function getRelations() |
@@ -3,10 +3,10 @@ |
||
| 3 | 3 | |
| 4 | 4 | class ControllerRestActionsCommand extends BaseCommand { |
| 5 | 5 | |
| 6 | - protected $signature = 'wn:controller:rest-actions |
|
| 6 | + protected $signature = 'wn:controller:rest-actions |
|
| 7 | 7 | {--force= : override the existing files}'; |
| 8 | 8 | |
| 9 | - protected $description = 'Generates REST actions trait to use into controllers'; |
|
| 9 | + protected $description = 'Generates REST actions trait to use into controllers'; |
|
| 10 | 10 | |
| 11 | 11 | public function handle() |
| 12 | 12 | { |
@@ -3,32 +3,32 @@ |
||
| 3 | 3 | |
| 4 | 4 | class ControllerCommand extends BaseCommand { |
| 5 | 5 | |
| 6 | - protected $signature = 'wn:controller |
|
| 6 | + protected $signature = 'wn:controller |
|
| 7 | 7 | {model : Name of the model (with namespace if not App)} |
| 8 | 8 | {--no-routes= : without routes} |
| 9 | 9 | {--force= : override the existing files} |
| 10 | 10 | '; |
| 11 | 11 | |
| 12 | - protected $description = 'Generates RESTful controller using the RESTActions trait'; |
|
| 12 | + protected $description = 'Generates RESTful controller using the RESTActions trait'; |
|
| 13 | 13 | |
| 14 | 14 | public function handle() |
| 15 | 15 | { |
| 16 | - $model = $this->argument('model'); |
|
| 17 | - $name = ''; |
|
| 18 | - if(strrpos($model, "\\") === false){ |
|
| 19 | - $name = $model; |
|
| 20 | - $model = "App\\" . $model; |
|
| 21 | - } else { |
|
| 22 | - $name = explode("\\", $model); |
|
| 23 | - $name = $name[count($name) - 1]; |
|
| 24 | - } |
|
| 16 | + $model = $this->argument('model'); |
|
| 17 | + $name = ''; |
|
| 18 | + if(strrpos($model, "\\") === false){ |
|
| 19 | + $name = $model; |
|
| 20 | + $model = "App\\" . $model; |
|
| 21 | + } else { |
|
| 22 | + $name = explode("\\", $model); |
|
| 23 | + $name = $name[count($name) - 1]; |
|
| 24 | + } |
|
| 25 | 25 | $controller = ucwords(str_plural($name)) . 'Controller'; |
| 26 | 26 | $content = $this->getTemplate('controller') |
| 27 | - ->with([ |
|
| 28 | - 'name' => $controller, |
|
| 29 | - 'model' => $model |
|
| 30 | - ]) |
|
| 31 | - ->get(); |
|
| 27 | + ->with([ |
|
| 28 | + 'name' => $controller, |
|
| 29 | + 'model' => $model |
|
| 30 | + ]) |
|
| 31 | + ->get(); |
|
| 32 | 32 | |
| 33 | 33 | $this->save($content, "./app/Http/Controllers/{$controller}.php", "{$controller}"); |
| 34 | 34 | |
@@ -3,13 +3,13 @@ |
||
| 3 | 3 | |
| 4 | 4 | class SeederCommand extends BaseCommand { |
| 5 | 5 | |
| 6 | - protected $signature = 'wn:seeder |
|
| 6 | + protected $signature = 'wn:seeder |
|
| 7 | 7 | {model : full qualified name of the model.} |
| 8 | 8 | {--count=10 : number of elements to add in database.} |
| 9 | 9 | {--force= : override the existing files} |
| 10 | 10 | '; |
| 11 | 11 | |
| 12 | - protected $description = 'Generates a seeder'; |
|
| 12 | + protected $description = 'Generates a seeder'; |
|
| 13 | 13 | |
| 14 | 14 | public function handle() |
| 15 | 15 | { |
@@ -10,10 +10,10 @@ |
||
| 10 | 10 | class BaseCommand extends Command { |
| 11 | 11 | |
| 12 | 12 | protected $fs; |
| 13 | - protected $templates; |
|
| 13 | + protected $templates; |
|
| 14 | 14 | |
| 15 | - public function __construct(Filesystem $fs) |
|
| 16 | - { |
|
| 15 | + public function __construct(Filesystem $fs) |
|
| 16 | + { |
|
| 17 | 17 | parent::__construct(); |
| 18 | 18 | |
| 19 | 19 | $this->fs = $fs; |
@@ -3,7 +3,7 @@ discard block |
||
| 3 | 3 | |
| 4 | 4 | class FactoryCommand extends BaseCommand { |
| 5 | 5 | |
| 6 | - protected $signature = 'wn:factory |
|
| 6 | + protected $signature = 'wn:factory |
|
| 7 | 7 | {model : full qualified name of the model.} |
| 8 | 8 | {--fields= : the fields to generate.} |
| 9 | 9 | {--file= : the factories file.} |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | {--force= : override the existing files} |
| 12 | 12 | '; |
| 13 | 13 | |
| 14 | - protected $description = 'Generates a model factory'; |
|
| 14 | + protected $description = 'Generates a model factory'; |
|
| 15 | 15 | |
| 16 | 16 | public function handle() |
| 17 | 17 | { |