Source for file AkObject.php

Documentation is available at AkObject.php

  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.  
  39.     // ------ CLASS METHODS ------ //
  40.  
  41.  
  42.  
  43.  
  44.     // ---- Public methods ---- //
  45.  
  46.  
  47.     // {{{ AkObject()
  48.  
  49.     /**
  50.     * A hack to support __construct() on PHP 4
  51.     *
  52.     * Hint: descendant classes have no PHP4 class_name()
  53.     * constructors, so this one gets called first and calls the
  54.     * top-layer __construct() which (if present) should call
  55.     * parent::__construct()
  56.     *
  57.     * @access public
  58.     * @return void
  59.     */
  60.     function AkObject()
  61.     {
  62.         static $_callback_called;
  63.         Ak::profile('Instantiating '.get_class($this));
  64.         $args func_get_args();
  65.         // register_shutdown_function(array(&$this, '__destruct'));
  66.         ____ak_shutdown_function(&$this);
  67.         call_user_func_array(array(&$this'__construct')$args);
  68.  
  69.         if(empty($_callback_called)){
  70.             $_callback_called = true;
  71.             register_shutdown_function('____ak_shutdown_function');
  72.         }
  73.     }
  74.  
  75.     // }}}
  76.     // {{{ toString()
  77.  
  78.     /**
  79.     * Object-to-string conversion
  80.     *
  81.     * Each class can override it as necessary
  82.     *
  83.     * @access public
  84.     * @return string in this case returns this class name
  85.     */
  86.     function toString()
  87.     {
  88.         return get_class($this);
  89.     }
  90.     
  91.     function __toString()
  92.     {
  93.         return $this->toString();
  94.     }
  95.  
  96.     // }}}
  97.  
  98.  
  99.     // ---- Protected methods ---- //
  100.  
  101.  
  102.     // {{{ __construct()
  103.  
  104.     /**
  105.     * Class constructor, overriden in descendant classes
  106.     *
  107.     * @access protected
  108.     * @return void
  109.     */
  110.     function __construct()
  111.     {
  112.  
  113.     }
  114.  
  115.     // }}}
  116.     // {{{ __destruct()
  117.  
  118.     /**
  119.     * Class destructor, overriden in descendant classes
  120.     *
  121.     * @access protected
  122.     * @return void
  123.     */
  124.     function __destruct()
  125.     {
  126.         unset($this);
  127.     }
  128.  
  129.  
  130.     // }}}
  131.  
  132.  
  133.     // {{{ __clone()
  134.  
  135.     /**
  136.     * Clone class (Zend Engine 2 compatibility trick)
  137.     */
  138.     function __clone()
  139.     {
  140.         return $this;
  141.     }
  142.  
  143.     // }}}
  144.  
  145.     function log($message$type ''$identifyer '')
  146.     {
  147.         require_once 'Log.php';
  148.         $ident = empty($ident'main' $ident;
  149.  
  150.         $log = Log::singleton('file'AK_LOGS_DIR.DS.$ident.'.log',$ident);
  151.         $log->log($type$message);
  152.     }
  153.     
  154.     
  155.     /**
  156.     * Unsets circular reference children that are not freed from memory
  157.     * when calling unset() or when the parent object is garbage collected.
  158.     * 
  159.     * @see http://paul-m-jones.com/?p=262
  160.     * @see http://bugs.php.net/bug.php?id=33595
  161.     */
  162.     function freeMemory()
  163.     {
  164.         // We can't use get_class_vars as it does not include runtime assigned attributes
  165.         foreach (array_keys((array)$thisas $attribute){
  166.             if(isset($this->$attribute)){
  167.                 unset($this->$attribute);
  168.             }
  169.         }
  170.     }
  171.  
  172. }
  173.  
  174.  
  175. function ____ak_shutdown_function($details = false)
  176. {
  177.     static $___registered_objects;
  178.     if(!$details){
  179.         Ak::profile('Calling shutdown destructors');
  180.         foreach (array_keys($___registered_objectsas $k){
  181.             if(!empty($___registered_objects[$k]&& is_object($___registered_objects[$k]&& method_exists($___registered_objects[$k],'__destruct')){
  182.                 Ak::profile('Calling destructor for '.get_class($___registered_objects[$k]));
  183.                 $___registered_objects[$k]->__destruct();
  184.             }
  185.         }
  186.     }else{
  187.         $___registered_objects[=$details;
  188.     }
  189. }
  190.  
  191. }
  192.  
  193. ?>

Documentation generated on Tue, 17 Jun 2008 14:26:03 +0200 by phpDocumentor 1.3.2