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.
Related
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
* /
...
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
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
How to automatically format PhpDoc comments in Netbeans?
I'd like to have comments aligned like this:
* #author Author Name <example#example.com>
* #package Doctrine
* #subpackage Table
* #license http://www.opensource.org/licenses/lgpl-license.php LGPL
* #version $Revision: 67999 $
* #link www.phpdoctrine.org
* #since 1.0
When I type /**[Enter] in Netbeans, it automatically imports all parameters as #param from the method definition. But then, when the comment is already generated I add a new variable to the definition. What now? How to trigger comment reparse and add newly added parameter?
Not possible in current version. I just use TAB to align the docs.
Not sure if this will work, but its a formatter that allows you to create a custom profile where you dictate the spacing/indentation of everything from your comment blocks to your class, field, methods declarations. It allows you to be able to hit Ctrl+F to have your code automatically format according to what you specify in your profile. Great way of maintaining the appearance of your code for readability without the manual labor involved.
http://en.sourceforge.jp/projects/pdt-tools/
can someone explain or give some examples how to use the #Category Tag the right way ? PHPDocumentator is not parsing the Tag.
How does an correct File-DocBlock and Class-DocBlock looks like ?
I don't know if this helps, but... From the manual:
The #category tag is used to organize
groups of packages together. This is
directly applicable to the
XML:DocBook/peardoc2 Converter, and
can be used by other converters. Other
Converters packaged with phpDocumentor
ignore the category, but this may
change in future versions. It is also
possible to dynamically specify
category using the -dc,
--defaultcategoryname command-line switch.
/**
* Page-Level DocBlock
* #package MyPackage
* #category mycategory
*/
/**
* #global array used for stuff
*/
function mine()
{
global $baz;
...
}
Also, here's a sample of the proper way to write PEAR code, including DocBlocks with #category.
Please post some sample code that's not parsing -- that may help in answering what's wrong.
I haven't been able to find any useful examples on how to use the #category tag. It made sense to me to use it to represent the MVC layers using that tag ie:
/**
* Layout or template
*
* #category view
*/
/**
* Database representation of the user
*
* #category model
*/
/**
* Login actions
*
* #category controller
*/
That's how I use it.