请求params和phpdoc [英] Request params and phpdoc

查看:120
本文介绍了请求params和phpdoc的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

是否有记录GET / POST参数的标准?

尝试通过phpdoc找出记录请求参数的最佳方式,这是有意义的。具体来说,我有一些Zend Framework控制器操作通过GET / POST接收参数,但不是功能参数。这是否有意义?

Trying to figure out the best way to document request parameters via phpdoc in a manner that makes sense. Specifically, I've got some Zend Framework controller actions that receive parameters via GET/POST, but aren't functional params. Does this make sense?

/**
 * Display a pagination/grid list of rows.
 *
 * @param string $_GET['order']  What field to sort on
 * @param string $_GET['dir']    Direction to sort; either ASC|DESC
 * 
 * @return void
 */
public function listAction()
{
    $order = $this->_request->order;
    ...

如果我为此方法生成文档,指示order和dir可以通过url字符串传递给这个方法。

If I generated docs for this method, there wouldn't be an indication that "order" and "dir" can be passed via a url string to this method. Would it make more sense to just do

@param string $order

我应该使用@var吗?

Should I use @var instead?

欢迎的想法。

推荐答案

我会避免使用@param 。

I would avoid mucking with @param.

也可以使用_validate()方法使它在代码中显而易见。然后您可以使用_validate()为单元测试创​​建 seam

Also you could make a _validate() method to make it obvious in the code. Then you could use _validate() to create a seam for unit testing.

/**
 * Display a pagination/grid list of rows.
 *
 * Requires $_REQUEST['order'] and $_REQUEST['dir']
 * 
 * @return void
 */
public function listAction()
{
    list($order, $dir) = $this->_validate($this->_request);
    ...

private function _validate($request) {
    if (!$request->order)
         throw new InvalidArgumentException('"Order" must be in request');

    if (!$request->dir)
         throw new InvalidArgumentException('"Dir" must be in request');

    // maybe clean vars???
    //Zend_Filter_Numeric.....

    return array($request->order, $request->dir);
} 

这篇关于请求params和phpdoc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