.

TextPlaceholderBase Class Reference

Basic implementation of a text placeholder. More...

Inheritance diagram for TextPlaceholderBase:
ITextPlaceholder

List of all members.

Public Member Functions

  __constructor ($cmd)
  apply ($text)
  Apply on given text.

Protected Member Functions

  build_regex ()
  Build the tegex used to find placeholders.
  do_apply ($params)
  Appyl params.

Protected Attributes

  $cmd = ''

Detailed Description

Basic implementation of a text placeholder.

Looks for placeholders of form {command:a[:b...]}, that is a command and a list of parameters, separated by double colon and wrapped in curly brackets.

Attention:
There must be at least one parameter!

This base class must be instantiated with the command.

Definition at line 13 of file textplaceholder.base.cls.php.


Member Function Documentation

TextPlaceholderBase::__constructor ( cmd  ) 

Definition at line 16 of file textplaceholder.base.cls.php.

00016                                             {
00017                 $this->cmd = $cmd;
00018         }
TextPlaceholderBase::apply ( text  ) 

Apply on given text.

Parameters:
string  $text
Returns:
string

Implements ITextPlaceholder.

Definition at line 26 of file textplaceholder.base.cls.php.

00026                                      {
00027                 $ret = $text;
00028                 $matches = array();
00029                 String::preg_match_all($this->build_regex(), $ret, $matches, PREG_SET_ORDER);
00030                 foreach($matches as $match) {
00031                         $params = explode(':', $match[1]);
00032                         $replace = $this->do_apply($params);
00033                         if ($replace !== false) {
00034                                 $ret = str_replace($match[0], $replace, $ret);
00035                         }
00036                 }       
00037                 return $ret;
00038         }       
TextPlaceholderBase::build_regex (  )  [protected]

Build the tegex used to find placeholders.

Returns:
string

Definition at line 45 of file textplaceholder.base.cls.php.

00045                                          {
00046                 $cmd = preg_quote($this->cmd);
00047                 return "@{{$cmd}:(.*?)}@i";
00048         }
TextPlaceholderBase::do_apply ( params  )  [protected]

Appyl params.

Parameters:
array  $params
Returns:
string Replacement or FALSE if $params are invalid

Definition at line 56 of file textplaceholder.base.cls.php.

00056                                              {
00057                 return false;
00058         }

Member Data Documentation

TextPlaceholderBase::$cmd = '' [protected]

Definition at line 14 of file textplaceholder.base.cls.php.


The documentation for this class was generated from the following file: