jms/cg
jms/cg is a PHP code generation library that builds classes, methods, and properties programmatically. It provides a fluent API plus reflection and metadata support to generate readable source code, useful for proxies, serializers, and other build-time tooling.
jms/cg) is a code generation toolset designed to automate boilerplate PHP class creation (e.g., entities, repositories, services). It aligns well with Domain-Driven Design (DDD) or CRUD-heavy applications where repetitive patterns (e.g., Doctrine entities, API resources) are common.make:model, make:controller, or packages like Laravel Shift or Inertia.composer.json.jms/cg generators, but this requires custom development.make:model?php-compat) or is a fork necessary?maker-bundle)?Entity, Repository, Service layers).jms/cg with Laravel-specific configurations:
// app/Console/Commands/GenerateEntity.php
use JMS\CG\Generator\Generator;
use JMS\CG\Template\Template;
class GenerateEntity extends Command {
protected $signature = 'make:entity {name}';
protected $description = 'Generate a DDD entity with jms/cg';
public function handle() {
$generator = new Generator();
$template = new Template(__DIR__.'/../../templates/entity.twig');
$generator->generate($template, ['name' => $this->argument('name')]);
}
}
Entity.php.twig, Repository.php.twig) in resources/templates/.Entity.php.twig:
{% extends 'base.php.twig' %}
{% block class %}
namespace App\\Entities;
use Illuminate\\Database\\Eloquent\\Model;
use Illuminate\\Notifications\\Notifiable;
class {{ name }} extends Model
{
use Notifiable;
// ...
}
{% endblock %}
post-install or post-update:
"scripts": {
"post-install-cmd": [
"php artisan make:entity User"
]
}
git push to dev branch.^9.5 in composer.json to avoid conflicts.twig/twig as a dev dependency.make:migration or a custom solution.make:entity, make:repository).make:service).make:resource).jms/cg, Twig, and Laravel’s autoloader.How can I help you explore Laravel packages today?