PHP code example of event-engine / php-code-generator-event-engine-ast

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

    

event-engine / php-code-generator-event-engine-ast example snippets




declare(strict_types=1);

use EventEngine\CodeGenerator\EventEngineAst\Command;
use EventEngine\CodeGenerator\EventEngineAst\Config\EventEngineConfig;
use EventEngine\CodeGenerator\EventEngineAst\Config\PreConfiguredNaming;
use EventEngine\CodeGenerator\EventEngineAst\Metadata;
use EventEngine\InspectioGraphCody\EventSourcingAnalyzer;
use EventEngine\InspectioGraphCody\EventSourcingGraph;

$contextName = 'Acme';
$basePath = '../app';
$composerFile = $basePath . '/composer.json';

$config = new EventEngineConfig();
$config->setBasePath($basePath);
$config->addComposerInfo($composerFile);

$namingConfig = new PreConfiguredNaming($config);
$namingConfig->setDefaultContextName($contextName);

$analyzer = new EventSourcingAnalyzer(
    new EventSourcingGraph(
        $config->getFilterConstName(),
        new Metadata\MetadataFactory(new Metadata\InspectioJson\MetadataFactory())
    )
);
// create class to generate code for commands
// same behaviour for the other classes e.g. EventEngine\CodeGenerator\EventEngineAst\Event
$commandGenerator = new Command($namingConfig);

// contains all generated PHP classes
$fileCollection = \OpenCodeModeling\CodeAst\Builder\FileCollection::emptyList();

// assume that $codyNode is an instance of \EventEngine\InspectioGraphCody\Node which describes a command
$connection = $analyzer->analyse($codyNode);

// generate JSON schema file of the command
$schemas = $commandGenerator->generateJsonSchemaFile($connection, $analyzer);

foreach ($schemas as $schema) {
    $schema['filename']; // contains path with filename depending on your configuration
    $schema['code']; // contains generated JSON schema
}

// call the different generate methods of the code generator class
$commandGenerator->generateApiDescription($connection, $analyzer, $fileCollection);
$commandGenerator->generateApiDescriptionClassMap($connection, $analyzer, $fileCollection);
$commandGenerator->generateCommandFile($connection, $analyzer, $fileCollection);

$files = $config->getObjectGenerator()->generateFiles($fileCollection);

// loop over files and store them in filesystem
foreach ($files as $file) {
    $file['filename']; // contains path with filename depending on your configuration e.g. src/Domain/Aggregate
    $file['code']; // contains generated PHP code
}

bash
$ composer