Библиотека-генератор php классов (файлов)?

Коллеги, здравствуйте!
Существует ли какая нибудь библиотека для генерации php класса-файла.

Например:

Имя класса
перечисляю базовые методы заглушки
...
Всё как обычно руками происходит.

На выходе получаем например

<?php

namespace App\Http\Controller\Api;



/**
 * Class IndexController
 * @package App\Http\Controller\Api
 */
class IndexController
{


    public function index()
    {
        echo "The Core greets you!";
    }
}


Спасибо!
  • Вопрос задан
  • 149 просмотров
Решения вопроса 1
IgorPI
@IgorPI Автор вопроса
Всё проще, чем я ожидал.

На примере "Laravel"

Файл app/Console/Commands/stubs/controller.stub

<?php

namespace DummyNamespace;

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

class DummyClass extends Controller
{
	public $user;

	/**
	 * DummyClass constructor.
	 */
	public function __construct()
	{
		$this->middleware(['auth:api', 'role:admin|organizer|prof_organizer'])->only(['store', 'update', 'destroy']);

		$this->user = \Auth::guard('api')->user();
	}

	/**
	 * 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)
	{
		//
	}
}


Класс генератор
<?php

namespace App\Console\Commands;

use Illuminate\Console\GeneratorCommand;
use Symfony\Component\Console\Input\InputOption;

class MakeController extends GeneratorCommand
{
	/**
	 * The console command name.
	 *
	 * @var string
	 */
	protected $name = 'make:controller';

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

	/**
	 * The type of class being generated.
	 *
	 * @var string
	 */
	protected $type = 'Controller';
	
	/**
	 * Get the stub file for the generator.
	 *
	 * @return string
	 */
	protected function getStub()
	{
		return __DIR__.'/stubs/controller.stub';
	}

	/**
	 * Get the default namespace for the class.
	 *
	 * @param  string  $rootNamespace
	 * @return string
	 */
	protected function getDefaultNamespace($rootNamespace)
	{
		return $rootNamespace."\\Http\\Controllers\\Api";
	}
}
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы
YCLIENTS Москва
от 200 000 до 350 000 ₽
Ведисофт Екатеринбург
от 25 000 ₽
ИТЦ Аусферр Магнитогорск
от 100 000 до 160 000 ₽
25 апр. 2024, в 12:23
2500 руб./за проект
25 апр. 2024, в 12:21
10000 руб./за проект