root/events/phpframework/akelos/trunk/lib/AkObject.php
@
21114
| Revision 21114, 4.6 kB (checked in by gen, 5 years ago) |
|---|
| Line | |
|---|---|
| 1 | <?php |
| 2 | /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ |
| 3 | |
| 4 | // +----------------------------------------------------------------------+ |
| 5 | // | Akelos Framework - http://www.akelos.org | |
| 6 | // +----------------------------------------------------------------------+ |
| 7 | // | Copyright (c) 2002-2006, Akelos Media, S.L. & Bermi Ferrer Martinez | |
| 8 | // | Released under the GNU Lesser General Public License, see LICENSE.txt| |
| 9 | // +----------------------------------------------------------------------+ |
| 10 | |
| 11 | /** |
| 12 | * @package ActiveSupport |
| 13 | * @subpackage Compatibility |
| 14 | * @author Bermi Ferrer <bermi a.t akelos c.om> |
| 15 | * @copyright Copyright (c) 2002-2006, Akelos Media, S.L. http://www.akelos.org |
| 16 | * @license GNU Lesser General Public License <http://www.gnu.org/copyleft/lesser.html> |
| 17 | */ |
| 18 | |
| 19 | if(!class_exists('AkObject')){ |
| 20 | |
| 21 | /** |
| 22 | * Allows for __construct and __destruct to be used in PHP4. |
| 23 | * |
| 24 | * A hack to support __construct() on PHP 4 |
| 25 | * Hint: descendant classes have no PHP4 class_name() |
| 26 | * constructors, so this one gets called first and calls the |
| 27 | * top-layer __construct() which (if present) should call |
| 28 | * parent::__construct() |
| 29 | * |
| 30 | * @author Bermi Ferrer <bermi a.t akelos c.om> |
| 31 | * @copyright Copyright (c) 2002-2005, Akelos Media, S.L. http://www.akelos.org |
| 32 | * @license GNU Lesser General Public License <http://www.gnu.org/copyleft/lesser.html> |
| 33 | */ |
| 34 | class AkObject |
| 35 | { |
| 36 | |
| 37 | |
| 38 | // ------ CLASS METHODS ------ // |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | // ---- Public methods ---- // |
| 44 | |
| 45 | |
| 46 | // {{{ AkObject() |
| 47 | |
| 48 | /** |
| 49 | * A hack to support __construct() on PHP 4 |
| 50 | * |
| 51 | * Hint: descendant classes have no PHP4 class_name() |
| 52 | * constructors, so this one gets called first and calls the |
| 53 | * top-layer __construct() which (if present) should call |
| 54 | * parent::__construct() |
| 55 | * |
| 56 | * @access public |
| 57 | * @return void |
| 58 | */ |
| 59 | function AkObject() |
| 60 | { |
| 61 | Ak::profile('Instantiating '.get_class($this)); |
| 62 | $args = func_get_args(); |
| 63 | ____ak_shutdown_function(&$this); |
| 64 | call_user_func_array(array(&$this, '__construct'), $args); |
| 65 | ____ak_shutdown_function(true); |
| 66 | |
| 67 | } |
| 68 | |
| 69 | // }}} |
| 70 | |
| 71 | |
| 72 | // {{{ toString() |
| 73 | |
| 74 | /** |
| 75 | * Object-to-string conversion |
| 76 | * |
| 77 | * Each class can override it as necessary |
| 78 | * |
| 79 | * @access public |
| 80 | * @return string in this case returns this class name |
| 81 | */ |
| 82 | function toString() |
| 83 | { |
| 84 | return get_class($this); |
| 85 | } |
| 86 | |
| 87 | function __toString() |
| 88 | { |
| 89 | return $this->toString(); |
| 90 | } |
| 91 | |
| 92 | // }}} |
| 93 | |
| 94 | |
| 95 | // ---- Protected methods ---- // |
| 96 | |
| 97 | |
| 98 | // {{{ __construct() |
| 99 | |
| 100 | /** |
| 101 | * Class constructor, overriden in descendant classes |
| 102 | * |
| 103 | * @access protected |
| 104 | * @return void |
| 105 | */ |
| 106 | function __construct() |
| 107 | { |
| 108 | |
| 109 | } |
| 110 | |
| 111 | // }}} |
| 112 | // {{{ __destruct() |
| 113 | |
| 114 | /** |
| 115 | * Class destructor, overriden in descendant classes |
| 116 | * |
| 117 | * @access protected |
| 118 | * @return void |
| 119 | */ |
| 120 | function __destruct() |
| 121 | { |
| 122 | unset($this); |
| 123 | } |
| 124 | |
| 125 | |
| 126 | // }}} |
| 127 | |
| 128 | // {{{ __clone() |
| 129 | |
| 130 | /** |
| 131 | * Clone class (Zend Engine 2 compatibility trick) |
| 132 | */ |
| 133 | function __clone() |
| 134 | { |
| 135 | return $this; |
| 136 | } |
| 137 | |
| 138 | // }}} |
| 139 | |
| 140 | function log($message, $type = '', $identifyer = '') |
| 141 | { |
| 142 | if (AK_LOG_EVENTS){ |
| 143 | $Logger =& Ak::getLogger(); |
| 144 | $Logger->log($message, $type); |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | /** |
| 149 | * Unsets circular reference children that are not freed from memory |
| 150 | * when calling unset() or when the parent object is garbage collected. |
| 151 | * |
| 152 | * @see http://paul-m-jones.com/?p=262 |
| 153 | * @see http://bugs.php.net/bug.php?id=33595 |
| 154 | */ |
| 155 | function freeMemory() |
| 156 | { |
| 157 | // We can't use get_class_vars as it does not include runtime assigned attributes |
| 158 | foreach (array_keys((array)$this) as $attribute){ |
| 159 | if(isset($this->$attribute)){ |
| 160 | unset($this->$attribute); |
| 161 | } |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | } |
| 166 | |
| 167 | function ____ak_shutdown_function($details = false) |
| 168 | { |
| 169 | static $_registered = false; |
| 170 | static $___registered_objects = array(); |
| 171 | if($details === false){ |
| 172 | Ak::profile('Calling shutdown destructors'); |
| 173 | foreach (array_keys($___registered_objects) as $k){ |
| 174 | if(!empty($___registered_objects[$k]) && is_object($___registered_objects[$k]) && method_exists($___registered_objects[$k],'__destruct')){ |
| 175 | Ak::profile('Calling destructor for '.get_class($___registered_objects[$k])); |
| 176 | $___registered_objects[$k]->__destruct(); |
| 177 | } |
| 178 | } |
| 179 | } else if ($details === true && $_registered === false) { |
| 180 | register_shutdown_function('____ak_shutdown_function'); |
| 181 | $_registered = true; |
| 182 | } else { |
| 183 | $___registered_objects[] =& $details; |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | } |
| 188 | |
| 189 | ?> |
Note: See TracBrowser
for help on using the browser.
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)