PHP code example of prometee / php-class-generator

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

    

prometee / php-class-generator example snippets


$loader = rine\Common\Annotations\Annotation\Required;
use Prometee\PhpClassGenerator\Builder\ClassBuilder;
use Prometee\PhpClassGenerator\Builder\Model\ModelFactoryBuilder;
use Prometee\PhpClassGenerator\Builder\View\ViewFactoryBuilder;
use Prometee\PhpClassGenerator\Model\PhpDoc\PhpDocInterface;

// Create your own Php Generator
final class MyPhpGenerator implements PhpGeneratorInterface {
    use PhpGeneratorTrait;
}

$path = __DIR__ . '/etc/build/Dummy';
$namespace = 'Tests\\Prometee\\PhpClassGenerator\\Resources';
$classConfig = [
    [
        'class' => 'MyClass',
        'type' => 'final',
        'extends' => stdClass::class,
        'phpdoc' => [
            PhpDocInterface::TYPE_DESCRIPTION => [
                'My own class description',
                'with multiple lines',
            ],
        ],
        'properties' => [
            [
                'name' => 'myProperty',
                'types' => [
                    'null',
                    $namespace . '\\MyClass[]',
                ],
                'default' => null,
                'description' => null,
                'phpdoc' => [
                    PhpDocInterface::TYPE_DESCRIPTION => [
                        'My description',
                        'My description line 2',
                    ],
                    sprintf('\\%s()', Required::class) => [''] // An annotation
                ],
            ],
        ],
    ],
];

$dummyPhpGenerator = new MyPhpGenerator(
    new ClassBuilder(
        new ModelFactoryBuilder(),
        new ViewFactoryBuilder()
    )
);

// Configure the generator first
$dummyPhpGenerator->configure(
    $path,
    $namespace,
    $classConfig
);

// Then generate
$dummyPhpGenerator->generate();


$ composer