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

Annotation of /nfo/php/libs/org.netfrag.glib/DesignPattern/Bridge.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations)
Mon Feb 3 05:01:27 2003 UTC (21 years, 7 months ago) by joko
Branch: MAIN
Changes since 1.1: +16 -6 lines
+ now attributes can get passed in to the constructors

1 joko 1.1 <?
2     // ---------------------------------------------------------------------------
3 joko 1.2 // $Id: Bridge.php,v 1.1 2003/02/03 03:33:48 joko Exp $
4 joko 1.1 // ---------------------------------------------------------------------------
5 joko 1.2 // $Log: Bridge.php,v $
6     // Revision 1.1 2003/02/03 03:33:48 joko
7     // + initial commit
8     //
9 joko 1.1 // ---------------------------------------------------------------------------
10    
11    
12     class DesignPattern_Bridge extends DesignPattern_Logger {
13    
14 joko 1.2 function DesignPattern_Bridge($classname, $attributes = null) {
15     //return $this->_mkInstance($classname, $attributes);
16     $this = $this->_mkInstance($classname, $attributes);
17     //return $this;
18 joko 1.1 }
19    
20 joko 1.2 function &_mkInstance($classname, $attributes = null) {
21 joko 1.1 $this->log( get_class($this) . "->_mkInstance( classname $classname )", LOG_DEBUG );
22 joko 1.2 if (isset($attributes)) {
23     $instance = new $classname($attributes);
24     } else {
25     $instance = new $classname;
26     }
27     return $instance;
28 joko 1.1 }
29    
30     function _mkEmbeddedObjects($args) {
31    
32     $this->log( get_class($this) . "->_mkEmbeddedObjects()", LOG_DEBUG );
33    
34     foreach ($args[class_names] as $classname) {
35    
36     // build objectname from classname
37     // - make lowercase
38     // - strip leading "Xyz_" ('Site_' here)
39     $objectname = $classname;
40     $objectname = str_replace('Site_', '', $objectname);
41     $objectname = strtolower($objectname);
42    
43     // create new instance of helper object by classname
44     $this->$objectname = &$this->_mkInstance($classname);
45    
46     // create additional references to helper object with other names if requested
47     // the intention is (e.g.) to migrate objects over to new reference-names when development progresses and ...
48     // ... refactoring the object hierarchy is needed, but ...
49     // ... you wanna provide the old reference names as "fallbacks" for old code using the libs
50     if (is_array($args[ref_names])) {
51     foreach ($args[ref_names] as $ref_name) {
52     //print "mkRef: $ref_name<br>";
53     $this->$ref_name = &$this->$objectname;
54     }
55     }
56    
57     // helper gets reference to ourselves as a parent
58     $this->$objectname->$args[parent_name] = &$this;
59    
60     if ( $method = $args[run] ) {
61     if (method_exists($this->$objectname, $method)) {
62     $this->log( get_class($this) . "->_mkEmbeddedObjects: calling method \$this->" . $objectname . "->$method()", LOG_DEBUG );
63     $this->$objectname->$method();
64     }
65     }
66    
67     }
68    
69     }
70    
71     function _init_logger() {
72     // Log
73     // valid logging-levels are:
74     // LOG_EMERG, LOG_ALERT, LOG_CRIT,
75     // LOG_ERR, LOG_WARNING, LOG_NOTICE, LOG_INFO, and LOG_DEBUG.
76     // The default is LOG_INFO.
77     $logfile = 'log.txt';
78     $logfile = $this->config[path][base] . "core/var/log/logfile.txt";
79    
80     // TODO: maybe include userid here?
81     //$log_ident = substr(session_id(), 10, 6);
82     $log_ident = session_id();
83     if ($this->config[mode][LOG]) {
84     $this->logger = &Log::singleton('file', $logfile, $log_ident);
85     //$site->logger = new Log_file($logfile, $log_ident);
86     } else {
87     $this->logger = &Log::singleton('dummy', $logfile, $log_ident);
88     }
89     $this->log( get_class($this) . "->_init_logger: ready\t\t--------------------", LOG_DEBUG );
90     }
91    
92     }
93     ?>

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