【发布时间】:2014-09-22 01:11:44
【问题描述】:
这个问题很简单——我应该如何区分接口和类实现接口的 phpdoc?它们应该/可以相同,或者接口文档应该尽可能通用,并且实现此接口的类更具体?
我从我的真实代码中包含了一种方法 phpDoc:
我的界面:
interface CacheInterface
{
/**
* Adds data to cache
*
* @param string $objectId Name of object to store in cache
* @param mixed $objectValue Data to store in cache
* @param mixed $lifetime Lifetime of cache file
* @param string $group Name of cache group.
* @param array $params Parameters that distinct cache files.
* @param array $files Name of files that are checked if cache is valid.
* @return bool True if cache was created, false if cache was not created
*/
public function put(
$objectId,
$objectValue,
$lifetime = null,
$group = null,
$params = array(),
$files = array()
);
}
我的类实现接口:
class Cache implements CacheInterface
{
/**
* Adds data to cache
*
* @param string $objectId Name of object. If it begins with : cache filename will be created using hash
* function. If name doesn't begin with : it should use ASCII characters to avoid
* problems with filenames
* @param mixed $objectValue Data to store in cache
* @param mixed $lifetime Lifetime of cache file. If none provided it will use the one set in contructor.
* Possible lifetime values: time in seconds (3600 means that cache is valid
* for 1 hour = 3600 seconds) or one of TIME_ constants @see CacheInterface
* @param string $group Name of cache group. If none/null provided it will use the one set in constructor.
* Sub-groups should be created using | for example group|subgroup|subgroup2
* @param array $params Parameters that distinct cache files. You can for example pass here array('id' => 1)
* to set cache for user id. If $params is not empty, they are also used to generate
* file name. That's way they should rather include simple ASCII values
* @param array $files Name of files that are checked if cache is valid. It should be numerical array
* (not assosiative). If files are not empty when getting data from cache it's checked
* wheteher those files exists and are created earlier than cache was created.
* If any of those conditions is not met cache file is treated as invalid
* @return bool True if cache was created, false if cache was not created
*/
public function put(
$objectId,
$objectValue,
$lifetime = null,
$group = null,
$params = array(),
$files = array()
) {
// implementation here
}
}
文档应该是这样的吗?接口更通用,实现该接口的类更具体?
【问题讨论】:
-
我认为您不应该将所有 phpDoc 从接口复制到实现类。只有在界面上与对应的标签不同的标签。其余的你可以通过
@see标签留下链接
标签: php class interface documentation phpdoc