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')) return;
27 var $priority = 0; # rule priority (rules are applied in ascending order)
28 # -100 = application escape, +100 = application unescape
29 var $name; # rule's name
30 var $author; # rule's author
31 var $url; # rule's homepage
32 var $package; # rule belongs to package
33 var $version; # rule version
34 var $test; # rule test function
35 var $disabled=false; # true if rule is disabled
38 ## the rule will be applied if the text...
40 var $if_chars; # ...contains one of these chars
41 var $if_str; # ...contains this string (case sensitive)
42 var $if_stri; # ...contains this string (case insensitive)
43 var $if_match; # ...matches this simple expr
46 ## rule effectors, matching
48 var $type; # 'preg' (default), 'str', 'all', 'split'...
49 var $match; # matching string or expression
51 # var $limit; # limit number of applications (unused)
53 ## rule effectors, replacing
55 var $replace; # replace match with this expression
58 var $is_callback=false; # $replace is a callback function
59 var $is_wheel; # flag to create a sub-wheel from rules given as replace
60 var $pick_match = 0; # item to pick for sub-wheel replace
61 var $glue = null; # glue for implode ending split rule
65 var $require; # file to require_once
66 var $create_replace; # do create_function('$m', %) on $this->replace, $m is the matched array
76 public function TextWheelRule($args) {
79 foreach($args as $k=>$v)
80 if (property_exists($this, $k))
81 $this->$k = $args[$k];
82 $this->checkValidity(); // check that the rule is valid
88 protected function checkValidity(){
89 if ($this->type
=='split'){
90 if (is_array($this->match
))
91 throw new InvalidArgumentException('match argument for split rule can\'t be an array');
92 if (isset($this->glue
) AND is_array($this->glue
))
93 throw new InvalidArgumentException('glue argument for split rule can\'t be an array');