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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.6 - (show annotations)
Fri Feb 28 04:18:13 2003 UTC (21 years, 6 months ago) by joko
Branch: MAIN
Changes since 1.5: +20 -1 lines
+ special-case-handling for single argument pass-in
+ testing with constructor autocalling: not used for now since weird sideeffects occoured!
   o however: rethink it completely!

1 <?
2 // ---------------------------------------------------------------------------
3 // $Id: Object.php,v 1.5 2003/02/27 16:36:02 joko Exp $
4 // ---------------------------------------------------------------------------
5 // $Log: Object.php,v $
6 // Revision 1.5 2003/02/27 16:36:02 joko
7 // re-allowed underscores ('_') in php classnames
8 // does this break something?
9 //
10 // Revision 1.4 2003/02/22 16:34:16 joko
11 // + minor fix: can seperate namespace identifier with slashes ('/') now
12 //
13 // Revision 1.3 2003/02/09 17:16:06 joko
14 // + handling arguments perl style ;-)
15 //
16 // Revision 1.2 2003/02/03 05:01:48 joko
17 // + now attributes can get passed in to the constructors
18 //
19 // Revision 1.1 2003/02/03 03:33:48 joko
20 // + initial commit
21 //
22 // ---------------------------------------------------------------------------
23
24
25 /*
26 class DesignPattern_Object {
27 function DesignPattern_Object() {
28
29 }
30 }
31 */
32
33 function _ns2file($nsName) {
34 if ($filename = str_replace('::', '/', $nsName)) {
35 $filename .= '.php';
36 return $filename;
37 }
38 }
39
40 function mkObject() {
41 $arg_list = func_get_args();
42
43 // patch arglist if all arguments are passed in as a single array
44 if (count($arg_list) == 1 && is_array($arg_list[0])) {
45 $arg_list = $arg_list[0];
46 }
47
48 //print Dumper($arg_list);
49 $namespacedClassname = array_shift($arg_list);
50 if (strstr($namespacedClassname, '_')) {
51 //print "mkObject: unallowed character in namespaced classname: '_' ($namespacedClassname)<br/>";
52 //return;
53 }
54 //print "class: $classname<br>";
55 $attributes = $arg_list;
56 $classname = $namespacedClassname;
57 if (loadModule($namespacedClassname)) {
58 $classname = str_replace('::', '_', $namespacedClassname);
59 $classname = str_replace('/', '_', $classname);
60 }
61 $obj = new DesignPattern_Bridge($classname, $attributes);
62
63 // call constructor if possible
64 // FIXME: take care for side-effects!!!
65 /*
66 if (method_exists($obj, 'constructor')) {
67 $obj->constructor();
68 }
69 */
70
71 return $obj;
72 }
73
74 function loadModule($namespacedClassname) {
75 if ($filename = _ns2file($namespacedClassname)) {
76 require_once($filename);
77 return 1;
78 }
79 }
80
81 ?>

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