1

我目前正在使用 FOSCommentBundle 来获取 Rest api 最佳实践的示例

在此捆绑包中使用具有不同选项的排序器(或排序)服务,使用日期 asc 和日期 desc 进行排序,但此服务未注入排序提供程序数组(在排序类服务内)

通过“页码”或“日期”范围以 oder page 的方式重用 this

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%']

我在使用分类工厂内声明为私有的服务作为可能的分类器提供者数组时遇到了一些麻烦

4

1 回答 1

0

不好的做法,我犯了一个错误,应该直接注入服务,而不是像这样通过数组引用传递:

# 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%']
于 2017-05-03T19:04:35.543 回答