source: branches/2.3/contactcenter/inc/class.object_keeper.inc.php @ 2

Revision 2, 4.2 KB checked in by niltonneto, 17 years ago (diff)

Removida todas as tags usadas pelo CVS ($Id, $Source).
Primeira versão no CVS externo.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1<?php
2  /***************************************************************************\
3  * eGroupWare - Object Keeper                                                *
4  * http://www.egroupware.org                                                 *
5  * Written by:                                                               *
6  *  - Raphael Derosso Pereira <raphaelpereira@users.sourceforge.net>         *
7  *  - Jonas Goes <jqhcb@users.sourceforge.net>                               *
8  *  sponsored by Thyamad - http://www.thyamad.com                            *
9  * ------------------------------------------------------------------------- *
10  *  This program is free software; you can redistribute it and/or modify it  *
11  *  under the terms of the GNU General Public License as published by the    *
12  *  Free Software Foundation; either version 2 of the License, or (at your   *
13  *  option) any later version.                                               *
14  \***************************************************************************/
15
16
17        class object_keeper
18        {
19                var $repository = array('_USED_' => array());
20                var $rep_size = 0;
21                var $max_rep_size = 0;
22
23                var $serial_rep;
24               
25                function object_keeper ()
26                {
27                        // TODO: get this value from preferences
28                        $this->max_rep_size = 50000;
29                }
30               
31                function & GetObject ($class_name, $unique_id = '_UNDEF_',
32                                                        $p1='_UNDEF_',$p2='_UNDEF_',$p3='_UNDEF_',$p4='_UNDEF_',
33                                        $p5='_UNDEF_',$p6='_UNDEF_',$p7='_UNDEF_',$p8='_UNDEF_',
34                                        $p9='_UNDEF_',$p10='_UNDEF_',$p11='_UNDEF_',$p12='_UNDEF_',
35                                        $p13='_UNDEF_',$p14='_UNDEF_',$p15='_UNDEF_',$p16='_UNDEF_')
36                {
37                        // TODO: error management
38                        if (is_array($unique_id))
39                        {
40                                exit(lang('Object Keeper ERROR: Can\'t use an array as an unique ID!'));
41                        }
42                               
43                        if (is_object($repository[$class_name][$unique_id]))
44                        {
45                                $this->repository['_USED_'][$class_name.','.$unique_id]++;
46                                return ($this->repository[$class_name][$unique_id]);
47                        }
48                       
49                        if ($this->repository_size > $this->max_rep_size)
50                        {
51                                arsort($this->repository['_USED_']);
52                                reset($this->repository['_USED_']);
53                                $remove_class = explode(',',array_shift($this->repository['_USED_']));
54                                unset($this->repository[$remove_class[0]]);
55                        }
56                       
57                        $this->repository[$class_name][$unique_id] =& CreateObject($class_name,$p1,$p2,$p3,$p4,$p5,$p6,$p7,$p8,$p9,$p10,$p11,$p12,$p13,$p14,$p15,$p16);
58                        //$this->repository[$class_name]['_INC_'] = '../../'.substr($class_name, 1, strpos($class_name, '.')).substr($class_name, strpos($class_name, '.')+1, strlen($class_name));
59
60                        $this->repository['_USED_'][$class_name.','.$unique_id] = 1;
61       
62                        $this->rep_size = strlen(serialize($this->repository));
63                       
64                        return $this->repository[$class_name][$unique_id];             
65                }
66               
67                /*!
68               
69                        @function RemoveObject
70                        @abstract Removes an object with the specified ID from the repository
71                        @author Raphael Derosso Pereira
72                       
73                        @param string $class The class full name
74                        @param mixed $id The Object's Unique ID
75               
76                */
77                function RemoveObject($class,$id)
78                {
79                        if ($this->repository[$class][$id])
80                        {
81                                unset($this->repository[$class][$id]);
82                                unset($this->repository['_USED_'][$class.','.$id]);
83                                return true;
84                        }
85                       
86                        return false;
87                }
88                /*!
89               
90                        @function __sleep
91                        @abstract Reserved PHP function to be executed when the Object
92                                Keeper is serialized
93                        @author Raphael Derosso Pereira
94               
95                */
96                function __sleep()
97                {
98                        /* This is a temporary solution to keep the Object Keeper
99                         * inside the session. It is here while the method below
100                         * isn't implemented.
101                         */
102                        unset($this->repository);
103                       
104                        /* This is an attempt to keep the objects serialized in another
105                         * array, but the problem is that the php serialize function
106                         * doesn't keep track of references, so it's impossible (at least
107                         * I didn't find any good way to do it) to manage references. This
108                         * doesn't apply only to objects. It applies to any type.
109                         *
110                        foreach($repository as $class_name => $object)
111                        {
112                                foreach(get_object_vars($object) as $attr => $attr_value)
113                                {
114                                        if (!is_object($attr_value))
115                                        {
116                                                $this->serial_rep[$class_name][$attr] = serialize($attr_value);
117                                        }
118                                }
119                        }*/
120                }
121               
122                function __wakeup()
123                {
124                }
125        }
126?>
Note: See TracBrowser for help on using the repository browser.