root/trunk/lib/SGL/Registry.php

Revision 1965, 5.1 kB (checked in by demian, 1 year ago)

Implemented a library cache for all files used on every request

  • Property svn:eol-style set to native
Line 
1 <?php
2 /* Reminder: always indent with 4 spaces (no tabs). */
3 // +---------------------------------------------------------------------------+
4 // | Copyright (c) 2006, Demian Turner                                         |
5 // | All rights reserved.                                                      |
6 // |                                                                           |
7 // | Redistribution and use in source and binary forms, with or without        |
8 // | modification, are permitted provided that the following conditions        |
9 // | are met:                                                                  |
10 // |                                                                           |
11 // | o Redistributions of source code must retain the above copyright          |
12 // |   notice, this list of conditions and the following disclaimer.           |
13 // | o Redistributions in binary form must reproduce the above copyright       |
14 // |   notice, this list of conditions and the following disclaimer in the     |
15 // |   documentation and/or other materials provided with the distribution.    |
16 // | o The names of the authors may not be used to endorse or promote          |
17 // |   products derived from this software without specific prior written      |
18 // |   permission.                                                             |
19 // |                                                                           |
20 // | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS       |
21 // | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT         |
22 // | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR     |
23 // | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT      |
24 // | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,     |
25 // | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT          |
26 // | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,     |
27 // | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY     |
28 // | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT       |
29 // | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE     |
30 // | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.      |
31 // |                                                                           |
32 // +---------------------------------------------------------------------------+
33 // | Seagull 0.6                                                               |
34 // +---------------------------------------------------------------------------+
35 // | Registry.php                                                         |
36 // +---------------------------------------------------------------------------+
37 // | Author:   Demian Turner <demian@phpkitchen.com>                           |
38 // +---------------------------------------------------------------------------+
39 // $Id: Permissions.php,v 1.5 2005/02/03 11:29:01 demian Exp $
40
41 /**
42  * Generic data storage object, referred to as $input.
43  *
44  * @package SGL
45  * @author  Demian Turner <demian@phpkitchen.com>
46  * @version $Revision: 1.49 $
47  */
48 class SGL_Registry
49 {
50     var $aProps = array();
51
52     function &singleton()
53     {
54         static $instance;
55         if (!isset($instance)) {
56             $class = __CLASS__;
57             $instance = new $class();
58         }
59         return $instance;
60     }
61
62     function &get($key)
63     {
64         if (array_key_exists($key, $this->aProps)) {
65             $ret $this->aProps[$key];
66         } else {
67             $ret = null;
68         }
69         return $ret;
70     }
71
72     function set($key, &$value)
73     {
74         $this->aProps[$key] = &$value;
75     }
76
77     function exists($key) {
78         return array_key_exists($key, $this->aProps);
79     }
80
81     function getRequest()
82     {
83         return $this->get('request');
84     }
85
86     function setRequest($req)
87     {
88         #$reg = &SGL_RequestRegistry::singleton();
89         $this->set('request', $req);
90         //  php 4 version of
91         //  self::singleton()->set('request', $req);
92     }
93
94     function getCurrentUrl()
95     {
96         return $this->get('currentUrl');
97     }
98
99     function setCurrentUrl($url)
100     {
101         $this->set('currentUrl', $url);
102     }
103
104     function setFilters($aFilters)
105     {
106         $this->set('aFilters', $aFilters);
107     }
108
109     function getFilters()
110     {
111         return $this->get('aFilters');
112     }
113
114     function getConfig()
115     {
116         $c = &SGL_Config::singleton();
117         return $c->getAll();
118     }
119
120     /**
121      * Copies properties from source object to destination object.
122      *
123      * @access  public
124      * @static
125      * @param   object  $dest   typically the ouput object
126      * @return  void
127      */
128     function aggregate(& $dest)
129     {
130         SGL::logMessage(null, PEAR_LOG_DEBUG);
131         $aObjAttrs = get_object_vars($this);
132         if (is_array($aObjAttrs)) {
133             foreach ($aObjAttrs as $objAttrName => $objAttrValue) {
134                 $dest->$objAttrName = $objAttrValue;
135             }
136             foreach ($dest->aProps as $k => $obj) {
137                 $dest->$k = $obj;
138             }
139             unset($dest->aProps);
140         }
141     }
142 }
143 ?>
Note: See TracBrowser for help on using the browser.