6 * let's reinvent the wheel one last time
8 * This library of code is meant to be a fast and universal replacement
9 * for any and all text-processing systems written in PHP
11 * It is dual-licensed for any use under the GNU/GPL2 and MIT licenses,
14 * (c) 2009 Fil - fil@rezo.net
15 * Documentation & http://zzz.rezo.net/-TextWheel-
17 * Usage: $wheel = new TextWheel(); echo $wheel->text($text);
21 if (!defined('_ECRIRE_INC_VERSION')) {
29 public $priority = 0; # rule priority (rules are applied in ascending order)
30 # -100 = application escape, +100 = application unescape
31 public $name; # rule's name
32 public $author; # rule's author
33 public $url; # rule's homepage
34 public $package; # rule belongs to package
35 public $version; # rule version
36 public $test; # rule test function
37 public $disabled = false; # true if rule is disabled
40 ## the rule will be applied if the text...
42 public $if_chars; # ...contains one of these chars
43 public $if_str; # ...contains this string (case sensitive)
44 public $if_stri; # ...contains this string (case insensitive)
45 public $if_match; # ...matches this simple expr
48 ## rule effectors, matching
50 public $type; # 'preg' (default), 'str', 'all', 'split'...
51 public $match; # matching string or expression
53 # var $limit; # limit number of applications (unused)
55 ## rule effectors, replacing
57 public $replace; # replace match with this expression
60 public $is_callback = false; # $replace is a callback function
61 public $is_wheel; # flag to create a sub-wheel from rules given as replace
62 public $pick_match = 0; # item to pick for sub-wheel replace
63 public $glue = null; # glue for implode ending split rule
67 public $require; # file to require_once
68 public $create_replace; # do create_function('$m', %) on $this->replace, $m is the matched array
79 public function __construct($args) {
80 if (!is_array($args)) {
83 foreach ($args as $k => $v) {
84 if (property_exists($this, $k)) {
85 $this->$k = $args[$k];
88 $this->checkValidity(); // check that the rule is valid
94 protected function checkValidity() {
95 if ($this->type
== 'split') {
96 if (is_array($this->match
)) {
97 throw new InvalidArgumentException('match argument for split rule can\'t be an array');
99 if (isset($this->glue
) and is_array($this->glue
)) {
100 throw new InvalidArgumentException('glue argument for split rule can\'t be an array');