mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
44b68061d4
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@40456 467b73ca-7a2a-4603-9d3b-597d59a354a9
51 lines
1.7 KiB
PHP
51 lines
1.7 KiB
PHP
<?php
|
|
/**
|
|
* Parses text in a variety of ways.
|
|
*
|
|
* Called from a template by $Content.Parse(SubClassName), similar to $Content.XML.
|
|
* This will work on any Text database field (Or a sub-class, such as HTMLText,
|
|
* although it's usefulness in this situation is more limited).
|
|
*
|
|
* Any sub-classes of TextParser must implement a parse() method.
|
|
* This should take $this->content and parse it however you want. For an example
|
|
* of the implementation, @see BBCodeParser.
|
|
*
|
|
* Your sub-class will be initialized with a string of text, then parse() will be called.
|
|
* parse() should (after processing) return the formatted string.
|
|
*
|
|
* Note: $this->content will have NO conversions applied to it.
|
|
* You should run Covert::raw2xml or whatever is appropriate before using it.
|
|
*
|
|
* Optionally (but recommended), is creating a static usable_tags method,
|
|
* which will return a DataObjectSet of all the usable tags that can be parsed.
|
|
* This will (mostly) be used to create helper blocks - telling users what things will be parsed.
|
|
* Again, @see BBCodeParser for an example of the syntax
|
|
*
|
|
* TODO Define a proper syntax for (or refactor) usable_tags that can be extended as needed.
|
|
*/
|
|
abstract class TextParser extends Object {
|
|
protected $content;
|
|
|
|
/**
|
|
* Creates a new TextParser object.
|
|
*
|
|
* @param string $content The contents of the dbfield
|
|
*/
|
|
function __construct($content = "") {
|
|
$this->content = $content;
|
|
}
|
|
|
|
/**
|
|
* Convenience method, shouldn't really be used, but it's here if you want it
|
|
*/
|
|
function setContent($content = "") {
|
|
$this->content = $content;
|
|
}
|
|
|
|
/**
|
|
* Define your own parse method to parse $this->content appropriately.
|
|
* See the class doc-block for more implementation details.
|
|
*/
|
|
abstract function parse();
|
|
}
|
|
?>
|