Definition at line 32 of file servlet.php.
Public Member Functions | |
| add ($name, $attrs) | |
| Adds attributes. | |
| add_to_errorlist ($msg) | |
| Adds message to the errorlist. | |
| array_convert (&$var, $src) | |
| Array convertor for req() and opt(). | |
| create_doc () | |
| Resets the output document. | |
| fill_errormsg (&$errormsg, $name) | |
| If the $errormsg is empty, it fills it with default text 'Please enter $name. | |
| get_doc () | |
| get_page () | |
| get_page_name () | |
| This should return page name without extension. | |
| get_referer () | |
| This should return page URL. | |
| get_title () | |
| This should return page title. | |
| int_convert (&$var, $src) | |
| Integer convertor for req() and opt(). | |
| onoff_convert (&$var, $src) | |
| On/Off (good for checkboxes) convertor for req() and opt(). | |
| opt ($name, &$var, $src, $convertor) | |
| Like req(), but if the variable is not found, it simply returns without generating an error and without touching $var. | |
| opt_array ($name, &$var, $src) | |
| opt_get_array ($name, &$var) | |
| opt_get_int ($name, &$var) | |
| opt_get_onoff ($name, &$var) | |
| opt_get_string ($name, &$var) | |
| opt_get_yesno ($name, &$var) | |
| opt_int ($name, &$var, $src) | |
| opt_onoff ($name, &$var, $src) | |
| opt_post_array ($name, &$var) | |
| opt_post_int ($name, &$var) | |
| opt_post_onoff ($name, &$var) | |
| opt_post_string ($name, &$var) | |
| opt_post_yesno ($name, &$var) | |
| opt_string ($name, &$var, $src) | |
| opt_yesno ($name, &$var, $src) | |
| page_attr ($name, $value) | |
| Adds page attribute. | |
| page_elems ($name, $elems, $where=NULL) | |
| Adds page elements. | |
| req ($name, &$var, $errormsg, $src, $convertor) | |
| Requests a variable named $name from array $src and after converting it with $convertor() its put into $var. | |
| req_array ($name, &$var, $errormsg, $src) | |
| req_get_array ($name, &$var, $errormsg= ') | |
| req_get_int ($name, &$var, $errormsg= ') | |
| req_get_onoff ($name, &$var, $errormsg= ') | |
| req_get_string ($name, &$var, $errormsg= ') | |
| req_get_yesno ($name, &$var, $errormsg= ') | |
| req_int ($name, &$var, $errormsg, $src) | |
| req_onoff ($name, &$var, $errormsg, $src) | |
| req_post_array ($name, &$var, $errormsg= ') | |
| req_post_int ($name, &$var, $errormsg= ') | |
| req_post_onoff ($name, &$var, $errormsg= ') | |
| req_post_string ($name, &$var, $errormsg= ') | |
| req_post_yesno ($name, &$var, $errormsg= ') | |
| req_string ($name, &$var, $errormsg, $src) | |
| req_yesno ($name, &$var, $errormsg, $src) | |
| run () | |
| Call this on your servlet to start the action. | |
| show ($pagename) | |
| Renders page to HTML and sends it to browser. | |
| string_convert (&$var, $src) | |
| String convertor for req() and opt(). | |
| validate_input () | |
| This function is called after starting the servlet, to check if all required parameters are OK. | |
| work () | |
| You should do your application logic here. | |
| yesno_convert (&$var, $src) | |
| Yes/No (good for radiobuttons) convertor for req() and opt(). | |
Private Attributes | |
| $doc | |
| DomDocument of the resulting page. | |
| $errorlist = array() | |
| List with error messages. | |
| $page | |
| Base page DomElement. | |
Static Private Attributes | |
| static | $control_characters |
| used by string_convert() | |
| static | $replacement |
| used by string_convert() | |
|
||||||||||||
|
Adds attributes.
Definition at line 429 of file servlet.php. References page_elems(). Referenced by run(). 00429 {
00430 $elem = $this->doc->createElement($name);
00431 foreach ($attrs as $name => $value):
00432 if (is_array($value)):
00433 $this->page_elems($name, $value, $elem);
00434 else:
00435 $elem->setAttribute($name, $value);
00436 endif;
00437 endforeach;
00438 $this->page->appendChild($elem);
00439 }
|
|
|
Adds message to the errorlist.
Definition at line 44 of file servlet.php. Referenced by req(), and run(). 00044 {
00045 $this->errorlist[] = $msg;
00046 }
|
|
||||||||||||
|
Array convertor for req() and opt().
Definition at line 156 of file servlet.php. Referenced by opt_array(), and req_array(). 00156 {
00157 if (!is_array($src) or count($src) == 0):
00158 return FALSE;
00159 endif;
00160 $var = $src;
00161 return TRUE;
00162 }
|
|
|
Resets the output document.
Definition at line 390 of file servlet.php. Referenced by run(). 00390 {
00391 $this->doc = new DomDocument();
00392 $this->page = $this->doc->createElement('page');
00393 $this->doc->appendChild($this->page);
00394 }
|
|
||||||||||||
|
If the $errormsg is empty, it fills it with default text 'Please enter $name. '
Definition at line 54 of file servlet.php. Referenced by req(). 00054 {
00055 if ($errormsg == ''):
00056 $errormsg = "Please enter $name.";
00057 endif;
00058 }
|
|
|
Definition at line 469 of file servlet.php. 00469 {
00470 return $this->doc;
00471 }
|
|
|
Definition at line 476 of file servlet.php. 00476 {
00477 return $this->page;
00478 }
|
|
|
This should return page name without extension. Based on this value it is located XSLT stylesheet in the view subdir. On default it returns 'index'. Definition at line 334 of file servlet.php. Referenced by get_referer(). 00334 { return 'index'; }
|
|
|
This should return page URL. By default it returns $this->get_page_name() . '.php'. See sources for exact behaviour. Definition at line 346 of file servlet.php. References get_page_name(), and starts_with(). Referenced by show(). 00346 {
00347 $pagename = $this->get_page_name();
00348 if ($pagename == 'index' or starts_with('do_', $pagename)):
00349 return '';
00350 endif;
00351 return $pagename . '.php';
00352 }
|
|
|
This should return page title.
Definition at line 339 of file servlet.php. 00339 { return ''; }
|
|
||||||||||||
|
Integer convertor for req() and opt().
Definition at line 144 of file servlet.php. Referenced by opt_int(), and req_int(). 00144 {
00145 $src = (int) $src;
00146 if ($src === 0):
00147 return FALSE;
00148 endif;
00149 $var = $src;
00150 return TRUE;
00151 }
|
|
||||||||||||
|
On/Off (good for checkboxes) convertor for req() and opt().
Definition at line 132 of file servlet.php. Referenced by opt_onoff(), and req_onoff(). 00132 {
00133 if ($src):
00134 $var = 1;
00135 else:
00136 $var = 0;
00137 endif;
00138 return TRUE;
00139 }
|
|
||||||||||||||||||||
|
Like req(), but if the variable is not found, it simply returns without generating an error and without touching $var.
Definition at line 84 of file servlet.php. Referenced by opt_array(), opt_int(), opt_onoff(), opt_string(), and opt_yesno(). 00084 {
00085 if (isset($src[$name])):
00086 $this->$convertor($var, $src[$name]);
00087 endif;
00088 }
|
|
||||||||||||||||
|
Definition at line 204 of file servlet.php. References array_convert(), and opt(). Referenced by opt_get_array(), and opt_post_array(). 00204 {
00205 $this->opt($name, $var, $src, 'array_convert');
00206 }
|
|
||||||||||||
|
Definition at line 304 of file servlet.php. References opt_array(). 00304 {
00305 $this->opt_array($name, $var, $_GET);
00306 }
|
|
||||||||||||
|
Definition at line 284 of file servlet.php. References opt_int(). 00284 {
00285 $this->opt_int($name, $var, $_GET);
00286 }
|
|
||||||||||||
|
Definition at line 264 of file servlet.php. References opt_onoff(). 00264 {
00265 $this->opt_onoff($name, $var, $_GET);
00266 }
|
|
||||||||||||
|
Definition at line 224 of file servlet.php. References opt_string(). 00224 {
00225 $this->opt_string($name, $var, $_GET);
00226 }
|
|
||||||||||||
|
Definition at line 244 of file servlet.php. References opt_yesno(). 00244 {
00245 $this->opt_yesno($name, $var, $_GET);
00246 }
|
|
||||||||||||||||
|
Definition at line 196 of file servlet.php. References int_convert(), and opt(). Referenced by opt_get_int(), and opt_post_int(). 00196 {
00197 $this->opt($name, $var, $src, 'int_convert');
00198 }
|
|
||||||||||||||||
|
Definition at line 188 of file servlet.php. References onoff_convert(), and opt(). Referenced by opt_get_onoff(), and opt_post_onoff(). 00188 {
00189 $this->opt($name, $var, $src, 'onoff_convert');
00190 }
|
|
||||||||||||
|
Definition at line 300 of file servlet.php. References opt_array(). 00300 {
00301 $this->opt_array($name, $var, $_POST);
00302 }
|
|
||||||||||||
|
Definition at line 280 of file servlet.php. References opt_int(). 00280 {
00281 $this->opt_int($name, $var, $_POST);
00282 }
|
|
||||||||||||
|
Definition at line 260 of file servlet.php. References opt_onoff(). 00260 {
00261 $this->opt_onoff($name, $var, $_POST);
00262 }
|
|
||||||||||||
|
Definition at line 220 of file servlet.php. References opt_string(). 00220 {
00221 $this->opt_string($name, $var, $_POST);
00222 }
|
|
||||||||||||
|
Definition at line 240 of file servlet.php. References opt_yesno(). 00240 {
00241 $this->opt_yesno($name, $var, $_POST);
00242 }
|
|
||||||||||||||||
|
Definition at line 172 of file servlet.php. References opt(), and string_convert(). Referenced by opt_get_string(), and opt_post_string(). 00172 {
00173 $this->opt($name, $var, $src, 'string_convert');
00174 }
|
|
||||||||||||||||
|
Definition at line 180 of file servlet.php. References opt(), and yesno_convert(). Referenced by opt_get_yesno(), and opt_post_yesno(). 00180 {
00181 $this->opt($name, $var, $src, 'yesno_convert');
00182 }
|
|
||||||||||||
|
Adds page attribute.
Definition at line 399 of file servlet.php. Referenced by show(). 00399 {
00400 $this->page->setAttribute($name, $value);
00401 }
|
|
||||||||||||||||
|
Adds page elements.
Definition at line 410 of file servlet.php. Referenced by add(). 00410 {
00411 $container = $this->doc->createElement($name);
00412 foreach ($elems as $elem):
00413 $container->appendChild($elem);
00414 endforeach;
00415 if (!$where):
00416 $where = $this->page;
00417 endif;
00418 $where->appendChild($container);
00419 }
|
|
||||||||||||||||||||||||
|
Requests a variable named $name from array $src and after converting it with $convertor() its put into $var. If its not found, error message $errormsg is inserted into error list.
Definition at line 72 of file servlet.php. References add_to_errorlist(), and fill_errormsg(). Referenced by req_array(), req_int(), req_onoff(), req_string(), and req_yesno(). 00072 {
00073 if (!isset($src[$name]) || !$this->$convertor($var, $src[$name])):
00074 $this->fill_errormsg($errormsg, $name);
00075 $this->add_to_errorlist($errormsg);
00076 endif;
00077 }
|
|
||||||||||||||||||||
|
Definition at line 200 of file servlet.php. References array_convert(), and req(). Referenced by req_get_array(), and req_post_array(). 00200 {
00201 $this->req($name, $var, $errormsg, $src, 'array_convert');
00202 }
|
|
||||||||||||||||
|
Definition at line 296 of file servlet.php. References req_array(). 00296 {
00297 $this->req_array($name, $var, $errormsg, $_GET);
00298 }
|
|
||||||||||||||||
|
Definition at line 276 of file servlet.php. References req_int(). 00276 {
00277 $this->req_int($name, $var, $errormsg, $_GET);
00278 }
|
|
||||||||||||||||
|
Definition at line 256 of file servlet.php. References req_onoff(). 00256 {
00257 $this->req_onoff($name, $var, $errormsg, $_GET);
00258 }
|
|
||||||||||||||||
|
Definition at line 216 of file servlet.php. References req_string(). 00216 {
00217 $this->req_string($name, $var, $errormsg, $_GET);
00218 }
|
|
||||||||||||||||
|
Definition at line 236 of file servlet.php. References req_yesno(). 00236 {
00237 $this->req_yesno($name, $var, $errormsg, $_GET);
00238 }
|
|
||||||||||||||||||||
|
Definition at line 192 of file servlet.php. References int_convert(), and req(). Referenced by req_get_int(), and req_post_int(). 00192 {
00193 $this->req($name, $var, $errormsg, $src, 'int_convert');
00194 }
|
|
||||||||||||||||||||
|
Definition at line 184 of file servlet.php. References onoff_convert(), and req(). Referenced by req_get_onoff(), and req_post_onoff(). 00184 {
00185 $this->req($name, $var, $errormsg, $src, 'onoff_convert');
00186 }
|
|
||||||||||||||||
|
Definition at line 292 of file servlet.php. References req_array(). 00292 {
00293 $this->req_array($name, $var, $errormsg, $_POST);
00294 }
|
|
||||||||||||||||
|
Definition at line 272 of file servlet.php. References req_int(). 00272 {
00273 $this->req_int($name, $var, $errormsg, $_POST);
00274 }
|
|
||||||||||||||||
|
Definition at line 252 of file servlet.php. References req_onoff(). 00252 {
00253 $this->req_onoff($name, $var, $errormsg, $_POST);
00254 }
|
|
||||||||||||||||
|
Definition at line 212 of file servlet.php. References req_string(). 00212 {
00213 $this->req_string($name, $var, $errormsg, $_POST);
00214 }
|
|
||||||||||||||||
|
Definition at line 232 of file servlet.php. References req_yesno(). 00232 {
00233 $this->req_yesno($name, $var, $errormsg, $_POST);
00234 }
|
|
||||||||||||||||||||
|
Definition at line 168 of file servlet.php. References req(), and string_convert(). Referenced by req_get_string(), and req_post_string(). 00168 {
00169 $this->req($name, $var, $errormsg, $src, 'string_convert');
00170 }
|
|
||||||||||||||||||||
|
Definition at line 176 of file servlet.php. References req(), and yesno_convert(). Referenced by req_get_yesno(), and req_post_yesno(). 00176 {
00177 $this->req($name, $var, $errormsg, $src, 'yesno_convert');
00178 }
|
|
|
Call this on your servlet to start the action.
Definition at line 358 of file servlet.php. References add(), add_to_errorlist(), create_doc(), show(), validate_input(), and work(). 00358 {
00359 $this->create_doc();
00360
00361 try {
00362 $this->validate_input();
00363 } catch (Exception $e) {
00364 $this->add_to_errorlist($e->getMessage());
00365 }
00366
00367 if (count($this->errorlist) > 0):
00368 foreach ($this->errorlist as $errormsg):
00369 $this->add('msg', array('desc' => $errormsg));
00370 endforeach;
00371 $this->show('error');
00372 exit;
00373 endif;
00374
00375 try {
00376 $this->work();
00377 } catch (Exception $e) {
00378 $this->create_doc(); // reset the document
00379 $this->add('msg', array('desc' => $e->getMessage()));
00380 $this->show('error');
00381 exit;
00382 }
00383
00384 $this->show($this->get_page_name());
00385 }
|
|
|
Renders page to HTML and sends it to browser.
Definition at line 445 of file servlet.php. References get_referer(), page_attr(), and url(). Referenced by run(). 00445 {
00446 $xsl = new DomDocument();
00447 $xsl->load("view/$pagename.xsl");
00448
00449 $proc = new xsltprocessor();
00450 $proc->importStylesheet($xsl);
00451
00452 $this->page_attr('title', $this->get_title());
00453
00454 $referer = $this->get_referer();
00455 if ($referer):
00456 $this->page_attr('referer', '?r=' . url($referer));
00457 endif;
00458
00459 if (isset($_SESSION['user'])):
00460 $this->page_attr('login', $_SESSION['user']['name']);
00461 endif;
00462
00463 echo $proc->transformToXML($this->doc);
00464 }
|
|
||||||||||||
|
String convertor for req() and opt().
Definition at line 104 of file servlet.php. Referenced by opt_string(), and req_string(). 00104 {
00105 // we remove all control (i.e. with ASCII value lower than 0x20 (space),
00106 // except of 0x0A (line feed) and 0x09 (tabulator)
00107 $src = strtr($src, Servlet::$control_characters, Servlet::$replacement);
00108 $src = str_replace("\r", '', $src); // \r === \x0D
00109 $src = trim($src);
00110 if ($src === ''):
00111 return FALSE;
00112 endif;
00113 $var = $src;
00114 return TRUE;
00115 }
|
|
|
This function is called after starting the servlet, to check if all required parameters are OK. Instead of just throwing an exception on error, it should locate as much of problems as possible and add then to the error list. This function MAY NOT generate any page content.
Definition at line 321 of file servlet.php. Referenced by run(). 00321 {}
|
|
|
You should do your application logic here.
Definition at line 327 of file servlet.php. Referenced by run(). 00327 {}
|
|
||||||||||||
|
Yes/No (good for radiobuttons) convertor for req() and opt().
Definition at line 120 of file servlet.php. Referenced by opt_yesno(), and req_yesno(). 00120 {
00121 switch ($src):
00122 case '1': $var = 1; break;
00123 case '0': $var = 0; break;
00124 default: return FALSE;
00125 endswitch;
00126 return TRUE;
00127 }
|
|
|
Initial value:
"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x0B\x0C\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F"
Definition at line 95 of file servlet.php. |
|
|
DomDocument of the resulting page.
Definition at line 37 of file servlet.php. |
|
|
List with error messages.
Definition at line 35 of file servlet.php. |
|
|
Base page DomElement.
Definition at line 39 of file servlet.php. |
|
|
Initial value:
"\x0D\x0D\x0D\x0D\x0D\x0D\x0D\x0D\x0D\x0D\x0D\x0D\x0D\x0D\x0D\x0D\x0D\x0D\x0D\x0D\x0D\x0D\x0D\x0D\x0D\x0D\x0D\x0D\x0D"
Definition at line 98 of file servlet.php. |
1.4.2