PHP code example of blutrixx / generator-engine

1. Go to this page and download the library: Download blutrixx/generator-engine 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/ */

    

blutrixx / generator-engine example snippets


use Blutrixx\GeneratorEngine\Generators\PathManager;

// Required: absolute path to the output root.
// Backend files land in {root}/BACKEND, frontend in {root}/FRONTEND.
PathManager::setProjectRoot('/var/www/my-project');

// Required: project identity used by some generators.
PathManager::setProjectContext(['id' => 42, 'uuid' => 'abc-123-...']);

// Optional but strongly recommended: module registry.
// Enables accurate PHP namespace and Vue import-path resolution for FKs.
PathManager::setModuleRegistry([
    ['name' => 'Users',    'module_type' => 'Core',   'table_name' => 'users'],
    ['name' => 'Products', 'module_type' => 'Custom',  'table_name' => 'products'],
    // ...
]);

// Optional: wire up a callable to receive warnings during generation.
PathManager::setIssueHandler(function (string $message, string $level): void {
    // e.g. forward to Artisan output, a logger, or a collection
    logger()->{$level}($message);
});

// Optional: FK graph for delete-check generation.
// Shape: [target_table => [['source_table' => string, 'source_column' => string], ...]]
PathManager::setForeignKeyGraph($graph);

// Optional: set a module sub-group (injected into output paths).
PathManager::setModuleSubGroup('Finance');  // → .../Custom/Finance/Invoices

use Blutrixx\GeneratorEngine\Schema\IntrospectionToConfig;

$columns = $schemaIntrospector->columns('products');

$config = (new IntrospectionToConfig())->build($columns, [
    'module_name' => 'Products',   // StudlyCase singular
    'module_type' => 'Custom',     // StudlyCase group
    'table_name'  => 'products',   // snake plural
    'id_type'     => 'uuid',       // 'uuid' | 'bigint'
    'group_name'  => null,         // optional sub-group
]);

use Blutrixx\GeneratorEngine\Generators\Backend\Models\ModelGenerator;
use Blutrixx\GeneratorEngine\Generators\Backend\Migrations\MigrationGenerator;
use Blutrixx\GeneratorEngine\Generators\Frontend\Pages\ListPageGenerator;

$moduleName  = 'Products';
$moduleGroup = 'Custom';

(new ModelGenerator($moduleName, $moduleGroup, $config))->generate();
(new MigrationGenerator($moduleName, $moduleGroup, $config))->generate();
(new ListPageGenerator($moduleName, $moduleGroup, $config))->generate();
// ... repeat for each desired generator

// Re-running on an existing module: files are skipped unless force is set.
$gen = new ModelGenerator($moduleName, $moduleGroup, $config);
$gen->setForce(true); // overwrite any existing file
$gen->generate();

'inline_items' => [
    'line_items' => [
        [
            'key'               => 'line_items',
            'label'             => 'Line Items',
            'child_module'      => 'OrderItems',
            'child_group'       => 'Custom',
            'parent_fk'         => 'order_id',
            'primary_field'     => 'product_name',
            'fields'            => [
                ['key' => 'product_name', 'label' => 'Product',  'type' => 'text',   '

PathManager::setTemplateRoots([
    'backend'    => '/path/to/custom/backend/stubs',
    'frontend'   => '/path/to/custom/frontend/stubs',
    'mobile_app' => '/path/to/custom/mobile_app/stubs',
    'ux'         => '/path/to/custom/ux/stubs',
    'mobile_ux'  => '/path/to/custom/mobile_ux/stubs',
]);

use Blutrixx\GeneratorEngine\Schema\SchemaIntrospector;

$introspector = new SchemaIntrospector('products');

if ($introspector->exists()) {
    $idType  = $introspector->idColumnType(); // 'uuid' | 'bigint' | 'string'
    $columns = $introspector->columns();      // structured column metadata array
}

// Build reverse FK graph across all application tables
$fkGraph = SchemaIntrospector::globalForeignKeys();
PathManager::setForeignKeyGraph($fkGraph);

// Wire up a warning handler (e.g. for missing indexes on FK columns)
SchemaIntrospector::setIssueHandler(function (string $message, string $level): void {
    logger()->{$level}($message);
});

PathManager::reportIssue(string $message, string $level = 'warning'): void

// Artisan command context
PathManager::setIssueHandler(function (string $message, string $level) use ($output): void {
    $output->writeln("<comment>[{$level}] {$message}</comment>");
});

// Laravel log context
PathManager::setIssueHandler(fn($msg, $lvl) => logger()->{$lvl}($msg));

PathManager::setIssueHandler(null);

PathManager::setTemplateRoots([
    'ux'        => app_path('Project/_Src/Stubs/Ux'),
    'mobile_ux' => app_path('Project/_Src/Stubs/MobileUx'),
]);

Source of truth
      │
      ▼
  Config array  (GeneratorModule shape)
      │
      ▼
  Generators    (one class per artifact)
      │
      ▼
  Emitted files (PHP / Vue / JSON)
bash
php tests/manual/run_introspection_to_config_smoke.php