PHP Classes

PHP Code Generator: Generate PHP code elements programatically

Recommend this page to a friend!
  Info   View files Documentation   View files View files (63)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2022-10-21 (23 days ago) RSS 2.0 feedStarStarStarStar 73%Total: 417 This week: 5All time: 6,388 This week: 170Up
Version License PHP version Categories
php-generator 1.0.13MIT/X Consortium ...5.3.3PHP 5, Libraries, Code Generation
Description Author

This package can generate PHP code elements programatically.

It provides a set of classes that can generate PHP code elements of different types like PHP files, classes, interfaces, functions, function patrameters, variables and annotations.

Another set of classes can generate more complex components made of base PHP code elements that are passed to these classes as object parameters.

Innovation Award
PHP Programming Innovation award nominee
September 2015
Number 8


Prize: One copy of the Zend Studio
One common way to generate code in PHP or any other language is to use templates and replace variable values.

This package provide an alternative approach that consists in classes of objects that represent each type of construct of the PHP language, like classes, interfaces, functions, variables, etc..

It can define the PHP code you want to generate by combining language element objects in a hierarchic way.

Manuel Lemos
Picture of WsdlToPhp
  Performance   Level  
Name: WsdlToPhp <contact>
Classes: 9 packages by
Country: France France
Innovation award
Innovation award
Nominee: 5x

Winner: 1x

Details

PhpGenerator, a Real PHP source code generator

> PhpGenerator helps to generate PHP source code

License Latest Stable Version TeamCity build status Scrutinizer Code Quality Code Coverage Total Downloads StyleCI SymfonyInsight

Even if this project is yet another PHP source code generator, its main goal is to provide a consistent PHP source code generator for the PackageGenerator project. Nevertheless, it also aims to be used for any PHP source code generation process as it generates standard PHP code.

Rest assured that it is not tweaked for the purpose of the PackageGenerator project.

Main features

This project contains two main features:

  • Element: generate basic elements
  • Component: generate structured complex elements

Testing using Docker

Thanks to the Docker image of phpfarm, tests can be run locally under any PHP version using the cli: - php-7.4

First of all, you need to create your container which you can do using docker-compose by running the below command line from the root directory of the project:

$ docker-compose up -d --build

You then have a container named php_generator in which you can run composer commands and php cli commands such as:

# install deps in container (using update ensure it does use the composer.lock file if there is any)
$ docker exec -it php_generator php-7.4 /usr/bin/composer update
# run tests in container
$ docker exec -it php_generator php-7.4 -dmemory_limit=-1 vendor/bin/phpunit

FAQ

If you have a question, feel free to create an issue.

License

The MIT License (MIT). Please see License File for more information.

  Files folder image Files  
File Role Description
Files folder image.docker (1 file)
Files folder imagesrc (2 directories)
Files folder imagetests (1 file, 3 directories)
Accessible without login Plain text file .editorconfig Data Auxiliary data
Accessible without login Plain text file .php-cs-fixer.php Example Example script
Accessible without login Plain text file CHANGELOG.md Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file docker-compose.yml Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file phpunit.xml.dist Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation
Accessible without login Plain text file UPGRADE-3.0.md Data Auxiliary data
Accessible without login Plain text file UPGRADE-4.0.md Data Auxiliary data

  Files folder image Files  /  .docker  
File Role Description
  Accessible without login Plain text file Dockerfile Data Auxiliary data

  Files folder image Files  /  src  
File Role Description
Files folder imageComponent (6 files)
Files folder imageElement (21 files)

  Files folder image Files  /  src  /  Component  
File Role Description
  Plain text file AbstractComponent.php Class Class source
  Plain text file GenerateableInterface.php Class Class source
  Plain text file PhpClass.php Class Class source
  Plain text file PhpFile.php Class Class source
  Plain text file PhpInterface.php Class Class source
  Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  src  /  Element  
