00001 <?php
00011 class STrans extends SObject {
00018 protected $parent;
00019 protected $page;
00020
00023 protected $transHelper;
00026 protected $transHelperClass = "";
00027
00030 protected $transHelperCustom;
00033 protected $transHelperCustomClass = "";
00034
00037 protected $options = array();
00040 protected $inputOptions = array();
00041
00046 public function doc() {
00047 return "STrans is the parent translator class that all ther PR2"
00048 . " translators should extend.";
00049 }
00050
00056 public function __construct ($parent) {
00057 $this->parent = $parent;
00058 $this->page = $parent->getPage();
00059
00060
00061
00062 if ($this->transHelperClass != "") {
00063
00064
00065 $helper = $this->parent->getClassInstance($this->transHelperClass);
00066
00067
00068 if (!$helper){
00069 $this->setPrettyError("construct", "Can't retain a helper translator object. Object was not created.");
00070 return false;
00071 }
00072
00073
00074 $this->transHelper = $helper;
00075 $this->transHelper->setTranslator($this);
00076 }
00077 }
00078
00079
00080
00081
00082
00083
00090 public function getInFormat() {
00091 return $this->getOption('inFormat');
00092 }
00093
00100 public function getOutFormat() {
00101 return $this->getOption('outFormat');
00102 }
00103
00104
00105
00106
00107
00108
00119 public function translate ($si)
00120 {
00121
00122
00123 if ($this->hasError()) {
00124 $this->setPrettyError("translate",
00125 "This translator has logged errors; translation halted.");
00126 return false;
00127 }
00128
00129
00130
00131 if($si->getOption('trans_helper') != "") {
00132
00133 $this->transHelperCustomClass = $si->getOption('trans_helper');
00134
00135
00136 $helper = $this->parent->getClassInstance($this->transHelperCustomClass);
00137
00138
00139 if (!$helper){
00140 $this->setPrettyError("construct", "Can't retain a custom helper translator "
00141 . "object. Object was not created.");
00142 return false;
00143 }
00144
00145
00146
00147 $this->transHelperCustom = $helper;
00148 $this->transHelperCustom->setTranslator($this);
00149 }
00150 return true;
00151 }
00152
00153
00154
00155
00156
00157
00167 public function sendToTarget ($si, $input)
00168 {
00169 $target = $si->getOption('trans_target');
00170 $appendFn = ($si->getOption('trans_mode') == 'append') ? 'appendToSlot' : 'setSlot';
00171 $this->page->$appendFn($target, $input);
00172 }
00173
00180 public function setOption ($key, $value)
00181 { $this->options[$key] = $value; }
00182
00190 public function getOption($key)
00191 { if (isset($this->options[$key])) return $this->options[$key];
00192 else return $this->parent->getOption($key); }
00193
00199 public function setInputOptions($options) {
00200 $this->inputOptions = $options;
00201 }
00202
00209 public function setInputOption ($key, $value)
00210 { $this->inputOptions[$key] = $value; }
00211
00218 function getInputOption($key)
00219 { if (isset($this->inputOptions[$key])) return $this->inputOptions[$key];
00220 else return null; }
00221
00222
00230 function getPageRender() {
00231 return $this->parent;
00232 }
00233 }
00234
00235 ?>