symfony - 减少消耗 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)
{
//
}
任何想法都会非常感激。谢谢你。
解决方案
推荐阅读
- php - 我在 PHP 7.4.3 上出现弃用错误
- java - Android glide 无法在 Android 4.X 中加载图片
- google-cloud-dataflow - Go SDK 中的数据流自定义指标不会出现在监控中
- java - 有谁知道如何将 ActionListener 添加到按钮数组中?
- c# - C# 控制台在多处理模式下调用 rest API 100k 加次 (Parallel.ForEach)
- java - 在 Java Swing 中为 JLabel 图标绘制线条
- python - Matplotlib 对数图 - 仅在 y 轴上显示 10 的幂
- c# - 如何同时缩放数组中的所有对象?
- expect - Expect中的`expect_before`命令有什么用?
- javascript - 由于路径错误,我无法为 webpack 创建新的入口点