定制 smilesrg/pipelineparser-bundle 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

smilesrg/pipelineparser-bundle

Composer 安装命令:

composer require smilesrg/pipelineparser-bundle

包简介

Pipeline comments parser for FOSCommentBundle

README 文档

README

Pipeline comments parser for FOSCommentBundle. Imagine that you need to integrate ExerciseHTMLPurifierBundle parser, hashtag parser, user mention parser... it's better to have several parsers where each is responsible for their actions. That's why I decided to write this bundle. This bundle is written for make chain (pipeline) of parser classes.

#Usage

First, configure parser classes as services. You don't have to use all parsers that this bundle provides. The main parser of this bundle is PipelineParser which provides pipeline for parser classes.

    markup.mention_parser:
        #This is implementation of simple user mentioning parser like Twitter does
        class: Smilesrg\PipelineParserBundle\Parser\UserMentionParser
        # If you don't plan to use this parser somewhere in the code, it's better to make it private.
        # this should increase service container performance
        public: false
        arguments:
            - @fos_user.user_manager # FOS User Manager
            - @router # Router itself
            - "user_profile_show" # The route for showing user profile
            - "/\B\@([\w\-@]+)/im" # The regular expression pattern for user mentioning

    # See https://github.com/FriendsOfSymfony/FOSCommentBundle/blob/master/Resources/doc/9a-markup_htmlpurifier.md
    markup.exercise_html_purifier:
        class: FOS\CommentBundle\Markup\HtmlPurifier
        arguments: [ @exercise_html_purifier.default ]

Then, you have to define PipelineParser as a service and configure it with parsers.

    markuper.pipeline_parser:
        class: Smilesrg\PipelineParserBundle\Parser\PipelineParser
        calls:
            - [addToPipeline, ["@markup.exercise_html_purifier"]]
            - [addToPipeline, ["@markup.mention_parser"]]

The order of parsers is important. First parser that has been added to pipeline is executed first.

The last step is to use pipeline parser as described in documentation

# app/config/config.yml

fos_comment:
    service:
        markup: markuper.pipeline_parser # The pipeline parser service

统计信息

  • 总下载量: 6
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-03-30