首页 > 解决方案 > 减少消耗 FosRest 注释

问题描述

我正在使用Fos RestBundle来帮助我为我的 Rest API 资源实现一些注释,事实上我并不喜欢应该在我的函数上方定义的大量注释......我query param fetcher用来获取一些注释的地方诸如此类query的数据category......
知道如何创建一个包含注释孔块的Symfony@FOSRest\QueryParam注释。
最后,新的解决方案将帮助我减少代码、分离代码并将其解耦。


这是我的功能:

    /**
     * @param ParamFetcherInterface $paramFetcher
     *
     * @return int[]
     *
     * @FOSRest\QueryParam(name="query")
     * @FOSRest\QueryParam(name="articleReference", requirements="\d+")
     * @FOSRest\QueryParam(name="category", requirements="\d+")
     * @FOSRest\QueryParam(name="memberCategory", requirements="\d+")
     * @FOSRest\QueryParam(name="supplier", requirements="\d+", nullable=true)
     * @FOSRest\QueryParam(name="published", requirements="(0|1)", nullable=true)
     * @FOSRest\QueryParam(name="withoutCoefficient", requirements="(0|1)", nullable=true)
     * @FOSRest\QueryParam(name="zipCode", requirements="\d+", nullable=true)
     * @FOSRest\QueryParam(name="memberCategoryStrict", default=0, requirements="(0|1)")
     * @FOSRest\QueryParam(name="orphan", requirements="(0|1)", nullable=true)
     * @FOSRest\QueryParam(name="articleType", requirements="article|catalog", nullable=true)
     * @FOSRest\QueryParam(name="withImage", requirements="0|1", nullable=true)
     * @FOSRest\QueryParam(name="withTechnicalSheet", requirements="0|1", nullable=true)
     *
     */
    public function getArticlesStatsAction(ParamFetcherInterface $paramFetcher)
    {
     //
     }

我想实现一个名为@GetArticlesStats()例如的注释。最终结果应如下所示:

/**
 * @param ParamFetcherInterface $paramFetcher
 *
 * @return int[]
 *
 * @GetArticlesStats()
 *
 */
public function getArticlesStatsAction(ParamFetcherInterface $paramFetcher)
{
//
}

任何想法都会非常感激。谢谢你。

标签: symfonyfosrestbundle

解决方案


推荐阅读