Skip to content

Instantly share code, notes, and snippets.

@VEnis
Created April 1, 2014 16:50
Show Gist options
  • Save VEnis/9918124 to your computer and use it in GitHub Desktop.
Save VEnis/9918124 to your computer and use it in GitHub Desktop.
phpdoc usage example
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
@Kapeli
Copy link

Kapeli commented Apr 1, 2014

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?

  1. All in folder demo
  2. Install composer: curl -s http://getcomposer.org/installer | php
  3. Set up a composer.json:
{
    "require": {
        "<package I want>": "<version I want>"
    }
}
  1. Let Composer grab the source: php composer.phar install
  2. Package source is now in vedor/<package>

Question: is there any way to make Composer grab the package source without grabbing other dependencies?

@VEnis
Copy link
Author

VEnis commented Apr 1, 2014

Using composer for downloading package is good idea. Here is some tricker usage I have tested now:

  1. All in folder demo
  2. Install composer: curl -s http://getcomposer.org/installer | php
  3. Set up a composer.json:
{
    "require": {
        "monolog/monolog": "1.8.0"
    }
}
  1. Run composer as php composer.phar archive --format=zip monolog/monolog 1.8.0
  2. Receive monolog vendor only in archive named monolog-monolog-392ef35fd470638e08d0160d6b1cbab63cb23174-zip-50c6fc

@Kapeli
Copy link

Kapeli commented Apr 1, 2014

Awesome. That should give me everything I need. I'll contact you on Twitter if I need further help.

@VEnis
Copy link
Author

VEnis commented Apr 1, 2014

Actually it can be simpler.

  1. Set up a composer.json:
{
    "require": {
        "monolog/monolog": "*"
    }
}
  1. 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

@VEnis
Copy link
Author

VEnis commented Apr 1, 2014

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