File Role Description
  Plain text file AbstractElement.php Class Class source
  Plain text file AccessRestrictedElementInterface.php Class Class source
  Plain text file AccessRestrictedElementTrait.php Class Class source
  Plain text file AssignedValueElementInterface.php Class Class source
  Plain text file AssignedValueElementTrait.php Class Class source
  Plain text file GenerateableInterface.php Class Class source
  Plain text file PhpAnnotation.php Class Class source
  Plain text file PhpAnnotationBlock.php Class Class source
  Plain text file PhpClass.php Class Class source
  Plain text file PhpConstant.php Class Class source
  Plain text file PhpDeclare.php Class Class source
  Plain text file PhpFile.php Class Class source
  Plain text file PhpFunction.php Class Class source
  Plain text file PhpFunctionParameter.php Class Class source
  Plain text file PhpInterface.php Class Class source
  Plain text file PhpMethod.php Class Class source
  Plain text file PhpProperty.php Class Class source
  Plain text file PhpVariable.php Class Class source
  Accessible without login Plain text file README.md Doc. Documentation
  Plain text file TypeHintedElementInterface.php Class Class source
  Plain text file TypeHintedElementTrait.php Class Class source

  Files folder image Files  /  tests  
File Role Description
Files folder imageComponent (4 files)
Files folder imageElement (12 files)
Files folder imageresources (8 files)
  Accessible without login Plain text file TestCase.php Test Unit test script

  Files folder image Files  /  tests  /  Component  
File Role Description
  Accessible without login Plain text file AbstractComponent.php Test Unit test script
  Accessible without login Plain text file PhpClassTest.php Test Unit test script
  Accessible without login Plain text file PhpFileTest.php Test Unit test script
  Accessible without login Plain text file PhpInterfaceTest.php Test Unit test script

  Files folder image Files  /  tests  /  Element  
File Role Description
  Accessible without login Plain text file PhpAnnotationBlockTest.php Test Unit test script
  Accessible without login Plain text file PhpAnnotationTest.php Test Unit test script
  Accessible without login Plain text file PhpClassTest.php Test Unit test script
  Accessible without login Plain text file PhpConstantTest.php Test Unit test script
  Plain text file PhpDeclareTest.php Class Class source
  Accessible without login Plain text file PhpFileTest.php Test Unit test script
  Accessible without login Plain text file PhpFunctionParameterTest.php Test Unit test script
  Accessible without login Plain text file PhpFunctionTest.php Test Unit test script
  Accessible without login Plain text file PhpInterfaceTest.php Test Unit test script
  Accessible without login Plain text file PhpMethodTest.php Test Unit test script
  Accessible without login Plain text file PhpPropertyTest.php Test Unit test script
  Accessible without login Plain text file PhpVariableTest.php Test Unit test script

  Files folder image Files  /  tests  /  resources  
File Role Description
  Accessible without login Plain text file PhpClassTest_SimpleToString.php Test Unit test script
  Accessible without login Plain text file PhpClassTest_Simpl...rnTypePerMethod.php Aux. Auxiliary script
  Accessible without login Plain text file PhpClassTest_Simpl...rnTypePerMethod.php Aux. Auxiliary script
  Accessible without login Plain text file PhpFileTest_SimpleClassToString.php Test Unit test script
  Plain text file PhpFileTest_Simple...gWithReturnType.php Class Class source
  Accessible without login Plain text file PhpFileTest_SimpleInterfaceToString.php Test Unit test script
  Accessible without login Plain text file PhpInterfaceTest_SimpleToString.php Test Unit test script
  Accessible without login Plain text file PhpInterfaceTest_S...gWithReturnType.php Aux. Auxiliary script

 Version Control Unique User Downloads Download Rankings  
 100%
Total:417
This week:5
All time:6,388
This week:170Up
 User Ratings  
 
 All time
Utility:93%StarStarStarStarStar
Consistency:93%StarStarStarStarStar
Documentation:81%StarStarStarStarStar
Examples:-
Tests:87%StarStarStarStarStar
Videos:-
Overall:73%StarStarStarStar
Rank:228
  
For more information send a message to info at phpclasses dot org.