Skip to content

Commit

Permalink
Responses
Browse files Browse the repository at this point in the history
  • Loading branch information
EsdertCO committed Sep 16, 2020
1 parent 4d74b86 commit 584887a
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Config/laravel-stubs.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@
'interface' => [
'namespace' => '\App\Interfaces'
],
/**
* make:response
*
* Allows you to change the namespace (and so the folder) where the response will be stored
*/
'response' => [
'namespace' => '\App\Http\Responses'
],
/**
* make:scope
*
Expand Down
60 changes: 60 additions & 0 deletions src/Console/Make/MakeResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

namespace Creativeorange\LaravelStubs\Console\Make;

use Creativeorange\LaravelStubs\Console\CustomGeneratorCommand;
use Illuminate\Support\Str;
use Symfony\Component\Console\Input\InputArgument;

class MakeResponse extends CustomGeneratorCommand
{

/**
* The name and signature of the console command.
*
* @var string
*/
protected $name = 'make:response';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Create a new response';

protected $signature = 'make:response
{name : The name of the response}';

protected $type = 'Response';

protected function getStub()
{
return $this->resolveStubPath('/../stubs/response.stub');
}

protected function getDefaultNamespace($rootNamespace)
{
return (empty(config('laravel-stubs.make.response.namespace')))
? $rootNamespace
: config('laravel-stubs.make.response.namespace');
}

protected function getNameInput()
{
$name = trim($this->argument('name'));

$name = Str::endsWith($name, 'Response')
? $name
: $name . 'Response';

return $name;
}

protected function getArguments()
{
return [
['name', InputArgument::REQUIRED, 'The name of the response']
];
}
}
1 change: 1 addition & 0 deletions src/LaravelStubsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function boot()
Console\Make\MakeViewComposer::class,
Console\Make\MakeFacade::class,
Console\Make\MakeHelper::class,
Console\Make\MakeResponse::class,
/** Patch */
Console\Patch::class,
/** Publish */
Expand Down
21 changes: 21 additions & 0 deletions src/stubs/response.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace DummyNamespace;

use Illuminate\Contracts\Support\Responsable;

class DummyClass implements Responsable
{

/**
* Create an HTTP response that represents the object.
*
* @param \Illuminate\Http\Request $request
* @return \Symfony\Component\HttpFoundation\Response
*/
public function toResponse($request)
{
return \response();
}

}

0 comments on commit 584887a

Please sign in to comment.