-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathRadix.php
793 lines (700 loc) · 24.5 KB
/
Radix.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
<?php
/**
@file
@brief Radix PHP Development Toolkit
@see http://radix.edoceo.com/
@copyright 2001-2014 Edoceo, Inc.
@package Radix
@mainpage Radix PHP Toolkit Core Library
@section intro_sec Introduction
Radix PHP is a collection of PHP libraries which can be used for rapid application development.
These libraries are light-weight, relatively fast and simple to understand.
The assumptions is that a few simple implementations of these classes can bring the system to life quickly.
*/
/**
@brief Radix Base Class, Core MVC Utilities
Radix is also the class instantiated for the View object
*/
namespace Edoceo;
class Radix
{
const OK = 200;
const NOT_FOUND = 404;
private static $_module_list;
private static $_file_list = array();
private static $_route_list = array();
private static $_exec_res; // Result of exec()
private static $_view_res; // Result of view()
protected static $_m; // Module
protected static $_c; // Controller
protected static $_a = 'index'; // Action
public static $theme_name = 'html';
public static $theme_bail = 'bail';
public static $root; // Filesystem root of Application
public static $host; // Hostname
public static $base; // Web-Base of Application ( "/" or "/something" )
public static $path; // Path of Request in Application "/" is main page
public static $osua; // Operating System and User Agent - Well Known Only
// Other's can set more Public Stuff on this Object
public static $view; // The View Object
public $body; // Body of the Response
private function __construct() { /* Only I may dance */ }
/**
Our Autoloader Handler
*/
public static function autoload()
{
if (!defined('RADIX_ROOT')) {
define('RADIX_ROOT', __DIR__);
}
spl_autoload_register(function($c) {
$file = str_replace('Radix\\', null, $c);
$file = str_replace('\\', '/', $file);
$path = sprintf('%s/lib/%s.php', RADIX_ROOT, $file);
// echo "require_once($path);\n";
if (is_file($path)) {
require_once($path);
}
});
}
/**
Initialize the Radix System
@param array $opts specfiy: root, theme, theme_bail
@return void
*/
public static function init($opts=null)
{
// My Hostname
self::$host = (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] :
( isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : ($_SERVER['SERVER_ADDR']) ) );
// Root of Application
if (isset($opts['root'])) {
self::$root = $opts['root'];
} else {
// We are Generally Rooted one-up from the Handler
self::$root = dirname(dirname($_SERVER['SCRIPT_FILENAME'])); // Should be webroot/index.php
}
// Base of Application
self::$base = Radix::base();
// Path of Request
self::$path = Radix::path();
// Possible Module Name? /(\w+)/.+
if (preg_match('|^/(\w+)/.+|',self::$path,$m)) {
self::$_m = $m[1];
}
if (!empty($opts['theme'])) {
self::$theme_name = $opts['theme'];
}
if (!empty($opts['theme_bail'])) {
self::$theme_bail = $opts['theme_bail'];
}
if (empty(self::$view)) {
self::$view = new Radix();
}
}
/**
Create a new Route, routes are only process once (that is, no cascade/recurse)
@param $src = the source path, regular expression (with capture)
@param $dst = the destination path
@param $arg = the by-ref argument of where to put the matched stuff
*/
public static function route($src=null,$dst=null,&$arg=null)
{
// Accept the $src as RE, but escape only the '/'
$src = str_replace('/','\/',$src);
self::$_route_list[] = array(
'src' => $src,
'dst' => $dst,
'arg' => $arg,
);
// @deprecated - over-rides existing pages/scripts cause it's in front
// we want routes to trigger if no Controller/View Found
if (preg_match("/$src/i",$_SERVER['REQUEST_URI'],$m)) {
Radix::$path = $dst;
if ($arg !== null) {
$arg = array_merge($arg,$m);
} else {
$_GET = array_merge($_GET,$m);
}
}
// die( $src );
// if (preg_match(
}
/**
*/
public static function stat()
{
// Check Controller
$path = self::$path;
while ( (!empty($path)) && ('/' != $path) ) {
$file = sprintf('%s/controller/%s.php',self::$root,trim($path,'/'));
if (is_file($file)) return true;
$path = dirname($path);
}
// Check Views
$list = array();
// Module View
if (!empty(self::$m)) {
$list[sprintf('%s/view/%s.php',self::$m,self::$path)] = -1;
}
if (self::$_a == 'index') {
$list[] = sprintf('%s/view/%s/index.php',self::$root,self::$path);
}
// Theme Specific View
$list[] = sprintf('%s/theme/%s/view/%s.php',self::$root,self::$theme_name,self::$path);
// Standard View
$list[] = sprintf('%s/view/%s.php',self::$root,self::$path);
foreach ($list as $file) {
if (is_file($file)) return true;
}
return false;
}
/**
Execute the Controller for the Request
Searches /controller from most specific to least specific path
@return name of controller on success, array of attempted files on failure
*/
public static function exec()
{
$path = self::$path;
$list = array();
$temp = array();
foreach (explode('/', $path) as $x) {
$x = trim($x);
if (empty($x)) continue;
$temp[] = $x;
$list[] = sprintf('%s/controller/%s.php', self::$root, implode('/', $temp));
}
// while ( (!empty($path)) && ('/' != $path) ) {
// $list[] = sprintf('%s/controller/%s.php',self::$root,trim($path,'/'));
// $path = dirname($path);
// }
if (self::$_a == 'index') {
$list[] = sprintf('%s/controller/%s/index.php',self::$root,trim(self::$path, '/'));
}
ob_start();
$res = self::$view->_include($list, false);
self::$view->body.= ob_get_clean();
self::$_exec_res = $res;
return self::$_exec_res;
}
/**
render the view body
*/
public static function view()
{
$list = array();
// Module View
if (!empty(self::$m)) {
$list[sprintf('%s/view/%s.php',self::$m,self::$path)] = -1;
}
if (self::$_a == 'index') {
$list[] = sprintf('%s/view/%s/index.php',self::$root,self::$path);
}
// Theme Specific View
$list[] = sprintf('%s/theme/%s/view/%s.php',self::$root,self::$theme_name,self::$path);
// Standard View
$list[] = sprintf('%s/view/%s.php',self::$root,self::$path);
ob_start();
$res = self::$view->_include($list);
self::$view->body.= ob_get_clean();
self::$_view_res = $res;
return self::$_view_res;
}
/**
Sends the Results from the exec() and view() as page
@return 200|404
*/
static function send()
{
ob_start();
// Bail on Error?
// die('self::$_view_res ' . self::$_view_res . "\n");
if (self::$_view_res !== self::OK) {
$v = self::$_view_res;
self::$_view_res = self::OK;
radix::bail($v);
return(0);
}
$list = array(
sprintf('%s/theme/%s.php',self::$root,self::$theme_name),
// sprintf('%s/theme/%s/layout.php',self::$root,self::$theme_name),
);
if (self::$view->_include($list)) {
ob_end_flush();
return(0);
}
// No Layout? Use This Built-In
if (empty($_ENV['title'])) $_ENV['title'] = 'radix';
echo "<!doctype html>\n";
echo "<html>\n";
echo '<head><meta http-equiv="content-type" content="text/html;charset=utf-8" />';
echo '<title>' . $_ENV['title'] .'</title>';
echo '</head><body>';
echo '<div>' . self::$view->body . '</div>';
echo '</body></html>';
ob_end_flush();
}
/**
Respond with an HTTP 400 or 500 level Error Message
@see http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
@param $opt int or text for error message or array('body'=>null), default 500
@return never
*/
static function bail($opt=null)
{
if (empty(self::$view)) {
self::$view = new Radix();
}
// self::$view->body = ob_get_clean();
self::$_view_res = self::OK;
// ob_end_flush();
if ($opt === null) $opt = 500;
if (is_int($opt)) {
$opt = array('code' => $opt);
} elseif (is_string($opt)) {
$opt = array('code' => 500,'text' => $opt);
} elseif (is_array($opt)) {
if (!empty($opt['theme'])) {
self::$theme_name = $opt['theme'];
}
}
// Change Text
switch ($opt['code']) {
case 400:
$opt['text'] = 'Bad Request';
break;
case 401:
$opt['text'] = 'Not Authorized';
break;
case 402:
$opt['text'] = 'Payment Required';
break;
case 403:
$opt['text'] = 'Forbidden';
break;
case 404:
$opt['text'] = 'Not Found';
break;
case 405:
$opt['text'] = 'Method Not Allowed';
break;
case 406:
$opt['text'] = 'Not Acceptable';
break;
case 409:
$opt['text'] = 'Conflict';
break;
case 410:
$opt['text'] = 'Gone';
break;
case 500:
default:
if (empty($opt['text'])) {
$opt['text'] = 'Unexpected System Error';
}
break;
}
header(sprintf('HTTP/1.1 %d %s',$opt['code'],$opt['text']));
if (empty(self::$view->body)) {
self::$view->body = $opt['text'];
}
self::send();
exit(0);
}
/**
Engage trap handler for error and exceptions
Also the routine that is used to trap errors and exceptions
@param $ecode Error or Exception, true to engage, false to disable
@param $ecode as Error Handler the Error Code
@see http://php.net/manual/en/function.set-error-handler.php
@param $etext Text Passed in when trap is called as Handler
@param $efile File Passed in when trap is called as Handler
@param $eline Line Passed in when trap is called as Handler
@param $edata Args Passed in when trap is called as Handler
*/
static function trap($ecode,$etext=null,$efile=null,$eline=null,$edata=null)
{
// Engage myself as the error handler?
if ((true === $ecode) && (null === $etext)) {
set_error_handler(array('radix', 'trap'));
set_exception_handler(array('radix', 'trap'));
return(true);
}
$body = null;
// An Error
if (is_numeric($ecode)) {
// Ignore Errors Not Being Shown
$er = error_reporting();
if (($ecode & $er) != $er) return false;
$body = "<h1>Error: $ecode: $etext in $efile@$eline</h1>";
} elseif (is_object($ecode)) { // Exception
$body = '<h1>Exception: ' . $ecode->getMessage() . '</h1>';
$body.= '<h2>' . $ecode->getFile() . ' @' . $ecode->getLine() . '</h2>';
if ($x = $ecode->getPrevious()) {
$body.= '<h2>From: ' . $x->getMessage() . '</h2>';
$body.= '<h3>' . $x->getFile() . ' @' . $x->getLine() . '</h2>';
}
$body.= '<pre>';
$body.= $ecode->getTraceAsString();
$body.= '</pre>';
}
// Trap Existing Buffer
$buf = '';
while (ob_get_level() > 0) {
$buf.= ob_get_clean();
}
if (strlen($buf)) {
$body.= '<div><h3>Output Buffer</h3><pre>' . htmlspecialchars($buf, ENT_QUOTES, 'utf-8', false) . '</pre></div>';
}
header($_SERVER['SERVER_PROTOCOL'] . ' 500 Server Error', true, 500);
$_ENV['title'] = 'Server Error';
try {
// @todo reset view to 'error'
// @todo insert 'error' layout as option
// @todo insert 'error' theme as option
self::$view = new Radix();
self::$_view_res = self::OK;
self::$view->body = $body;
self::send();
} catch (Exception $e) {
die('Fatal Exception: ' . $e->getMessage());
}
die(500);
}
/**
@full true|false*, true to return full URI base
@return uri base of the application
@note site's at the root are '/' otherwise '/path/'
*/
public static function base($full=false)
{
$base = null;
if ($full) {
// Find Hostname
$host = $_SERVER['SERVER_NAME'];
if (empty($host)) $host = $_SERVER['SERVER_ADDR'];
// Scheme, Hostname & Port
$base = 'http://';
$port = 80;
if ('on' == $_SERVER['HTTPS'] || ('https' == $_SERVER['HTTP_X_FORWARDED_PROTO'])) {
$base = 'https://';
$port = 443;
}
$base.= $host;
if ($_SERVER['SERVER_PORT'] != $port) {
$base.= ':' . $_SERVER['SERVER_PORT'];
}
$base = rtrim($base, '.');
}
// Apache:
// [SCRIPT_FILENAME] => /opt/edoceo/app/imperium.git/webroot/index.php
// [SCRIPT_NAME] => /imperium.git/index.php
// Dirname of the Path of the SCRIPT_NAME which is the handler
$path = dirname(parse_url($_SERVER['SCRIPT_NAME'],PHP_URL_PATH));
$path = trim($path, '.');
$base.= $path;
return rtrim($base,'/');;
}
/**
@return path of current request, with leading /
*/
public static function path()
{
// @todo Find First Best one and break loop
// $list = array('PATH_INFO','SCRIPT_URI');
$path = null;
if (isset($_SERVER['HTTP_X_REWRITE_URL'])) {
$path = $_SERVER['HTTP_X_REWRITE_URL'];
} elseif (isset($_SERVER['REQUEST_URI'])) {
$q = strpos($_SERVER['REQUEST_URI'], '?');
if ($q === false) {
$path = $_SERVER['REQUEST_URI'];
} else {
$path = substr($_SERVER['REQUEST_URI'], 0, $q);
}
} elseif (isset($_SERVER['ORIG_PATH_INFO'])) { // IIS 5.0, PHP as CGI
// Ignored?
} elseif (isset($_SERVER['SCRIPT_URL'])) {
$path = $_SERVER['SCRIPT_URL'];
} elseif (isset($_SERVER['REDIRECT_URL'])) {
$path = $_SERVER['REDIRECT_URL'];
} elseif (isset($_SERVER['PHP_SELF'])) {
$path = $_SERVER['PHP_SELF'];
} elseif (isset($_SERVER['SCRIPT_NAME'])) {
$path = $_SERVER['SCRIPT_NAME'];
if (isset($_SERVER['PATH_INFO'])) {
$path.= $_SERVER['PATH_INFO'];
}
}
$path = parse_url($path,PHP_URL_PATH);
// If there is a Base value, remove it
if (self::$base != '/') {
$path = str_replace(self::$base,null,$path);
}
// Refine
if (empty($path)) $path = '/';
if ($path == '/') $path = '/index';
return $path;
}
/**
@return True if AJAX requested
*/
public static function isAjax($ua=null)
{
$chk = strtolower($ua == null ? $_SERVER['HTTP_X_REQUESTED_WITH'] : $ua);
return ('xmlhttprequest' == $chk);
}
/**
Info function returns text/html or text/plain about the radix system
@return string html
*/
public static function info()
{
$html = null;
$html.= 'root:' . self::$root . '<br>'; // Root Path of Application
$html.= 'host:' . self::$host . '<br>'; // Hostname
$html.= 'base:' . self::$base . '<br>'; // Web-Base of Application ( "/" or "/something" )
$html.= 'path:' . self::$path . '<br>'; // Path of Request in Application
$html.= 'exec()==' . self::$_exec_res . '<br>';
$html.= 'view()==' . self::$_view_res . '<br>';
$html.= 'files:<br>';
foreach (self::$_file_list as $k=>$v) {
$html.= ('+' . $k . ' = ' . $v . '<br>');
}
$html.= 'routes:<br>';
foreach (self::$_route_list as $k=>$v) {
$html.= ('@' . htmlspecialchars($v['src']) . ' = ' . htmlspecialchars($v['dst']) . '<br>');
}
// $html.= 'module:self::$m"; // Module of Request?
// $html.= "view:$view; // The View Object
if (php_sapi_name() == 'cli') {
$html = strip_tags(str_replace('<br>',"\n",$html));
}
return $html;
}
/**
Dumps Var to output
@param $data the stuff to dump
@return void
*/
static function dump($data)
{
if (php_sapi_name() != 'cli') {
echo '<pre>' . htmlspecialchars(print_r($data,true)) . '</pre>';
} else {
echo ("\n" . print_r($data,true) . "\n");
}
}
/**
Dumps a var and traces how we got here
@param $x the var to assert on
@return exits if var, like assert
*/
static function trace($x=null)
{
$buf = null;
$dbt = debug_backtrace();
$idx = 0;
foreach ($dbt as $sf) {
// if (empty($sf['file'])) $sf['file'] = '{main}';
// if (empty($sf['line'])) $sf['line'] = 0;
$buf.= sprintf('%d: ',$idx++);
if (!empty($sf['file'])) {
$buf.= sprintf('%s:%d',$sf['file'],$sf['line']);
$buf.= "\n ";
}
if (!empty($sf['class'])) {
$buf.= sprintf('%s%s',$sf['class'],$sf['type']);
}
$buf.= sprintf('%s(',$sf['function']);
// $buf.=
// Skip This One
// if ((isset($s['function'])) && ($s['function']=='local_error_handler')) continue;
$arg = array();
if (is_array($sf['args'])) foreach ($sf['args'] as $a) {
switch (strtolower(gettype($a))) {
case 'integer':
case 'double':
$arg[] = $a;
break;
case 'string':
$a = htmlspecialchars(substr($a, 0, 16)).((strlen($a) > 16) ? '...' : '');
$arg[] = "\"$a\"";
break;
case 'array':
$arg[] = 'Array('.count($a).')';
break;
case 'object':
$arg[] = 'Object('.get_class($a).')';
break;
case 'resource':
$arg[] = 'Resource('.strstr($a, '#').')';
break;
case 'boolean':
$arg[] = ($a ? 'TRUE' : 'FALSE');
break;
case 'null':
$arg[] = 'null';
break;
default:
$arg[] = strtolower(gettype($a)) . '?';
}
}
$buf.= implode(', ',$arg);
$buf.= ")\n";
}
// Radix::dump($sf);
// Output (should do something with ob_?)
self::dump($buf); // echo "<pre>$buf</pre>";
if ($x) {
self::dump($x);
exit(0);
}
}
/**
@param $uri to redirect to
@param $code HTTP code, default 302, or full HTTP status line
*/
public static function redirect($uri=null,$code=302)
{
// Special Case of Missing
if (empty($uri)) {
$uri = $_SERVER['HTTP_REFERER'];
}
if (empty($uri)) {
$uri = '/';
}
$hs = headers_sent();
if ($hs === false) {
switch ($code) {
case 301:
// Convert to GET
header('HTTP/1.1 301 Moved Permanently', true, $code);
break;
case 302:
// Confirm re-POST
header('HTTP/1.1 302 Found', true, $code);
break;
case 303:
// dont cache, always use GET
header('HTTP/1.1 303 See Other', true, $code);
break;
case 304:
// use cache
header('HTTP/1.1 304 Not Modified', true, $code);
break;
case 305:
header('HTTP/1.1 305 Use Proxy', true, $code);
break;
// case 306:
// header("306 Not Used HTTP/1.1",true,$code);
// break;
case 307:
header('HTTP/1.1 307 Temporary Redirect', true, $code);
break;
default:
// Pass Directly
if (preg_match('/^HTTP\/1.1 (\d{3})/', $code, $m)) {
header($code, true, $m[1]);
}
break;
}
header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
header("Location: $uri");
}
// Show the HTML?
if (($hs==true) || ($code==302) || ($code==303)) {
// todo: draw some javascript to redirect
$cover_div_style = 'background-color: #ccc; height: 100%; left: 0px; position: absolute; top: 0px; width: 100%;';
echo "<div style='$cover_div_style'>\n";
$link_div_style = 'background-color: #fff; border: 2px solid #f00; left: 0px; margin: 5px; padding: 3px; ';
$link_div_style.= 'position: absolute; text-align: center; top: 0px; width: 95%; z-index: 99;';
echo "<div style='$link_div_style'>\n";
echo "<p>Please See: <a href='$uri'>".htmlspecialchars($uri)."</a></p>\n";
echo "</div>\n</div>\n";
}
exit(0);
}
/**
Output a file from the ./block directory
Has access to self::$view (or $this->view) as the View object
@param $name file name, extension added if missing
@param $data to share
*/
static function block($name,$data=null)
{
// Add Extension if Missing
$x = pathinfo($name,PATHINFO_EXTENSION);
if (empty($x)) {
$name.= '.php';
}
$file = sprintf('%s/block/%s',self::$root,ltrim($name,'/'));
if (is_file($file)) {
ob_start();
include($file);
$html = ob_get_clean();
return $html;
}
}
/**
Wrapper for htmlentities
*/
static function h($x,$twice=false)
{
if (is_array($x)) $x = print_r($x,true);
return htmlentities($x,ENT_QUOTES,'utf-8',$twice);
}
/**
Relative Link to this Base
@param $path is application path, starting with '/' or schema://
@param $args query string parameters
*/
static function link($path,$args=null)
{
// No Schema == Local
if (!preg_match('/^\w+:\/\//',$path)) {
$path = sprintf('%s/%s',rtrim(self::$base,'/'),ltrim($path,'/'));
}
// Add Args
if ( (is_array($args)) && (count($args)>0) ) {
$path.= '?' . http_build_query($args);
}
return $path;
}
/**
Given a list of files, include the first
@return from included file
*/
private function _include($list,$once=true)
{
//syslog(LOG_DEBUG,'Radix::include_file()');
// Promote to Array
if (!is_array($list)) {
$list = array($list);
}
// Loop
foreach ($list as $file) {
$r = self::NOT_FOUND;
self::$_file_list[$file] = 'fail:404';
if (is_file($file)) {
$r = $this->_include_file($file);
// 0 if included file says "return(0);"
// 1 to promote include() success to HTTP OK
if ( ($r === 0) || ($r === 1) ) $r = self::OK;
self::$_file_list[$file] = sprintf('load:%d',$r);
if ($once) return($r);
}
}
return ($r);
}
/**
Includes the requested file with an mostly empty var space
@param $f the file
@return the return value from include
*/
private function _include_file($f)
{
return include($f);
}
}