How to use #package & #subpackage in phpdoc? - php

I'm wondering how I should use #package & #subpackage for class doc.
let say I've the following class
class My_Controller_Action_Helper_MyHelperAction extends Foo_Bar {}
Should it be:
#category My
#package Controller
#subpackage Action_Helper
or
#category My
#package Controller
#subpackage Action_Helper_MyHelperAction
or
#category My
#package Controller_Action
#subpackage MyHelperAction
or
#category My
#package My_Controller_Action
#subpackage MyHelperAction
What if use namespace instead of '_'?

First: If you use "_" or "\" (the namespace separator) should not influence your decision, how you annotate your classes. The underscore "_" comes from a pre-namespace age and "acts like" the namespace separator, except that it not create any namespaces. So "My_Controller_Action" should be treated as "Action" in "My_Controller".
However, how you use #package and/or #subpackage is really your decision. For example I dont use #category at all and #subpackage is everything after the "second" namespace. Let me explain: I follow the PSR-0 standard, where a package is structured into \<Vendorname>\<packagename>\<subpackage>\... (or "_" instead of "\", depending on the version). Then #package <vendorname>.<package> and #subpackage <subpackage>.
Conclusion: Its up to you :) A documentor may gerenate different structures of your code, depending on the tags you use and how you use them. Just try it out.

If you've came across this answer in 2020, both #category and #subpackage tags are considered deprecated, so please don't use them anymore.
Instead of that, you should use #package to provide the required logical sub-division.
According to https://docs.phpdoc.org/latest/guide/references/phpdoc/tags/category.html and https://docs.phpdoc.org/latest/guide/references/phpdoc/tags/subpackage.html :
Important This tag is considered deprecated and may be removed in a
future version of phpDocumentor. It is recommended to use the #package
tag’s ability to provide multiple levels.
Important This tag is considered deprecated and may be removed in a
future version of phpDocumentor. It is recommended to use the #package
tag’s ability to provide multiple levels.

i use #package for the name of the package this file belongs to... surprise :) eg if its a plugin called xyz the #package for all files that belong in that package.
for doxygen (which i use) there is no such thing as a #subpackage although you can make your own. eg: http://www.doxygen.nl/manual/commands.html
For doxygen you can use something like #package my.awesome.package which breaks it down in to 'sub packages'
You can really use it for anything as long as it makes sense and is consistent. first decide what you want to use and then look at the recommendations / docs for that application as they are all different

Related

Using #package instead of namespace in PhpDocumentor 2

I have a large code library for which I am trying to generate hierarchical documentation. The project does not use namespaces but uses #package instead.
I just tried generating docs as a test from the following file with phpDocumentor2:
<?php
/**
* This is a file
* #package JustAn\Example
**/
/**
* Something class
**/
class Something{
function try_this(){
}
}
Though according to the docs #package JustAn\Example should be the equivalent of namespace JustAn\Example, I found this not to be the case.
When I use namespaces the resulting documentation is like this:
When I use the #package notation the result looks like this (even though it recognizes the package notation - this is shown on the full details page of the class):
I am looking for a way to get the hierarchical result without having to rewrite the code to use 'real' namespaces.
The problem is that the default "clean" template does not support this feature. Other templates (like "responsive" for example) do. You can use the --template="responsive" flag to change the default template used.
I see that you have the package tag in the file docblock, but not the class docblock. If you add it to your class docblock, I think it should work.

PHP Documenting Code - How to use #package and #subpackage tags?

I am confused about how to properly use the #package and #subpackage tags when documenting my PHP code. If it's of any relevance, this is for CakePHP 2.x
How would I write the package tags for the classes located in the following directories within my application, for example:
app/Model/User.php
app/Model/Behavior/Sortable.php
app/Model/Behavior/Custom/Validator.php
...
And so on, with further subdirectories. I am particularly unsure about classes that reside in deep subdirectories.
/**
* #package ??
* #subpackage ??
*/
class ValidatorBehavior extends ModelBehavior {
}
Well it's matter of agreement and convention. Cake uses like:
/*
* #package App
* #subpackage App.Model.Behavior
* /
...

Can I use twice "#subpackage" for phpDocumentor?

For example I have a project called "myproj" and a subpackage called "utils" and in this subpackage there's again a subpackage called "debug".
Can I do something like that: ?
/**
* #package myproj
* #subpackage utils
* #subpackage debug
* /
Thanks in advance!
Solution
There is also the tag #category:
The #category tag is used to organize groups of packages together.
So you can use the tags in the following order: #category, #package, #subpackage
And if that isn't enough for you, can could use also underscores in the names.
I know the question is quite old, but for any google speeders - #subpackage tags are now deprecated. Use #package tag instead in a following manner:
#package [level 1]\[level 2]\[etc.]
Check PHPDocumentor2 manual: http://www.phpdoc.org/docs/latest/for-users/phpdoc/tags/package.html
Most generators will not understand multiple subpackage tags. Convention is either to use underscores or hyphens; or not segmenting below 2 levels (package / subpackage)
See: http://manual.phpdoc.org/HTMLSmartyConverter/HandS/phpDocumentor/tutorial_tags.subpackage.pkg.html

Structuring documentation when using Doxygen

I am starting to document my PHP5 framework using Doxygen. I am trying to use CodeIgniter framework's inline documentation as a reference. However, its documentation is written using phpDocumentor syntax. Below is an example of CodeIgniter's Loader class description:
/**
* Loader Class
*
* Loads views and files
*
* #package CodeIgniter
* #subpackage Libraries
* #author ExpressionEngine Dev Team
* #category Loader
* #link http://codeigniter.com/user_guide/libraries/loader.html
*/
class CI_Loader {
...
}
How can I implement the same structure (Package->Subpackage->Category->Class) using Doxygen? I would like to have a corresponding description page for each element of the structure.
Another one question is how do you structure your project's documentation?
If you are running PHP 5.3 then Doxygen supports namespaces. If you put them in then your documentation will be structured in a similar style to the phpDocumentor's packages. Have a look at the following links for more information about PHP namespaces:
http://php.net/manual/en/language.namespaces.php
http://www.sitepoint.com/php-53-namespaces-basics/

multiple subpackages for phpdoc

Is it possible to have a file belong to multiple subpackages? For example:
/**
* Name
*
* Desc
*
* #package Core
* #subpackage Sub1
* #subpackage Sub2
*/
Thanks!
It appears that PHPDoc does not allow you to do it for namespacing reasons. From the PHPDoc Docs:
NOTE: The #subpackage tag is intended to help categorize the elements that are in an actual #package value. Since PHP itself doesn't allow you to have two functions with the same name in the same script, PhpDocumentor also requires all names in an #package to be unique... meaning, #subpackage does not allow further "naming separation" inside that #package. What it does do is allow a level of visual grouping/separation of the elements inside that #package.
It seems that because PHPDoc's #package is a way to pseudo-namespace your functions and classes, but #subpackage is simply for categorization. Have you tried adding more than one subpackage? If so, what were the results?
You can use the following to do this:
* #package popcap\system\cache
This will create a hierarchy of packages when you compile the PHPdocs.
http://pear.php.net/package/PHP_UML/
Seems to do a pretty good job with multiple #subpackage tags - it will even generate html- documentation just as phpDocumentor does - though it doesn't seem to be as style-able as phpDocumentor.
It also makes use of the extra subpackage by showing it in the generated UML diagaram.

Categories