smilesrg/pipelineparser-bundle

FOSCommentBundle 的管道注释解析器

dev-master 2015-03-30 18:01 UTC

This package is not auto-updated.

Last update: 2024-09-28 17:17:52 UTC


README

FOSCommentBundle 的管道注释解析器。想象一下,你需要集成 ExerciseHTMLPurifierBundle 解析器、标签解析器、用户提及解析器……最好有多个解析器,每个解析器负责其自身的操作。这就是我决定编写这个包的原因。这个包是为了创建解析器类链(管道)而编写的。

#使用方法

首先,将解析器类配置为服务。你不必使用这个包提供的所有解析器。这个包的主要解析器是 PipelineParser,它为解析器类提供管道。

    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 ]

然后,你需要将 PipelineParser 定义为一个服务,并使用解析器进行配置。

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

解析器的顺序很重要。首先添加到管道中的解析器将首先执行。

最后一步是按照文档中的描述使用管道解析器。

# app/config/config.yml

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