Symfony : 私有服务 - 使用 Rest 提供更改选项 -API
Symfony : private services - provide change options by using Rest -API
我目前正在使用 FOSCommentBundle 获取 Rest 的示例 api 最佳实践
在此捆绑包中,使用具有不同选项的排序器(或排序)服务,使用日期升序和日期降序进行排序,但此服务未注入排序提供程序数组(在排序 class 服务内)
在 "page number" 或 "date" 范围
的订购页面中重复使用此内容
parameters:
# The sorting factory class
cms_content.sorting_factory.class: CMS\Bundle\ContentBundle\Sorting\SortingFactory
# Provide to sort by date
cms_content.sorter.date.class: CMS\Bundle\ContentBundle\Sorting\DateSorting
# Provide to sort by page number
cms_content.sorter.page_nb.class: CMS\Bundle\ContentBundle\Sorting\PageNbSorting
#
sorter_sevices_aliases:
- 'cms_content.sorter.page_nb_desc'
- 'cms_content.sorter.page_nb_asc'
- 'cms_content.sorter.date_desc'
- 'cms_content.sorter.date_asc'
services:
# sort by page nb asc
cms_content.sorter.page_nb_asc:
class: '%cms_content.sorter.page_nb.class%'
public: false
tags:
- { name: cms_content.sorter, alias: page_nb_asc }
arguments: [ASC]
# sort by page nb dsc
cms_content.sorter.page_nb_desc:
class: '%cms_content.sorter.page_nb.class%'
public: false
tags:
- { name: cms_content.sorter, alias: page_nb_desc }
arguments: [DESC]
# sort by date asc
cms_content.sorter.date_asc:
class: '%cms_content.sorter.date.class%'
public: false
tags:
- { name: cms_content.sorter, alias: date_asc }
arguments: [ASC]
# sort by date desc
cms_content.sorter.date_desc:
class: '%cms_content.sorter.date.class%'
public: false
tags:
- { name: cms_content.sorter, alias: date_desc }
arguments: [DESC]
# the sorting factory (may be construct with empty array )
cms_content.sorting_factory:
class: '%cms_content.sorting_factory.class%'
arguments: ['%sorter_sevices_aliases%', '%cms_content.sorting_factory.default_sorter%']
我在使用分类工厂内声明为私有的服务作为可能的分类器提供程序数组时遇到了一些麻烦
不好的做法,我犯了一个错误,服务应该直接注入,而不是像这样通过数组引用传递:
# the sorting factory (may be contruct with empty array )
cms_content.sorting_factory:
class: '%cms_content.sorting_factory.class%'
arguments: [['@cms_content.sorter.page_nb_asc', '@cms_content.sorter.page_nb_desc', '@cms_content.sorter.date_asc', '@cms_content.sorter.date_desc'], '%cms_content.sorting_factory.default_sorter%']
我目前正在使用 FOSCommentBundle 获取 Rest 的示例 api 最佳实践
在此捆绑包中,使用具有不同选项的排序器(或排序)服务,使用日期升序和日期降序进行排序,但此服务未注入排序提供程序数组(在排序 class 服务内)
在 "page number" 或 "date" 范围
的订购页面中重复使用此内容parameters:
# The sorting factory class
cms_content.sorting_factory.class: CMS\Bundle\ContentBundle\Sorting\SortingFactory
# Provide to sort by date
cms_content.sorter.date.class: CMS\Bundle\ContentBundle\Sorting\DateSorting
# Provide to sort by page number
cms_content.sorter.page_nb.class: CMS\Bundle\ContentBundle\Sorting\PageNbSorting
#
sorter_sevices_aliases:
- 'cms_content.sorter.page_nb_desc'
- 'cms_content.sorter.page_nb_asc'
- 'cms_content.sorter.date_desc'
- 'cms_content.sorter.date_asc'
services:
# sort by page nb asc
cms_content.sorter.page_nb_asc:
class: '%cms_content.sorter.page_nb.class%'
public: false
tags:
- { name: cms_content.sorter, alias: page_nb_asc }
arguments: [ASC]
# sort by page nb dsc
cms_content.sorter.page_nb_desc:
class: '%cms_content.sorter.page_nb.class%'
public: false
tags:
- { name: cms_content.sorter, alias: page_nb_desc }
arguments: [DESC]
# sort by date asc
cms_content.sorter.date_asc:
class: '%cms_content.sorter.date.class%'
public: false
tags:
- { name: cms_content.sorter, alias: date_asc }
arguments: [ASC]
# sort by date desc
cms_content.sorter.date_desc:
class: '%cms_content.sorter.date.class%'
public: false
tags:
- { name: cms_content.sorter, alias: date_desc }
arguments: [DESC]
# the sorting factory (may be construct with empty array )
cms_content.sorting_factory:
class: '%cms_content.sorting_factory.class%'
arguments: ['%sorter_sevices_aliases%', '%cms_content.sorting_factory.default_sorter%']
我在使用分类工厂内声明为私有的服务作为可能的分类器提供程序数组时遇到了一些麻烦
不好的做法,我犯了一个错误,服务应该直接注入,而不是像这样通过数组引用传递:
# the sorting factory (may be contruct with empty array )
cms_content.sorting_factory:
class: '%cms_content.sorting_factory.class%'
arguments: [['@cms_content.sorter.page_nb_asc', '@cms_content.sorter.page_nb_desc', '@cms_content.sorter.date_asc', '@cms_content.sorter.date_desc'], '%cms_content.sorting_factory.default_sorter%']