eudiegoborgs/hyperf-cgen
最新稳定版本:v3.1.0
Composer 安装命令:
composer require eudiegoborgs/hyperf-cgen
包简介
Custom class generator for hyperf
README 文档
README
CGen is a Custom Class Generator library to optimize your hyperf development experience.
If you use this library, you can make stub for your classes and create code structure with only one command.
Installation
composer require eudiegoborgs/hyperf-cgen
Configuration
Publish the config file so you can define your own rules
php bin/hyperf.php vendor:publish eudiegoborgs/hyperf-cgen
The config file will show up in the following path:
config/autoload/cgen.php
Here in the file you can define your own creation rules for specific classes
<?php declare(strict_types=1); return [ 'generator' => [ 'example_type' => [ 'namespace' => 'CyBorgs\\Hyperf\\CGen\\Custom', 'stub' => __DIR__ . '/stubs/class.stub', 'run_previous' => [ 'other_type', 'interface' ] ], 'other_type' => [ 'namespace' => 'CyBorgs\\Hyperf\\CGen\\OtherCustom', 'stub' => __DIR__ . '/stubs/other_class.stub', 'prefix' => 'Prefix', 'suffix' => 'Suffix', ], 'interface' => [ 'namespace' => 'CyBorgs\\Hyperf\\CGen\\Custom\\%CLASS%\\Interfaces', 'stub' => __DIR__ . '/stubs/interface.stub', 'suffix' => 'Interface', ], ], 'default' => [ 'stub' => 'path/to/real/stub/example_type.stub', 'namespace' => 'App\\Example\\Default' ] ];
Create stub files
This is a stub for other type:
// path/to/real/stub/other_type.stub <?php declare(strict_types=1); namespace %NAMESPACE%; class %CLASS% { }
This is a stub for example type interface:
// path/to/real/stub/example_type_interface.stub <?php declare(strict_types=1); namespace %NAMESPACE%; interface %CLASS% { }
This is a stub for example type:
// path/to/real/stub/example_type_interface.stub <?php declare(strict_types=1); namespace %NAMESPACE%; use %other_type.NAMESPACE%\%other_type.CLASS%; class %CLASS% { public function __construct( private %other_type.CLASS% %other_type.VARIABLE_NAME% ) {} }
Usage
To create a new class you need run this command:
php bin/hyperf.php cgen:create example_type MyClassName
After you run command, this lib will create for you files using your stubs with this structure:
src/
- Example/
- Namespace/
- MyClassName/
- Interfaces/
- MyClassNameInterface.php
- MyClassName.php
- OtherNamespace/
PrefixMyClassNameSuffix.php
Show the PrefixMyClassNameSuffix.php file
<?php declare(strict_types=1); namespace CyBorgs\Hyperf\CGen\OtherCustom; class PrefixMyClassNameSuffix { }
Show the MyClassNameInterface.php file
<?php declare(strict_types=1); namespace CyBorgs\Hyperf\CGen\Custom\MyClassName\Interfaces; class MyClassNameInterface { }
Show the MyClassName.php file
<?php declare(strict_types=1); namespace CyBorgs\Hyperf\CGen\Custom; use CyBorgs\Hyperf\CGen\OtherCustom\PrefixMyClassNameSuffix; class MyClassName { public function __construct( private PrefixMyClassNameSuffix $classTest ) {} }
统计信息
- 总下载量: 521
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-10-31