Version: current

     1 <?php
     2 /**
     3  * Parses text in a variety of ways.
     4  *
     5  * Called from a template by $Content.Parse(SubClassName), similar to $Content.XML.
     6  * This will work on any Text database field (Or a sub-class, such as HTMLText,
     7  * although it's usefulness in this situation is more limited).
     8  *
     9  * Any sub-classes of TextParser must implement a parse() method.
    10  * This should take $this->content and parse it however you want. For an example
    11  * of the implementation, @see BBCodeParser.
    12  *
    13  * Your sub-class will be initialized with a string of text, then parse() will be called.
    14  * parse() should (after processing) return the formatted string.
    15  *
    16  * Note: $this->content will have NO conversions applied to it.
    17  * You should run Covert::raw2xml or whatever is appropriate before using it.
    18  *
    19  * Optionally (but recommended), is creating a static usable_tags method,
    20  * which will return a DataObjectSet of all the usable tags that can be parsed.
    21  * This will (mostly) be used to create helper blocks - telling users what things will be parsed.
    22  * Again, @see BBCodeParser for an example of the syntax
    23  *
    24  * @todo Define a proper syntax for (or refactor) usable_tags that can be extended as needed.
    25  * @package sapphire
    26  * @subpackage misc
    27  */
    28 abstract class TextParser extends Object {
    29     protected $content;
    30
    31     /**
    32      * Creates a new TextParser object.
    33      *
    34      * @param string $content The contents of the dbfield
    35      */
    36     function __construct($content = "") {
    37         $this->content = $content;
    38     }
    39
    40     /**
    41      * Convenience method, shouldn't really be used, but it's here if you want it
    42      */
    43     function setContent($content = "") {
    44         $this->content = $content;
    45     }
    46
    47     /**
    48      * Define your own parse method to parse $this->content appropriately.
    49      * See the class doc-block for more implementation details.
    50      */
    51     abstract function parse();
    52 }
    53 ?>

[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -