Wallogit.com
2017 © Pedro Peláez
a simple demo to generate php code, (*1)
clone the resposity, (*2)
$ git clone https://github.com/Smiler94/code_generate.git, (*3)
install the dependencies, (*4)
$ composer install, (*5)
``` php require_once DIR.'/vendor/autoload.php';, (*6)
use generator\Property; use generator\Method; use generator\Classes; $property = (new Property('test')) ->addComment('a test property') ->setStatic(true) ->indent(0) ->setPrivilege(Property::PRIVILEGE_PROTECTED) ->setValue('dddd'); // ->generate();, (*7)
echo $property; // // $method = (new Method('test')) ->addComment('a test method') ->addComment(' ') ->addComment('@author linzhen 2017-07-03 16:17:02') ->setStatic(true) ->indent(1) ->addBody('return true');, (*8)
echo $method;, (*9)
$class = (new Classes('Test')) ->addComment('a test class') ->setNameSpace('generate') ->addTrait('\generate\Method') ->addExtend('extend') ->addImplement('implement') ->addImplement('implement2');, (*10)
$prop = $class->addProperty('prop1', '') ->addComment('prop1') ->setPrivilege('private');, (*11)
$method = $class->addMethod('method1') ->addComment('a test method') ->addComment(' ') ->addComment('@author linzhen 2017-07-04 09:55:57') ->setPrivilege('public') ->addParam('arg1') ->addBody('return true');, (*12)
$method2 = $class->addMethod('method2') ->addComment('a test method2') ->addComment(' ') ->addComment('@author linzhen 2017-07-04 09:55:57') ->setPrivilege('private') ->addParam('arg1') ->addBody(''); echo $class;, (*13)
```, (*14)