A generator for Yeoman that provides a boilerplate for a PHP Composer project
A generator for Yeoman.
It provides a basic boilerplate for a Composer project, which features:
- automatic creation of PhpDoc documentation on build
- a functional example
- buildable with Grunt
- Ready for Github, Travis-CI and Packagist
The proposed Grunt build for the generated Composer project has the following tasks:
- PHPLint to review quality of code
- PHPUnit to run tests
- automatic creation of a PhpDocumentor documentation
- Usage of Php Copy/Paste Detector
- Automatic versioning of all the project when version is modified in package.json
The generated PHP project does not rely on any other PHP dependency than Composer and Packagist-installed packages (e.g. no PEAR dependency).
You must have Nodejs and NPM installed.
Then, to install Yeoman globally from npm, run:
npm install -g yo
Finally, to install generator-composer globally from npm, run:
npm install -g generator-composer
You may also just install it locally:
npm install generator-composer
Once you have installed Node, NPM, Yeoman and the generator itself, you can initiate the generator:
Yeoman will ask you 4 questions:
- your github account (e.g. gitAccount)
- the name of the repository on Github (e.g. php-my-super-package)
- the name of the main PHP class of your project (e.g. mySuperPackage)
In order to build your generated Composer project from its source, you will need Grunt and PHP on the command line.
So, you must install PHP5 on your system on your command line. Test it:
To install Grunt globally on the command line (and run the above build task), run:
npm install -g grunt-cli
Then, with Grunt, you can install Composer locally. Just run once:
Then, you can install PhpDocumentor, PhpUnit and PhpCPD locally. Just run once:
php composer.phar install -vphp composer.phar require -v --dev "phpunit/phpunit:3.*"
Finally, you should also install the PHP extension named Xdebug, which will be used by PhpUnit for code coverage.
Once all your dependencies are installed, you can build your project with Grunt:
The build process will run the following tasks:
- PhpLint: runs php -l over the "src" folder
- Runs the tests located in the "tests" folder with PHPUnit
- Generates a PhpDocumentor documentation in the "doc" folder from the files of the "src" folder
- Detects copy/paste of code in the files of the "src" folder with PhpCPD
The generated PHP is ready-to-publish on Packagist. Just login on Packagist with Github, add the Packagist hooks to your Github account, and activate your package on Packagist.
In order to build the generator from its source, you will need Grunt. To install Grunt globally on the command line (and run the above build task), run:
npm install -g grunt-cli
Just run the
grunt task in the folder where your generator is installed:
- Try to get a livereload process for the generated project (maybe with grunt-php)
- More comments in the code
- Include a changelog generator in the build process of the generated code
- Include a changelog generator in the build process of generator
This generator is released under the MIT License.