PHPackages                             koeshiro/code-generator-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. koeshiro/code-generator-php

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

koeshiro/code-generator-php
===========================

A package for object style code generation in php.

1.0.4(3y ago)013MITPHP

Since Mar 6Pushed 3y ago1 watchersCompare

[ Source](https://github.com/koeshiro/code-generator-php)[ Packagist](https://packagist.org/packages/koeshiro/code-generator-php)[ RSS](/packages/koeshiro-code-generator-php/feed)WikiDiscussions main Synced today

READMEChangelog (4)Dependencies (4)Versions (6)Used By (0)

Code generator
==============

[](#code-generator)

A package for object style code generation in php.

Examples
--------

[](#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
    )
)->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(
                        '
