PHP code example of koeshiro / code-generator-php

1. Go to this page and download the library: Download koeshiro/code-generator-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

koeshiro / code-generator-php example snippets


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

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

$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++;')
    );

(new Fabric());
(new LogicFabric());