-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
323f412
commit b943b98
Showing
5 changed files
with
115 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
|
||
namespace Lomkit\Rest\Console\Commands; | ||
|
||
use Illuminate\Console\GeneratorCommand; | ||
use Illuminate\Contracts\Console\PromptsForMissingInput; | ||
use Illuminate\Database\Migrations\MigrationCreator; | ||
use Illuminate\Support\Composer; | ||
use Illuminate\Support\Str; | ||
use Lomkit\Rest\Console\ResolvesStubPath; | ||
|
||
class ResponseCommand extends GeneratorCommand implements PromptsForMissingInput | ||
{ | ||
use ResolvesStubPath; | ||
|
||
/** | ||
* The console command signature. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'rest:response {name : The name of the response} | ||
{--path= : The location where the response file should be created}'; | ||
|
||
/** | ||
* The type of class being generated. | ||
* | ||
* @var string | ||
*/ | ||
protected $type = 'Response'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Create a new response class'; | ||
|
||
public function handle() | ||
{ | ||
parent::handle(); | ||
} | ||
|
||
/** | ||
* Build the class with the given name. | ||
* | ||
* @param string $name | ||
* @return string | ||
*/ | ||
protected function buildClass($name) | ||
{ | ||
$replace = []; | ||
|
||
return str_replace( | ||
array_keys($replace), array_values($replace), parent::buildClass($name) | ||
); | ||
} | ||
|
||
/** | ||
* Get the stub file for the generator. | ||
* | ||
* @return string | ||
*/ | ||
protected function getStub() | ||
{ | ||
return $this->resolveStubPath('/stubs/rest/response.stub'); | ||
} | ||
|
||
/** | ||
* Get the default namespace for the class. | ||
* | ||
* @param string $rootNamespace | ||
* @return string | ||
*/ | ||
protected function getDefaultNamespace($rootNamespace) | ||
{ | ||
return $rootNamespace.'\Rest\Responses'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace {{ namespace }}; | ||
|
||
use Lomkit\Rest\Http\Response as RestResponse; | ||
|
||
class {{ class }} extends RestResponse | ||
{ | ||
/** | ||
* This map on each model returned by the API, use it at your ease. | ||
* | ||
* @var \Illuminate\Database\Eloquent\Model $model | ||
* @var array $responseModel | ||
* | ||
* @return array | ||
*/ | ||
protected function map(\Illuminate\Database\Eloquent\Model $model, array $responseModel) : array { | ||
return $responseModel; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters