PHP code example of shomisha / stubless

1. Go to this page and download the library: Download shomisha/stubless library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

shomisha / stubless example snippets




pp\Http\Controllers\Controller;
use App\Http\Requests\UserRequest;
use App\Models\User;
use Illuminate\Http\Request;
use Shomisha\Stubless\Templates\Argument;
use Shomisha\Stubless\Templates\ClassMethod;
use Shomisha\Stubless\Templates\ClassTemplate;
use Shomisha\Stubless\Utilities\Importable;

$class = ClassTemplate::name('UsersController')->extends(new Importable(Controller::class))->setNamespace('App\Http\Controllers');

$requestArgument = Argument::name('request')->type(new Importable(Request::class));
$userArgument = Argument::name('user')->type(new Importable(User::class));
$userRequestArgument = Argument::name('request')->type(new Importable(UserRequest::class));

$class->withMethods([
	ClassMethod::name('index')->addArgument($requestArgument),
	ClassMethod::name('show')->withArguments([
		$requestArgument,
		$userArgument,
	]),
	ClassMethod::name('store')->addArgument($userRequestArgument),
	ClassMethod::name('update')->withArguments([
		$userRequestArgument,
		$userArgument,
	]),
	ClassMethod::name('destroy')->addArgument($userArgument),
]);

echo $class->print();



namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use App\Http\Requests\UserRequest;
use App\Models\User;
use Illuminate\Http\Request;

class UsersController extends Controller
{
    public function index(Request $request)
    {
    }

    public function show(Request $request, User $user)
    {
    }

    public function store(UserRequest $request)
    {
    }

    public function update(UserRequest $request, User $user)
    {
    }

    public function destroy(User $user)
    {
    }
}