5 |
* |
* |
6 |
* @author Andreas Motl <andreas.motl@ilo.de> |
* @author Andreas Motl <andreas.motl@ilo.de> |
7 |
* @package org.netfrag.glib |
* @package org.netfrag.glib |
8 |
* @module php |
* @name php |
9 |
* |
* |
10 |
*/ |
*/ |
11 |
|
|
13 |
* $Id$ |
* $Id$ |
14 |
* |
* |
15 |
* $Log$ |
* $Log$ |
16 |
* Revision 1.1 2003/03/03 21:08:21 joko |
* Revision 1.7 2003/04/04 17:35:40 joko |
17 |
* refactored from flib/utils |
* fixed php croaking |
18 |
* |
* moved error handling function to 'php_errors.php' |
19 |
|
* + function php::maintenance |
20 |
* |
* |
21 |
*/ |
* Revision 1.6 2003/03/11 02:14:18 joko |
22 |
|
* + fixed metadata for phpDocumentor |
|
|
|
|
/** |
|
|
* --- php extension functions |
|
23 |
* |
* |
24 |
* x php::Dumper |
* Revision 1.5 2003/03/10 22:58:46 joko |
25 |
* x php::session_register_safe |
* + fixed metadata for phpDocumentor |
|
* x php::array_init |
|
|
* x php::is_hash |
|
|
* x php::array_join_merge |
|
|
* o php::merge |
|
|
* o php::merge_to |
|
|
* x php::loadModule |
|
|
* x php::mkInstance |
|
26 |
* |
* |
27 |
* @author Andreas Motl <andreas.motl@ilo.de> |
* Revision 1.4 2003/03/05 23:16:46 joko |
28 |
* @copyright (c) 2003 - All Rights reserved. |
* updated docu - phpDocumentor is very strict about its 'blocks'... |
|
* @license GNU LGPL (GNU Lesser General Public License) |
|
29 |
* |
* |
30 |
* @author-url http://www.netfrag.org/~joko/ |
* Revision 1.3 2003/03/05 18:54:41 joko |
31 |
* @license-url http://www.gnu.org/licenses/lgpl.txt |
* updated docu - phpDocumentor is very strict about its 'blocks'... |
32 |
* |
* |
33 |
* @package org.netfrag.glib |
* Revision 1.2 2003/03/05 11:58:49 joko |
34 |
* @module php |
* modified is_hash, mkInstance and others |
35 |
* |
* |
36 |
*/ |
* Revision 1.1 2003/03/03 21:08:21 joko |
37 |
|
* refactored from flib/utils |
|
/** |
|
|
* Todo: |
|
|
* o establish mkInstance here (move from DesignPattern::Object::mkObject) |
|
|
* o establish loadModule here (move from DesignPattern::Object::loadModule) |
|
38 |
* |
* |
|
* Ideas: |
|
|
* o php::create_redirector_function('func', array( type => 'lamba|function|method', name => 'Abc::do_xyz') ) |
|
|
* o php::create_redirector_method('class|obj_ref', 'method', $target) |
|
|
* o php::export_symbol(from, to) (maybe solves above two) |
|
39 |
* |
* |
40 |
*/ |
*/ |
41 |
|
|
42 |
|
|
|
|
|
43 |
/** |
/** |
44 |
* --- shortcut functions |
* --- shortcut functions |
45 |
* Is there a mechanism in php to 'export' these methods |
* Is there a mechanism in php to 'export' these methods |
57 |
* TODO: $php::EXPORT_OK = array('Dumper', 'session_register_safe', 'mkObject', 'is_hash', 'merge_to'); |
* TODO: $php::EXPORT_OK = array('Dumper', 'session_register_safe', 'mkObject', 'is_hash', 'merge_to'); |
58 |
* |
* |
59 |
*/ |
*/ |
|
|
|
60 |
// this is (and will probably always be) required by the "Exporter" |
// this is (and will probably always be) required by the "Exporter" |
61 |
function &Dumper() { |
function &Dumper() { |
62 |
$args = func_get_args(); |
$args = func_get_args(); |
82 |
|
|
83 |
|
|
84 |
/** |
/** |
85 |
* --- php extension functions lying in the php:: namespace |
* --- php extension functions living in the php:: namespace |
86 |
|
* |
87 |
|
* <pre> |
88 |
|
* x php::Dumper |
89 |
|
* x php::session_register_safe |
90 |
|
* x php::array_init |
91 |
|
* x php::is_hash |
92 |
|
* x php::array_join_merge |
93 |
|
* o php::merge |
94 |
|
* o php::merge_to |
95 |
|
* x php::loadModule |
96 |
|
* x php::mkInstance |
97 |
|
* </pre> |
98 |
|
* |
99 |
|
* @author Andreas Motl <andreas.motl@ilo.de> |
100 |
|
* @copyright (c) 2003 - All Rights reserved. |
101 |
|
* @license GNU LGPL (GNU Lesser General Public License) |
102 |
|
* |
103 |
|
* @link http://www.netfrag.org/~joko/ |
104 |
|
* @link http://www.gnu.org/licenses/lgpl.txt |
105 |
|
* |
106 |
|
* @package org.netfrag.glib |
107 |
|
* @name php |
108 |
|
* |
109 |
|
* <pre> |
110 |
|
* Todo: |
111 |
|
* @todo (o) establish mkInstance here (move from DesignPattern::Object::mkObject) |
112 |
|
* @todo (o) establish loadModule here (move from DesignPattern::Object::loadModule) |
113 |
|
* |
114 |
|
* Ideas: |
115 |
|
* @todo (o) php::create_redirector_function('func', array( type => 'lamba|function|method', name => 'Abc::do_xyz') ) |
116 |
|
* @todo (o) php::create_redirector_method('class|obj_ref', 'method', $target) |
117 |
|
* @todo (o) php::export_symbol(from, to) (maybe solves above two) |
118 |
|
* </pre> |
119 |
* |
* |
120 |
*/ |
*/ |
|
|
|
|
|
|
121 |
class php { |
class php { |
122 |
|
|
123 |
|
|
203 |
} |
} |
204 |
|
|
205 |
// from: php.net - http://www.php.net/manual/en/function.array-merge-recursive.php |
// from: php.net - http://www.php.net/manual/en/function.array-merge-recursive.php |
206 |
function is_hash( $var ) { |
function is_hash( $var = null ) { |
207 |
if( is_array( $var ) ) { |
if( is_array( $var ) ) { |
208 |
$keys = array_keys( $var ); |
$keys = array_keys( $var ); |
209 |
$all_num = true; |
$all_num = true; |
305 |
//set_error_handler('php_error_handler'); |
//set_error_handler('php_error_handler'); |
306 |
// TODO: do stack-backtracing here to determine function called two or three levels before!!! |
// TODO: do stack-backtracing here to determine function called two or three levels before!!! |
307 |
//print "file: $filename<br/>"; |
//print "file: $filename<br/>"; |
308 |
if (!include_once($filename)) { |
if (!@include_once($filename)) { |
309 |
$msg = "php::loadModule error: Could not load module '$namespacedClassname', file '$filename' does not exist."; |
$msg = "php::loadModule error: Could not load module '$namespacedClassname', file '$filename' does not exist."; |
310 |
user_error($msg); |
user_error($msg); |
311 |
php::append_log($msg, PEAR_LOG_ERR); |
php::append_log($msg, PEAR_LOG_ERR); |
325 |
function &mkComponent() { |
function &mkComponent() { |
326 |
|
|
327 |
// argument handling - perl style |
// argument handling - perl style |
328 |
$arg_list = func_get_args(); |
$arg_list = &func_get_args(); |
329 |
|
|
330 |
// trace |
// trace |
331 |
//print "php::mkInstance: " . Dumper($arg_list); |
//print "php::mkInstance: " . Dumper($arg_list); |
333 |
|
|
334 |
// patch arglist if all arguments are passed in as a single array |
// patch arglist if all arguments are passed in as a single array |
335 |
if (sizeof($arg_list) == 1 && is_array($arg_list[0])) { |
if (sizeof($arg_list) == 1 && is_array($arg_list[0])) { |
336 |
$arg_list = $arg_list[0]; |
$arg_list = &$arg_list[0]; |
337 |
} |
} |
338 |
|
|
339 |
//print "arg_list: $arg_list<br/>"; |
//print "arg_list: $arg_list<br/>"; |
367 |
|
|
368 |
|
|
369 |
// trace |
// trace |
370 |
//print "mkObject: $classname<br>"; |
//print "mkObject: $classname<br/>"; |
371 |
//print "file: $filename<br>"; |
//print "file: $filename<br/>"; |
372 |
|
|
373 |
// build native class name from namespaced one |
// build native class name from namespaced one |
374 |
$classname = str_replace('::', '_', $classname); |
$classname = str_replace('::', '_', $classname); |
436 |
} |
} |
437 |
} |
} |
438 |
|
|
439 |
function &mkInstance($classname, $attributes = null) { |
function &mkInstance($classname, $attributes = array()) { |
440 |
|
|
441 |
$oo = is_object($this); |
$oo = is_object($this); |
442 |
|
|
486 |
|
|
487 |
$args_pass = array(); |
$args_pass = array(); |
488 |
for ($i=0; $i<=count($attributes); $i++) { |
for ($i=0; $i<=count($attributes); $i++) { |
489 |
array_push($args_pass, '$attributes[' . $i . ']'); |
array_push($args_pass, '&$attributes[' . $i . ']'); |
490 |
} |
} |
491 |
|
|
492 |
$arg_string = join(', ', $args_pass); |
$arg_string = join(', ', $args_pass); |
515 |
//print "eval: $evalstr<br/>"; |
//print "eval: $evalstr<br/>"; |
516 |
|
|
517 |
$instance = eval($evalstr); |
$instance = eval($evalstr); |
518 |
//print $evalstr . "<br>"; |
//print $evalstr . "<br/>"; |
519 |
} else { |
} else { |
520 |
$instance = new $classname; |
$instance = new $classname; |
521 |
} |
} |
579 |
} |
} |
580 |
} |
} |
581 |
|
|
|
|
|
|
} |
|
582 |
|
|
583 |
//function error_handler($errno, $errstr, $errfile, $errline) { |
function maintenance($type = 'system', $options = array()) { |
|
function php_error_handler() { |
|
|
//print "ERROR!<br/>"; |
|
|
$error_raw = func_get_args(); |
|
584 |
|
|
585 |
//print Dumper($error_raw); |
switch ($type) { |
586 |
|
|
587 |
$error = array( |
case 'system': |
588 |
'level' => $error_raw[0], |
print "<br/><br/>"; |
589 |
'message' => $error_raw[1], |
print "<p align=\"center\">We have taken down our systems for maintenance purposes. <br/>Please apologize the downtime.</p>"; |
590 |
'file' => $error_raw[2], |
print "<p align=\"center\">Wir führen gerade Wartungsarbeiten an unseren Systemen durch. <br/>Bitte entschuldigen Sie die Unterbrechung des Betriebs.</p>"; |
591 |
'line' => $error_raw[3], |
|
592 |
'context' => &$error_raw[4], |
print "<br/><br/>"; |
593 |
'object_context' => &$error_raw[4][this], |
print "<p align=\"center\"><a href=\"mailto:info@top-scores.net\">Top-Scores Ltd.</a></p>"; |
594 |
); |
$do_exit = 1; |
595 |
$error[component] = $error[object_context]->_component_name; |
break; |
596 |
|
|
597 |
//$output_order = array( 'message', 'component', 'file', 'line', 'level' ); |
case 'database': |
598 |
$output_order = array( 'message', 'file', 'line' ); |
print " |
599 |
|
Database error, we are already notified of this failure and working to resolve it.<br/> |
600 |
|
We apologize for the inconvenience, please come back later.<br/> |
601 |
|
<br/> |
602 |
|
Es ist ein Datenbankfehler aufgetreten. Wir haben bereits Kenntnis von diesem Fehler, an der Lösung des Problems wird gearbeitet.<br/> |
603 |
|
Bitte versuchen Sie es später nocheinmal.<br/> |
604 |
|
"; |
605 |
|
$do_exit = 1; |
606 |
|
break; |
607 |
|
|
608 |
/* |
case 'rpc': |
609 |
$level = $error[0]; |
|
610 |
$context = &$error[4]; |
// V0 |
611 |
$cc = &$context['this']; |
//return; |
612 |
*/ |
|
613 |
|
// V2 |
614 |
|
// FIXME: implement some more behaviour here! |
615 |
//print Dumper($context); |
// via constants? |
616 |
//print Dumper($cc); |
// e.g.: |
617 |
//print Dumper($cc->_component_name); |
if (!constants::get('APP_MODE_DEBUG_LIGHT')) { return; } |
618 |
|
|
619 |
|
// V1 |
620 |
|
print "<font color=\"red\"><b>FIXME! - in 'php::maintenance(rpc)'</b></font><br/>"; |
621 |
|
print "RPC Problems!<br/>"; |
622 |
|
print "Status:<br/>"; |
623 |
|
print Dumper($options[status]); |
624 |
|
break; |
625 |
|
|
|
// by level |
|
|
//$do_trace = ($level <= 5); |
|
|
|
|
|
//$c_name = $context['this']['_component_name']; |
|
|
|
|
|
//print "c_error: $c_name<br/>"; |
|
|
|
|
|
// if component |
|
|
//$do_trace = isset($context[this][_component_name]); |
|
|
//$do_trace = isset($context->this[_component_name]); |
|
|
//$do_trace = isset($cc->_component_name); |
|
|
$do_trace = isset($error[component]); |
|
|
|
|
|
//$do_trace = 1; |
|
|
|
|
|
//print Dumper($context); |
|
|
|
|
|
if ($do_trace) { |
|
|
|
|
|
//print php::Dumper($error); |
|
|
//exit; |
|
|
|
|
|
//print "<hr/><b><font color=\"red\">ERROR:</font></b><br/>"; |
|
|
print "<b><font color=\"red\">ERROR:</font></b><br/> "; |
|
|
|
|
|
foreach ($output_order as $key) { |
|
|
print "<b>$key:</b> $error[$key]<br/>"; |
|
|
} |
|
|
|
|
626 |
} |
} |
627 |
|
|
628 |
|
if ($options[no_exit]) { $do_exit = 0; } |
629 |
|
if ($do_exit) { |
630 |
|
exit; |
631 |
|
} |
632 |
|
|
633 |
} |
} |
634 |
|
|
635 |
|
|
636 |
|
} |
637 |
|
|
638 |
|
|
639 |
?> |
?> |