Source for file Decorators.php
Documentation is available at Decorators.php
/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2002 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.02 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/3_0.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Alexander Zhukov <alex@veresk.ru> Original port from Python |
// | Authors: Harry Fuecks <hfuecks@phppatterns.com> Port to PEAR + more |
// | Authors: Many @ Sitepointforums Advanced PHP Forums |
// +----------------------------------------------------------------------+
// $Id: Decorators.php 22138 2007-06-01 10:19:14Z markwest $
* Decorators for dealing with parser options
* @version $Id: Decorators.php 22138 2007-06-01 10:19:14Z markwest $
* @see XML_HTMLSax3::set_option
* Trims the contents of element data from whitespace at start and end
* Original handler object
* Original handler method
* Constructs XML_HTMLSax3_Trim
* @param object handler object being decorated
* @param string original handler method
$this->orig_obj = & $orig_obj;
$this->orig_method = $orig_method;
* @param string element data
$this->orig_obj->{$this->orig_method}($parser, $data);
* Coverts tag names to upper case
* Original handler object
* Original open handler method
* Original close handler method
* Constructs XML_HTMLSax3_CaseFolding
* @param object handler object being decorated
* @param string original open handler method
* @param string original close handler method
$this->orig_obj = & $orig_obj;
$this->orig_open_method = $orig_open_method;
$this->orig_close_method = $orig_close_method;
* Folds up open tag callbacks
* @param array tag attributes
function foldOpen(&$parser, $tag, $attrs= array(), $empty = FALSE) {
$this->orig_obj->{$this->orig_open_method}($parser, strtoupper($tag), $attrs, $empty);
* Folds up close tag callbacks
function foldClose(&$parser, $tag, $empty = FALSE) {
$this->orig_obj->{$this->orig_close_method}($parser, strtoupper($tag), $empty);
* Breaks up data by linefeed characters, resulting in additional
* calls to the data handler
* Original handler object
* Original handler method
* Constructs XML_HTMLSax3_LineFeed
* @param object handler object being decorated
* @param string original handler method
$this->orig_obj = & $orig_obj;
$this->orig_method = $orig_method;
* Breaks the data up by linefeeds
* @param string element data
foreach ( $data as $chunk ) {
$this->orig_obj->{$this->orig_method}($parser, $chunk);
* Breaks up data by tab characters, resulting in additional
* calls to the data handler
* Original handler object
* Original handler method
* Constructs XML_HTMLSax3_Tab
* @param object handler object being decorated
* @param string original handler method
$this->orig_obj = & $orig_obj;
$this->orig_method = $orig_method;
* Breaks the data up by linefeeds
* @param string element data
foreach ( $data as $chunk ) {
$this->orig_obj->{$this->orig_method}($this, $chunk);
* Breaks up data by XML entities and parses them with html_entity_decode(),
* resulting in additional calls to the data handler<br />
* Original handler object
* Original handler method
* Constructs XML_HTMLSax3_Entities_Parsed
* @param object handler object being decorated
* @param string original handler method
$this->orig_obj = & $orig_obj;
$this->orig_method = $orig_method;
* Breaks the data up by XML entities
* @param string element data
$data = preg_split('/(&.+?;)/',$data,- 1,PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
foreach ( $data as $chunk ) {
$this->orig_obj->{$this->orig_method}($this, $chunk);
* Compatibility with older PHP versions
* Breaks up data by XML entities but leaves them unparsed,
* resulting in additional calls to the data handler<br />
* Original handler object
* Original handler method
* Constructs XML_HTMLSax3_Entities_Unparsed
* @param object handler object being decorated
* @param string original handler method
$this->orig_obj = & $orig_obj;
$this->orig_method = $orig_method;
* Breaks the data up by XML entities
* @param string element data
$data = preg_split('/(&.+?;)/',$data,- 1,PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
foreach ( $data as $chunk ) {
$this->orig_obj->{$this->orig_method}($this, $chunk);
* Strips the HTML comment markers or CDATA sections from an escape.
* If XML_OPTIONS_FULL_ESCAPES is on, this decorator is not used.<br />
* Original handler object
* Original handler method
* Constructs XML_HTMLSax3_Entities_Unparsed
* @param object handler object being decorated
* @param string original handler method
$this->orig_obj = & $orig_obj;
$this->orig_method = $orig_method;
* Breaks the data up by XML entities
* @param string element data
function strip(&$parser, $data) {
// Check for HTML comments first
if ( substr($data,0,2) == '--' ) {
'/^\-\-/', // Opening comment: --
'/\-\-$/', // Closing comment: --
// Check for XML CDATA sections (note: don't do both!)
} else if ( substr($data,0,1) == '[' ) {
'/^\[.*CDATA.*\[/s', // Opening CDATA
'/\].*\]$/s', // Closing CDATA
$this->orig_obj->{$this->orig_method}($this, $data);
|