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

Diff of /nfo/php/libs/org.netfrag.glib/DesignPattern/Object.php

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

revision 1.3 by joko, Sun Feb 9 17:16:06 2003 UTC revision 1.7 by joko, Sat Mar 1 21:13:39 2003 UTC
# Line 3  Line 3 
3  //  $Id$  //  $Id$
4  // ---------------------------------------------------------------------------  // ---------------------------------------------------------------------------
5  //  $Log$  //  $Log$
6    //  Revision 1.7  2003/03/01 21:13:39  joko
7    //  modified loadModule (take care!)
8    //
9    //  Revision 1.6  2003/02/28 04:18:13  joko
10    //  + special-case-handling for single argument pass-in
11    //  + testing with constructor autocalling: not used for now since weird sideeffects occoured!
12    //     o however: rethink it completely!
13    //
14    //  Revision 1.5  2003/02/27 16:36:02  joko
15    //  re-allowed underscores ('_') in php classnames
16    //  does this break something?
17    //
18    //  Revision 1.4  2003/02/22 16:34:16  joko
19    //  + minor fix: can seperate namespace identifier with slashes ('/') now
20    //
21  //  Revision 1.3  2003/02/09 17:16:06  joko  //  Revision 1.3  2003/02/09 17:16:06  joko
22  //  + handling arguments perl style ;-)  //  + handling arguments perl style ;-)
23  //  //
# Line 25  class DesignPattern_Object { Line 40  class DesignPattern_Object {
40    
41  function _ns2file($nsName) {  function _ns2file($nsName) {
42    if ($filename  = str_replace('::', '/', $nsName)) {    if ($filename  = str_replace('::', '/', $nsName)) {
     $filename .= '.php';  
43      return $filename;      return $filename;
44    }    }
45  }  }
46    
47  function mkObject() {  function &mkObject() {
48    $arg_list = func_get_args();    $arg_list = func_get_args();
49      
50      // patch arglist if all arguments are passed in as a single array
51      if (count($arg_list) == 1 && is_array($arg_list[0])) {
52        $arg_list = $arg_list[0];
53      }
54      
55  //print Dumper($arg_list);  //print Dumper($arg_list);
56    $namespacedClassname = array_shift($arg_list);    $namespacedClassname = array_shift($arg_list);
57    if (strstr($namespacedClassname, '_')) {    if (strstr($namespacedClassname, '_')) {
58      print "mkObject: unallowed character in namespaced classname: '_' ($namespacedClassname)<br/>";      //print "mkObject: unallowed character in namespaced classname: '_' ($namespacedClassname)<br/>";
59      return;      //return;
60    }    }
61    //print "class: $classname<br>";    //print "class: $classname<br>";
62    $attributes = $arg_list;    $attributes = $arg_list;
63    $classname = $namespacedClassname;    $classname = $namespacedClassname;
64    if (loadModule($namespacedClassname)) {    if (loadModule($namespacedClassname)) {
65      $classname = str_replace('::', '_', $namespacedClassname);      $classname = str_replace('::', '_', $namespacedClassname);
66        $classname = str_replace('/', '_', $classname);
67    }    }
68    $obj = new DesignPattern_Bridge($classname, $attributes);    $obj = new DesignPattern_Bridge($classname, $attributes);
69    
70      // call constructor if possible
71      // FIXME: take care for side-effects!!!
72      /*
73      if (method_exists($obj, 'constructor')) {
74        $obj->constructor();
75      }
76      */
77    
78    return $obj;    return $obj;
79  }  }
80    
81  function loadModule($namespacedClassname) {  function loadModule($namespacedClassname, $extension = 'php') {
82    if ($filename = _ns2file($namespacedClassname)) {    if ($filename = _ns2file($namespacedClassname)) {
83      require_once($filename);      if ($extension) {
84          $filename .= ".$extension";
85        }
86    
87        // V1: just require
88          //require_once($filename);
89    
90        // V2: check file for existance (didn't work!!! problem with path-style conversion regarding platform running on?)
91          /*
92          if (file_exists($filename)) {
93            require_once($filename);
94          } else {
95            //user_error("Could not load module '$namespacedClassname', file '$filename' does not exist.");
96          }
97          */
98    
99        // V3: wrapped through eval (weird)
100          /*
101          $evalstring = "return include_once('$filename');";
102          $result = eval($evalstring);
103          if (!$result) {
104            user_error("DesignPattern::Object: Could not load module '$namespacedClassname', file '$filename' does not exist.");
105            return;
106          }
107          */
108    
109        // V4: just include
110          if (!include_once($filename)) {
111            // TODO: do stack-backtracing here to determine function called two or three levels before!!!
112            user_error("DesignPattern::Object: Could not load module '$namespacedClassname', file '$filename' does not exist.");
113            return;
114          }
115    
116      return 1;      return 1;
117    }    }
118  }  }

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

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