定制 prometee/php-class-generator 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

prometee/php-class-generator

最新稳定版本:v1.0.14

Composer 安装命令:

composer require prometee/php-class-generator

包简介

PHP class generator

README 文档

README

Latest Version on Packagist Software License Build Status Quality Score

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 :

DummyPhpGenerator.php

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();

Results example

tests/Resources

统计信息

  • 总下载量: 7.86k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 1
  • 依赖项目数: 3
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-06-19