Skip to content

Commit

Permalink
Added new 'module:make-request' console command. Fix #155
Browse files Browse the repository at this point in the history
  • Loading branch information
Gravitano committed May 17, 2015
1 parent c5bbf71 commit ab9fc26
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 0 deletions.
71 changes: 71 additions & 0 deletions Commands/MakeRequestCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php namespace Pingpong\Modules\Commands;

use Illuminate\Support\Str;
use Pingpong\Generators\Stub;
use Pingpong\Modules\Traits\ModuleCommandTrait;
use Symfony\Component\Console\Input\InputArgument;

class MakeRequestCommand extends GeneratorCommand {

use ModuleCommandTrait;

/**
* The console command name.
*
* @var string
*/
protected $name = 'module:make-request';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Generate new form request class for the specified module.';

/**
* Get the console command arguments.
*
* @return array
*/
protected function getArguments()
{
return array(
array('name', InputArgument::REQUIRED, 'The name of the form request class.'),
array('module', InputArgument::OPTIONAL, 'The name of module will be used.'),
);
}

/**
* @return mixed
*/
protected function getTemplateContents()
{
return (new Stub('/request.stub', [
'MODULE' => $this->getModuleName(),
'NAME' => $this->getFileName(),
'MODULE_NAMESPACE' => $this->laravel['modules']->config('namespace')
]))->render();
}

/**
* @return mixed
*/
protected function getDestinationFilePath()
{
$path = $this->laravel['modules']->getModulePath($this->getModuleName());

$seederPath = $this->laravel['modules']->config('paths.generator.request');

return $path . $seederPath . '/' . $this->getFileName() . '.php';
}

/**
* @return string
*/
private function getFileName()
{
return Str::studly($this->argument('name'));
}

}
29 changes: 29 additions & 0 deletions Commands/stubs/request.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php namespace $MODULE_NAMESPACE$\$MODULE$\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class $NAME$ extends FormRequest {

/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return false;
}

/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
//
];
}

}
1 change: 1 addition & 0 deletions Providers/ConsoleServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class ConsoleServiceProvider extends ServiceProvider {
'Update',
'Use',
'Dump',
'MakeRequest',
];

/**
Expand Down

0 comments on commit ab9fc26

Please sign in to comment.