1. Go to this page and download the library: Download nexus4812/php-class-gen 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/ */
nexus4812 / php-class-gen example snippets
use PhpGen\ClassGenerator\Config\PhpGenConfig;
use PhpGen\ClassGenerator\Console\Commands\Example\Laravel\LaravelCqrsQueryCommand;
return PhpGenConfig::configure()
->withCommands([
LaravelCqrsQueryCommand::class,
])
->withComposerAutoload() // Load PSR-4 mappings from composer.json
->withStrictTypes(true); // Add strict types to generated code
namespace App\Commands;
use PhpGen\ClassGenerator\Blueprint\FileBlueprint;
use PhpGen\ClassGenerator\Console\Commands\Command;
use PhpGen\ClassGenerator\Core\Project;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
#[AsCommand(name: 'generate:service', description: 'Generate service class')]
final class ServiceGeneratorCommand extends Command
{
protected function handle(InputInterface $input, OutputInterface $output): Project
{
$project = new Project();
// Add files to generate
$project->add(
FileBlueprint::createEmptyClass('App\\Services\\UserService')
->defineStructure(function ($class) {
$class->setFinal();
$class->addMethod('__construct')->setPublic();
return $class;
})
);
return $project;
}
}