prometee / php-class-generator
PHP class generator
Installs: 6 989
Dependents: 3
Suggesters: 0
Security: 0
Stars: 3
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- ext-iconv: *
- symfony/string: ^5.4|^6.4|^7.1
Requires (Dev)
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^9
- rector/rector: ^0.17.10
- symplify/easy-coding-standard: ^12
README
PHP8 class generator
This library generate PHP8 classes.
Installation
Install using Composer :
$ composer require prometee/php-class-generator
Usage
Create your PhpGenerator
, an example can be found here :
Then instantiate :
$loader = require_once( __DIR__.'/vendor/autoload.php'); use Doctrine\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();