Created
April 1, 2014 16:50
-
-
Save VEnis/9918124 to your computer and use it in GitHub Desktop.
phpdoc usage example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Assume we are in directory named "demo" and we have php: >=5.3.3 installed | |
Download phpdoc from http://phpdoc.org/phpDocumentor.phar | |
1) Simple example of the source generation workflow | |
Go to the packagist to the page of some package. For example https://packagist.org/packages/monolog/monolog | |
Look of the package source code location at the top of the page. It will say "Source: https://github.com/Seldaek/monolog/tree/master" (99% it will be github) | |
Go to this page and download source code archive. In our example it will be https://github.com/Seldaek/monolog/archive/master.zip | |
Extract this archive to the some directory, for example in "source" | |
Run phpdoc to generate html documentation in the output directory named "doc" | |
php phpDocumentor.phar -d source -t doc --template responsive-twig | |
2) Better solution | |
All is the same, but run phpdoc as | |
php phpDocumentor.phar -d source -t doc --template xml | |
This will produce single xml file which will contain whole structure (classes, their properties, methods, docs etc) | |
Example of the file is http://pastebin.com/QttrrrDY | |
3) Potential problems | |
Currently a lot of php libraries from packagist has tests included and they I think must not be included to the generated code. | |
So best solution will be after downloading and extracting content of the package check file "composer.json" in the root of the extracted package and process it's section "autoload" according to composer documentation "https://getcomposer.org/doc/04-schema.md#autoload" like: | |
For each section under "autoload": | |
- if section is "psr-4" or "psr-0" then it will contain map of "name" to "directory" pairs and only those directories must be included in generation. | |
For example "monolog" contains: | |
"autoload": { | |
"psr-4": {"Monolog\\": "src/Monolog"} | |
}, | |
so only directory "src/Monolog" must be included | |
- if section is "classmap" of "files" then it contains list of files and directories and only they must be included | |
Using composer for downloading package is good idea. Here is some tricker usage I have tested now:
- All in folder
demo
- Install composer:
curl -s http://getcomposer.org/installer | php
- Set up a composer.json:
{
"require": {
"monolog/monolog": "1.8.0"
}
}
- Run composer as
php composer.phar archive --format=zip monolog/monolog 1.8.0
- Receive monolog vendor only in archive named
monolog-monolog-392ef35fd470638e08d0160d6b1cbab63cb23174-zip-50c6fc
Awesome. That should give me everything I need. I'll contact you on Twitter if I need further help.
Actually it can be simpler.
- Set up a composer.json:
{
"require": {
"monolog/monolog": "*"
}
}
- Run composer as
php composer.phar archive --format=zip monolog/monolog [version]
Version format can be found here: https://getcomposer.org/doc/01-basic-usage.md#package-versions
You can contact me directly on email: [email protected]
It will be much quicker I think.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Grabbing the source is a bit of a problem with the method you described, as I'd be only supporting packages on GitHub.
Why not this way?
demo
curl -s http://getcomposer.org/installer | php
php composer.phar install
vedor/<package>
Question: is there any way to make Composer grab the package source without grabbing other dependencies?