Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.6] Adds --api flag to make:controller #22996

Merged
merged 9 commits into from
Feb 3, 2018
18 changes: 14 additions & 4 deletions src/Illuminate/Routing/Console/ControllerMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,23 @@ class ControllerMakeCommand extends GeneratorCommand
*/
protected function getStub()
{
$stub = null;

if ($this->option('parent')) {
return __DIR__.'/stubs/controller.nested.stub';
$stub = '/stubs/controller.nested.stub';
} elseif ($this->option('model')) {
return __DIR__.'/stubs/controller.model.stub';
$stub = '/stubs/controller.model.stub';
} elseif ($this->option('resource')) {
return __DIR__.'/stubs/controller.stub';
$stub = '/stubs/controller.stub';
}

if ($this->option('api') && $stub !== null) {
$stub = substr_replace($stub, '.api', -5, 0);
}

return __DIR__.'/stubs/controller.plain.stub';
$stub = $stub ?? '/stubs/controller.plain.stub';

return __DIR__.$stub;
}

/**
Expand Down Expand Up @@ -167,6 +175,8 @@ protected function getOptions()
['resource', 'r', InputOption::VALUE_NONE, 'Generate a resource controller class.'],

['parent', 'p', InputOption::VALUE_OPTIONAL, 'Generate a nested resource controller class.'],

['api', 'a', InputOption::VALUE_NONE, 'Generate api resource methods only for a controller class.'],
];
}
}
64 changes: 64 additions & 0 deletions src/Illuminate/Routing/Console/stubs/controller.api.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

namespace DummyNamespace;

use Illuminate\Http\Request;
use DummyRootNamespaceHttp\Controllers\Controller;

class DummyClass extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
//
}

/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//
}

/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
//
}

/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//
}

/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}
}
65 changes: 65 additions & 0 deletions src/Illuminate/Routing/Console/stubs/controller.model.api.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

namespace DummyNamespace;

use DummyFullModelClass;
use Illuminate\Http\Request;
use DummyRootNamespaceHttp\Controllers\Controller;

class DummyClass extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
//
}

/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//
}

/**
* Display the specified resource.
*
* @param \DummyFullModelClass $DummyModelVariable
* @return \Illuminate\Http\Response
*/
public function show(DummyModelClass $DummyModelVariable)
{
//
}

/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \DummyFullModelClass $DummyModelVariable
* @return \Illuminate\Http\Response
*/
public function update(Request $request, DummyModelClass $DummyModelVariable)
{
//
}

/**
* Remove the specified resource from storage.
*
* @param \DummyFullModelClass $DummyModelVariable
* @return \Illuminate\Http\Response
*/
public function destroy(DummyModelClass $DummyModelVariable)
{
//
}
}
71 changes: 71 additions & 0 deletions src/Illuminate/Routing/Console/stubs/controller.nested.api.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

namespace DummyNamespace;

use DummyFullModelClass;
use ParentDummyFullModelClass;
use Illuminate\Http\Request;
use DummyRootNamespaceHttp\Controllers\Controller;

class DummyClass extends Controller
{
/**
* Display a listing of the resource.
*
* @param \ParentDummyFullModelClass $ParentDummyModelVariable
* @return \Illuminate\Http\Response
*/
public function index(ParentDummyModelClass $ParentDummyModelVariable)
{
//
}

/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \ParentDummyFullModelClass $ParentDummyModelVariable
* @return \Illuminate\Http\Response
*/
public function store(Request $request, ParentDummyModelClass $ParentDummyModelVariable)
{
//
}

/**
* Display the specified resource.
*
* @param \ParentDummyFullModelClass $ParentDummyModelVariable
* @param \DummyFullModelClass $DummyModelVariable
* @return \Illuminate\Http\Response
*/
public function show(ParentDummyModelClass $ParentDummyModelVariable, DummyModelClass $DummyModelVariable)
{
//
}

/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \ParentDummyFullModelClass $ParentDummyModelVariable
* @param \DummyFullModelClass $DummyModelVariable
* @return \Illuminate\Http\Response
*/
public function update(Request $request, ParentDummyModelClass $ParentDummyModelVariable, DummyModelClass $DummyModelVariable)
{
//
}

/**
* Remove the specified resource from storage.
*
* @param \ParentDummyFullModelClass $ParentDummyModelVariable
* @param \DummyFullModelClass $DummyModelVariable
* @return \Illuminate\Http\Response
*/
public function destroy(ParentDummyModelClass $ParentDummyModelVariable, DummyModelClass $DummyModelVariable)
{
//
}
}