Radix Base Class, Core MVC Utilities Radix is also the class instantiated for the View object.
More...
Radix Base Class, Core MVC Utilities Radix is also the class instantiated for the View object.
Definition at line 24 of file Radix.php.
| Radix::_include |
( |
|
$list, |
|
|
|
$once = true |
|
) |
| |
|
private |
Given a list of files, include the first
- Returns
- from included file
Definition at line 683 of file Radix.php.
687 if (!is_array($list)) {
688 $list = array($list);
692 foreach ($list as $file) {
693 self::$_file_list[$file] =
'fail:404';
694 if (is_file($file)) {
698 if ( ($r === 0) || ($r === 1) ) $r = self::OK;
699 self::$_file_list[$file] = sprintf(
'load:%d',$r);
703 return self::NOT_FOUND;
| Radix::_include_file |
( |
|
$f | ) |
|
|
private |
Includes the requested file with an mostly empty var space
- Parameters
-
- Returns
- the return value from include
Definition at line 711 of file Radix.php.
| static Radix::bail |
( |
|
$opt = null | ) |
|
|
static |
Respond with an HTTP 400 or 500 level Error Message
- See Also
- http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
- Parameters
-
| $opt | int or text for error message or array('body'=>null), default 500 |
- Returns
- never
Definition at line 249 of file Radix.php.
251 if (empty(self::$view)) {
252 self::$view =
new Radix();
254 self::$view->body = ob_get_clean();
255 self::$_view_res = self::OK;
258 if ($opt === null) $opt = 500;
261 $opt = array(
'code' => $opt);
262 } elseif (is_string($opt)) {
263 $opt = array(
'code' => 500,
'text' => $opt);
264 } elseif (is_array($opt)) {
265 if (!empty($opt[
'theme'])) {
266 self::$theme_name = $opt[
'theme'];
271 switch ($opt[
'code']) {
273 $opt[
'text'] =
'Bad Request';
276 $opt[
'text'] =
'Not Authorized';
279 $opt[
'text'] =
'Payment Required';
282 $opt[
'text'] =
'Forbidden';
285 $opt[
'text'] =
'Not Found';
288 $opt[
'text'] =
'Method Not Allowed';
291 $opt[
'text'] =
'Not Acceptable';
294 $opt[
'text'] =
'Conflict';
297 $opt[
'text'] =
'Gone';
301 if (empty($opt[
'text'])) {
302 $opt[
'text'] =
'Unexpected System Error';
306 header(sprintf(
'HTTP/1.1 %d %s',$opt[
'code'],$opt[
'text']));
307 if (empty(self::$view->body)) {
308 self::$view->body = $opt[
'text'];
| static Radix::base |
( |
|
$full = false | ) |
|
|
static |
- Returns
- uri base of the application
- Note
- site's at the root are '/' otherwise '/path/'
Definition at line 360 of file Radix.php.
365 $host = @$_SERVER[
'HTTP_HOST'];
366 if (empty(
$host))
$host = $_SERVER[
'SERVER_NAME'];
367 if (empty(
$host))
$host = $_SERVER[
'SERVER_ADDR'];
371 if ($_SERVER[
'SERVER_PORT'] != 80) {
372 $base =
'http://' .
$host .
':' . $_SERVER[
'SERVER_PORT'];
374 if (isset($_SERVER[
'HTTPS'])) {
376 if ($_SERVER[
'SERVER_PORT'] != 443) {
377 $base =
'http://' .
$host .
':' . $_SERVER[
'SERVER_PORT'];
382 $base.= dirname(parse_url($_SERVER[
'SCRIPT_NAME'],PHP_URL_PATH));
383 return rtrim(
$base,
'/');;
| static Radix::block |
( |
|
$name, |
|
|
|
$data = null |
|
) |
| |
|
static |
Output a file from the ./block directory Has access to self::$view (or $this->view) as the View object
- Parameters
-
| $name | file name, extension added if missing |
| $data | to share |
Definition at line 644 of file Radix.php.
647 $x = pathinfo($name,PATHINFO_EXTENSION);
652 $file = sprintf(
'%s/block/%s',self::$root,ltrim($name,
'/'));
653 if (is_file($file)) {
656 $html = ob_get_clean();
| static Radix::dump |
( |
|
$data | ) |
|
|
static |
- Parameters
-
- Returns
- debug dumping
Definition at line 439 of file Radix.php.
441 if (php_sapi_name() !=
'cli') {
442 echo
'<pre>' . htmlspecialchars(print_r($data,
true)) .
'</pre>';
444 echo (
"\n" . print_r($data,
true) .
"\n");
Execute the Controller for the Request Searches /controller from most specific to least specific path
- Returns
- name of controller on success, array of attempted files on failure
Definition at line 164 of file Radix.php.
168 $list[] = sprintf(
'%s/controller/%s.php',self::$root,trim(
$path,
'/'));
172 $res = self::$view->_include($list);
173 self::$view->body.= ob_get_clean();
174 self::$_exec_res = $res;
175 return self::$_exec_res;
Info function returns text/html or text/plain about the radix system
- Returns
- string html
Definition at line 452 of file Radix.php.
455 $html.=
'root:' . self::$root .
'<br>';
456 $html.=
'host:' . self::$host .
'<br>';
457 $html.=
'base:' . self::$base .
'<br>';
458 $html.=
'path:' . self::$path .
'<br>';
459 $html.=
'exec()==' . self::$_exec_res .
'<br>';
460 $html.=
'view()==' . self::$_view_res .
'<br>';
461 $html.=
'files:<br>';
462 foreach (self::$_file_list as $k=>$v) {
463 $html.= (
'+' . $k .
' = ' . $v .
'<br>');
465 $html.=
'routes:<br>';
466 foreach (self::$_route_list as $k=>$v) {
467 $html.= (
'@' . htmlspecialchars($v[
'src']) .
' = ' . htmlspecialchars($v[
'dst']) .
'<br>');
471 if (php_sapi_name() ==
'cli') {
472 $html = strip_tags(str_replace(
'<br>',
"\n",$html));
| static Radix::init |
( |
|
$opts = null | ) |
|
|
static |
Initialize the Radix System
- Parameters
-
| array | $opts | specfiy: root, theme, theme_bail |
- Returns
- void
Definition at line 60 of file Radix.php.
63 self::$host = (isset($_SERVER[
'HTTP_HOST']) ? $_SERVER[
'HTTP_HOST'] :
64 ( isset($_SERVER[
'SERVER_NAME']) ? $_SERVER[
'SERVER_NAME'] : ($_SERVER[
'SERVER_ADDR']) ) );
67 if (isset($opts[
'root'])) {
68 self::$root = $opts[
'root'];
71 self::$root = dirname(dirname($_SERVER[
'SCRIPT_FILENAME']));
79 if (preg_match(
'|^/(\w+)/.+|',self::$path,$m)) {
83 if (!empty($opts[
'theme'])) {
84 self::$theme_name = $opts[
'theme'];
86 if (!empty($opts[
'theme_bail'])) {
87 self::$theme_bail = $opts[
'theme_bail'];
90 if (empty(self::$view)) {
91 self::$view =
new Radix();
| static Radix::isAjax |
( |
|
$ua = null | ) |
|
|
static |
Definition at line 429 of file Radix.php.
431 $chk = strtolower($ua == null ? $_SERVER[
'HTTP_X_REQUESTED_WITH'] : $ua);
432 return (
'xmlhttprequest' == $chk);
| static Radix::link |
( |
|
$path, |
|
|
|
$args = null |
|
) |
| |
|
static |
Relative Link to this Base
- Parameters
-
| $path | is application path, starting with '/' or schema:// |
| $args | query string parameters |
Definition at line 666 of file Radix.php.
669 if (!preg_match(
'/^\w+:\/\//',
$path)) {
670 $path = sprintf(
'%s/%s',rtrim(self::$base,
'/'),ltrim(
$path,
'/'));
673 if ( (is_array($args)) && (count($args)>0) ) {
674 $path.=
'?' . http_build_query($args);
- Returns
- path of current request, with leading /
Definition at line 389 of file Radix.php.
394 if (isset($_SERVER[
'HTTP_X_REWRITE_URL'])) {
395 $path = $_SERVER[
'HTTP_X_REWRITE_URL'];
396 } elseif (isset($_SERVER[
'REQUEST_URI'])) {
397 $q = strpos($_SERVER[
'REQUEST_URI'],
'?');
399 $path = $_SERVER[
'REQUEST_URI'];
401 $path = substr($_SERVER[
'REQUEST_URI'], 0, $q);
403 } elseif (isset($_SERVER[
'ORIG_PATH_INFO'])) {
405 } elseif (isset($_SERVER[
'SCRIPT_URL'])) {
406 $path = $_SERVER[
'SCRIPT_URL'];
407 } elseif (isset($_SERVER[
'REDIRECT_URL'])) {
408 $path = $_SERVER[
'REDIRECT_URL'];
409 } elseif (isset($_SERVER[
'PHP_SELF'])) {
410 $path = $_SERVER[
'PHP_SELF'];
411 } elseif (isset($_SERVER[
'SCRIPT_NAME'])) {
412 $path = $_SERVER[
'SCRIPT_NAME'];
413 if (isset($_SERVER[
'PATH_INFO'])) {
414 $path.= $_SERVER[
'PATH_INFO'];
419 if (self::$base !=
'/') {
| static Radix::redirect |
( |
|
$uri = null, |
|
|
|
$code = 302 |
|
) |
| |
|
static |
- Parameters
-
| string | $uri | to redirect to |
| int | $code | HTTP code, default 302, or full HTTP status line |
Definition at line 543 of file Radix.php.
547 $uri = $_SERVER[
'HTTP_REFERER'];
555 if (substr($uri,0,4)==
'http') {
558 $location = self::base(
true);
560 if (substr($uri,0,2) ==
'//') {
561 $location .=
'/' . ltrim($uri,
'/');
562 } elseif (substr($uri,0,1) ==
'/') {
563 $location .=
'/' . ltrim($uri,
'/');
585 $hs = headers_sent();
590 header(
"301 Moved Permanently HTTP/1.1",
true,$code);
594 header(
"302 Found HTTP/1.1",
true,$code);
598 header(
"303 See Other HTTP/1.1",
true,$code);
602 header(
"304 Not Modified HTTP/1.1",
true,$code);
605 header(
"305 Use Proxy HTTP/1.1",
true,$code);
611 header(
"307 Temporary Redirect HTTP/1.1",
true,$code);
615 if (preg_match(
'/^(\d{3}) .+ HTTP\/1\.[01]/',$code,$m)) {
616 header($code,
true,$m[1]);
620 header(
'Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
621 header(
"Location: $location");
624 if (($hs==
true) || ($code==302) || ($code==303)) {
626 $cover_div_style =
'background-color: #ccc; height: 100%; left: 0px; position: absolute; top: 0px; width: 100%;';
627 echo
"<div style='$cover_div_style'>\n";
628 $link_div_style =
'background-color: #fff; border: 2px solid #f00; left: 0px; margin: 5px; padding: 3px; ';
629 $link_div_style.=
'position: absolute; text-align: center; top: 0px; width: 95%; z-index: 99;';
630 echo
"<div style='$link_div_style'>\n";
631 echo
"<p>Please See: <a href='$uri'>".htmlspecialchars($location).
"</a></p>\n";
632 echo
"</div>\n</div>\n";
| static Radix::route |
( |
|
$src = null, |
|
|
|
$dst = null, |
|
|
& |
$arg = null |
|
) |
| |
|
static |
Create a new Route, routes are only process once (that is, no cascade/recurse)
- Parameters
-
| $src | = the source path, regular expression (with capture) |
| $dst | = the destination path |
| $arg | = the by-ref argument of where to put the matched stuff |
Definition at line 102 of file Radix.php.
105 $src = str_replace(
'/',
'\/',$src);
106 self::$_route_list[] = array(
114 if (preg_match(
"/$src/i",$_SERVER[
'REQUEST_URI'],$m)) {
117 $arg = array_merge($arg,$m);
119 $_GET = array_merge($_GET,$m);
Sends the Results from the exec() and view() as page
- Returns
- 200|404
Definition at line 207 of file Radix.php.
213 if (self::$_view_res !== self::OK) {
214 $v = self::$_view_res;
215 self::$_view_res = self::OK;
221 sprintf(
'%s/theme/%s.php',self::$root,self::$theme_name),
231 if (empty($_ENV[
'title'])) $_ENV[
'title'] =
'radix';
232 echo
"<!doctype html>\n";
234 echo
'<head><meta http-equiv="content-type" content="text/html;charset=utf-8" />';
235 echo
'<title>' . $_ENV[
'title'] .
'</title>';
236 echo
'</head><body>';
237 echo
'<div>' . self::$view->body .
'</div>';
238 echo
'</body></html>';
Definition at line 129 of file Radix.php.
134 $file = sprintf(
'%s/controller/%s.php',self::$root,trim(
$path,
'/'));
135 if (is_file($file))
return true;
142 if (!empty(self::$m)) {
143 $list[sprintf(
'%s/view/%s.php',self::$m,self::$path)] = -1;
145 if (self::$_a ==
'index') {
146 $list[] = sprintf(
'%s/view/%s/index.php',self::$root,self::$path);
149 $list[] = sprintf(
'%s/theme/%s/view/%s.php',self::$root,self::$theme_name,self::$path);
151 $list[] = sprintf(
'%s/view/%s.php',self::$root,self::$path);
152 foreach ($list as $file) {
153 if (is_file($file))
return true;
| static Radix::trace |
( |
|
$x = null | ) |
|
|
static |
Dumps a var and traces how we got here
- Parameters
-
- Returns
- exits if var, like assert
Definition at line 482 of file Radix.php.
485 $dbt = debug_backtrace();
487 foreach ($dbt as $sf) {
489 $buf.= sprintf(
'%d: ',$idx++);
490 $buf.= sprintf(
'%s:%d',$sf[
'file'],$sf[
'line']);
492 if (!empty($sf[
'class'])) {
493 $buf.= sprintf(
'%s%s',$sf[
'class'],$sf[
'type']);
495 $buf.= sprintf(
'%s(',$sf[
'function']);
500 if (is_array($sf[
'args']))
foreach ($sf[
'args'] as $a) {
501 switch (strtolower(gettype($a))) {
507 $a = htmlspecialchars(substr($a, 0, 16)).((strlen($a) > 16) ?
'...' :
'');
511 $arg[] =
'Array('.count($a).
')';
514 $arg[] =
'Object('.get_class($a).
')';
517 $arg[] =
'Resource('.strstr($a,
'#').
')';
520 $arg[] = ($a ?
'True' :
'False');
526 $arg[] = strtolower(gettype($a)) .
'?';
529 $buf.= implode(
', ',$arg);
534 if ($x) self::dump($x);
Engage trap handler for error and exceptions Also the routine that is used to trap errors and exceptions
Definition at line 318 of file Radix.php.
322 if ( ($e_code ===
true) && ($e_text === null) ) {
329 syslog(LOG_ERR,
"I have had a fatal error");
330 file_put_contents(
'/tmp/custos.err',print_r(debug_backtrace(),
true));
338 set_exception_handler(null);
346 self::$view =
new Radix(
'error' );
347 self::$view->path =
'error';
350 }
catch (Exception $e) {
351 die(
'Really fatal error here');
353 die(sprintf(
'%s#%d',__FILE__,__LINE__));
render the view body
Definition at line 181 of file Radix.php.
185 if (!empty(self::$m)) {
186 $list[sprintf(
'%s/view/%s.php',self::$m,self::$path)] = -1;
188 if (self::$_a ==
'index') {
189 $list[] = sprintf(
'%s/view/%s/index.php',self::$root,self::$path);
192 $list[] = sprintf(
'%s/theme/%s/view/%s.php',self::$root,self::$theme_name,self::$path);
194 $list[] = sprintf(
'%s/view/%s.php',self::$root,self::$path);
197 $res = self::$view->_include($list);
198 self::$view->body.= ob_get_clean();
199 self::$_view_res = $res;
200 return self::$_view_res;
| Radix::$_file_list = array() |
|
staticprivate |
| Radix::$_route_list = array() |
|
staticprivate |
| Radix::$theme_bail = 'bail' |
|
static |
| Radix::$theme_name = 'html' |
|
static |
| const Radix::NOT_FOUND = 404 |
The documentation for this class was generated from the following file: