koeshiro/code-generator-php
最新稳定版本:1.0.4
Composer 安装命令:
composer require koeshiro/code-generator-php
包简介
A package for object style code generation in php.
README 文档
README
A package for object style code generation in php.
Examples
Creating class
(new ClassTemplate()) ->setName('Test') ->addProperty( (new PropertyTemplate()) ->setName('testProp') ->setScope('protected') ->setType('?string') )->addMethod( (new MethodTemplate()) ->setScope('public') ->addArgument( (new ArgumentTemplate()) ->setName('data') ->setType('string') )->setName( 'setTestProp' )->setReturnType( 'void' )->setBlock( (new BlockTemplate()) ->addLine('$this->testProp = $data') ) )->addMethod( (new MethodTemplate()) ->setScope('public') ->addArgument( (new ArgumentTemplate()) ->setName('test') ->setType('string') )->setName( 'testFun' )->setReturnType( 'string' )->setBlock( (new BlockTemplate()) ->addLine('return \'test\'.$test;') ) )
If block
$aVariable = (new GetTemplate())->setVariable((new VariableTemplate())->setName('a')); $bVariable = (new GetTemplate())->setVariable((new VariableTemplate())->setName('b')); $logicBlock = (new LogicBlockTemplate())->logic( (new LogicTemplate())->setLogic( "<", $aVariable, $bVariable ) )->and()->logic( (new LogicTemplate())->setLogic( ">", $aVariable, $bVariable ) )->or()->logic( (new LogicTemplate())->setLogic( "===", $aVariable, $bVariable ) );
While block
$iVariable = (new GetTemplate())->setVariable((new VariableTemplate())->setName('i')); $countVariable = (new GetTemplate())->setVariable((new VariableTemplate())->setName('count')); $whileTemplate = (new WhileTemplate()) ->setLogic( (new LogicBlockTemplate()) ->logic( (new LogicTemplate()) ->setLogic( '<', $iVariable, $countVariable ) ) ) ->setBlock( (new BlockTemplate())->addLine('$i++;') );
Fabric
Use Fabrics for ease and fast work with all generator object
(new Fabric()); (new LogicFabric());
统计信息
- 总下载量: 13
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-03-04