Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Source Generator Laravel Package

jumilla/laravel-source-generator

View on GitHub
Deep Wiki
Context7

Getting Started

  1. Install the package (it is archived, so pin the version and expect no upstream fixes):

    composer require jumilla/laravel-source-generator
    

    If the package does not support Laravel auto-discovery, register the service provider manually in config/app.php:

    Jumilla\LaravelSourceGenerator\SourceGeneratorServiceProvider::class,
    
  2. Look first at the package README and src/ directory. Because the package is archived and has no dependents, the README and the generator’s public methods are the authoritative API reference. Identify the primary facade or entry class, then inspect the method chain methods it exposes (namespace, uses, class declaration, properties, methods, file output).

  3. Run a minimal generation first. Create a throwaway Artisan command or tinker session that generates a single class into app/Generated:

    use Jumilla\LaravelSourceGenerator\SourceGenerator;
    
    SourceGenerator::make()
        ->namespace('App\\Generated')
        ->class('ExampleService')
        ->method('handle', function ($method) {
            $method->body('return true;');
        })
        ->save(app_path('Generated/ExampleService.php'));
    

    The first useful use case is scaffolding a small service or DTO class where the shape is repetitive. Once that works, expand the chain to include use statements, constructor injection, and typed properties.

  4. Verify the generated file with php -l and a quick PSR-4 autoload check. If the file loads and the class resolves, the package is wired correctly.

Implementation Patterns

  • Treat the generator as a template engine with a fluent DSL. Build a small internal helper or Artisan command that owns the chain for a given artifact type. For example, create MakeDtoCommand, MakeActionCommand, or MakeRepositoryCommand, each producing a consistent class skeleton. This keeps the method chain out of day-to-day application code.

  • Generate into a dedicated, predictable directory. Use a namespace-to-path convention such as App\Generated\... mapped in composer.json:

    "autoload": {
        "psr-4": {
            "App\\": "app/",
            "App\\Generated\\": "app/Generated/"
        }
    }
    

    Run composer dump-autoload after adding the mapping.

  • Compose chains from reusable fragments. If the package supports adding raw lines or blocks, wrap common patterns in your own builder:

    $generator = SourceGenerator::make()
        ->namespace('App\\Services')
        ->class($name)
        ->use('Illuminate\\Support\\Facades\\Log');
    
    $generator->method('execute', fn ($m) => $m
        ->body('Log::info("executing");')
        ->body('return $this->handle();')
    );
    
    $generator->save(app_path("Services/{$name}.php"));
    

    If the chain mutates an internal buffer, verify whether methods return $this or a new instance; design your wrapper around the observed behavior.

  • Integrate with Artisan and existing stubs. The package is most valuable when invoked from a command that accepts arguments (name, --namespace, --force). Use Laravel’s Filesystem to check for existing files and to create directories before calling save().

  • Use generated code as a starting point, not a runtime dependency. Commit generated files to version control and review them like handwritten code. Do not regenerate files at application boot or in production request paths.

  • Pair with static analysis and tests. Add a CI step that runs php -l over generated output and, ideally, a smoke test that instantiates generated classes. Since the package is unmaintained, this guards against API or PHP-version drift.

Gotchas and Tips

  • The package is archived. There will be no fixes for new PHP or Laravel versions. Pin it in composer.json, document the constraint, and be prepared to fork or vendor the source if a future Laravel release breaks compatibility.

  • Low adoption means thin documentation. With one star and zero dependents, examples on the internet are scarce. Read the source and write your own tests around the exact chain behavior you rely on.

  • Method-chain return semantics matter. Some fluent APIs return $this, others return cloned builders. If you store intermediate results or reuse a chain, confirm whether mutations leak between uses. Prefer building each file from a fresh entry point.

  • Escaping and code validity are your responsibility. A source generator typically writes strings verbatim. Namespaces, class names, and method bodies containing quotes, backslashes, or $ variables can produce invalid PHP. Validate user-supplied names against a strict pattern and lint generated files.

  • File overwrite behavior is a common pitfall. Check whether save() overwrites silently, appends, or throws. Implement your own --force flag and backup behavior in the calling command rather than relying on package defaults.

  • Config quirks are likely minimal but undocumented. If the package publishes a config file, inspect it via php artisan vendor:publish. Otherwise, treat paths and namespaces as caller-supplied and centralize them in your own config to avoid scattering literals.

  • Debugging generated output: write to a temporary path and inspect the string before saving. If the package exposes a toString() or render method, use it in tests; otherwise, generate into storage/framework/testing/ and assert on file contents.

  • Extension points: if the package allows custom line writers, method body callbacks, or template overrides, prefer those over string concatenation. If it does not, wrap the generator in your own class so you can swap implementations later without changing call sites.

  • Avoid using it for complex classes. For anything with heavy logic, annotations, or framework-specific boilerplate, Laravel’s native make:* commands and published stubs are better supported. Use this package for small, repetitive, project-specific scaffolds where you control the entire output shape.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
robertmarney/lara-hierarchial-collections
simonschaufi/rule-doc-generator
emissaoja/emissaoja
blackbricksoftware/gravityforms-civicrm-form-processor
al-rahabi/fancy-crud
jinas/dhivatar-component
mltstephane/laravel-quality
bernskiold/laravel-talentlms
bernskioldmedia/laravel-form-architect
youbar/easy-crud
c-point-labs/laravel-hostyourai
dbravoan/dbcms-admin-theme-dbcms
dbravoan/dbcms-theme-db-cyber
dbravoan/dbcms-blocks-basic
dbravoan/dbcms-module-content-audit
dbravoan/dbcms-module-ai-assistant
paygate-to/paygate-php
padosoft/askmydocs-connector-base
defstudio/supercharged-carbon
bernskioldmedia/laravel-matomo