/[cvs]/nfo/php/libs/org.netfrag.glib/php_extensions.php
ViewVC logotype

Diff of /nfo/php/libs/org.netfrag.glib/php_extensions.php

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2 by joko, Wed Mar 5 11:58:49 2003 UTC revision 1.7 by joko, Fri Apr 4 17:35:40 2003 UTC
# Line 5  Line 5 
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    
# Line 13  Line 13 
13   * $Id$   * $Id$
14   *   *
15   * $Log$   * $Log$
16   * Revision 1.2  2003/03/05 11:58:49  joko   * Revision 1.7  2003/04/04 17:35:40  joko
17   * modified is_hash, mkInstance and others   * fixed php croaking
18   *   * moved error handling function to 'php_errors.php'
19   * Revision 1.1  2003/03/03 21:08:21  joko   * + function php::maintenance
20   * refactored from flib/utils   *
21     * Revision 1.6  2003/03/11 02:14:18  joko
22     * + fixed metadata for phpDocumentor
23   *   *
24     * Revision 1.5  2003/03/10 22:58:46  joko
25     * + fixed metadata for phpDocumentor
26   *   *
27   */   * Revision 1.4  2003/03/05 23:16:46  joko
28     * updated docu - phpDocumentor is very strict about its 'blocks'...
   
 /**  
  * --- php extension functions  
  *  
  *  x php::Dumper  
  *  x php::session_register_safe  
  *  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  
  *  
  * @author Andreas Motl <andreas.motl@ilo.de>  
  * @copyright (c) 2003 - All Rights reserved.  
  * @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
# Line 79  Line 57 
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();
# Line 105  php::export_symbols(); Line 82  php::export_symbols();
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    
# Line 297  class php { Line 305  class php {
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);
# Line 359  class php { Line 367  class php {
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);
# Line 507  class php { Line 515  class php {
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      }      }
# Line 571  class php { Line 579  class php {
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&uuml;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  ?>  ?>

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.7

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed