Advertisement
fruffl

MOP Object

Aug 20th, 2012
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.25 KB | None | 0 0
  1. <?PHP
  2.     /**
  3.      * ILLI
  4.      *
  5.      * @category   ILLI_System
  6.      * @package    ILLI
  7.      * @link       http://illi.be
  8.      * @license    http://l.illi.be
  9.      * @copyright  ILLI Conference
  10.      */
  11.     NAMESPACE ILLI\System;
  12.     USE Serializable;
  13.  
  14.     /**
  15.      * ILLI Object
  16.      *
  17.      * singleton-support
  18.      * <code>
  19.      * <?PHP
  20.      *  $t1 = \ILLI\System\Rand::instanceGet(200); 
  21.      *  var_dump($t1);
  22.      *  $t1->__destruct();
  23.      *  $t2 = \ILLI\System\Rand::instanceGet(50);
  24.      *  var_dump($t2);
  25.      *  $foo = new \ILLI\System\Rand(15);
  26.      *  var_dump($foo);
  27.      * ?>
  28.      * </code>
  29.      *
  30.      * @category   ILLI_System
  31.      * @package    ILLI
  32.      * @subpackage System
  33.      * @namespace  ILLI\System
  34.      * @link       http://illi.be
  35.      * @license    http://l.illi.be
  36.      * @copyright  ILLI Conference
  37.      * @since      2.0.1
  38.      * @version    3.0.1
  39.      */
  40.     CLASS Object EXTENDS System
  41.     {
  42.         USE tSplHashRegister
  43.         {
  44.             tSplHashRegister___register     as private __splRegister;
  45.             tSplHashRegister___unregister       as private __splUnregister;
  46.             tSplHashRegister_getCode        as public splGetHashCode;
  47.             tSplHashRegister_getInstances       as public splGetInstances;
  48.             tSplHashRegister_getSiblings        as public splGetSiblingInstances;
  49.         }
  50.        
  51.         USE tAdapter
  52.         {
  53.             tAdapter_registerTrigger        as private adapterRegisterTrigger;
  54.             tAdapter_unregisterTrigger      as protected adapterUnregisterTrigger;
  55.             tAdapter_callAlias          as protected adapterCallAlias;
  56.             tAdapter_triggerExists          as protected adapterTriggerExists;
  57.             tAdapter_registerTriggerMethod      as public adapterRegisterTriggerMethod;
  58.             tAdapter_registerTriggerStaticMethod    as public adapterRegisterTriggerStaticMethod;
  59.             tAdapter_registerTriggerClosure     as public adapterRegisterTriggerClosure;
  60.         }
  61.        
  62.         USE tObserver
  63.         {
  64.             tObserver_registerEvent         as private observerRegisterEvent;
  65.             tObserver_unregisterEvent       as protected observerUnregisterEvent;
  66.             tObserver_notify            as protected observerNotify;
  67.             tObserver_eventExists           as protected observerEventExists;
  68.             tObserver_registerEventMethod       as public observerRegisterEventMethod;
  69.             tObserver_registerEventStaticMethod as public observerRegisterEventStaticMethod;
  70.             tObserver_registerEventClosure      as public observerRegisterEventClosure;
  71.         }
  72.        
  73.         USE tFilter
  74.         {
  75.             tFilter_registerEvent           as private filterRegisterEvent;
  76.             tFilter_registerEventMethod     as protected filterRegisterEventMethod;
  77.             tFilter_registerEventStaticMethod   as protected filterRegisterEventStaticMethod;
  78.             tFilter_registerEventClosure        as protected filterRegisterEventClosure;
  79.             tFilter_unregisterTrigger       as public filterUnregisterEvent;
  80.             tFilter_triggerExists           as public filterTriggerExists;
  81.             tFilter_applyFilter         as public filterApply;
  82.         }
  83.        
  84.         USE tVirtualMethod
  85.         {
  86.             tVirtualMethod_remove           as protected virtualMethodRemove;
  87.             tVirtualMethod_add          as public virtualMethodAdd;
  88.             tVirtualMethod_call         as public virtualMethodCall;
  89.         }
  90.        
  91.         USE tInstance
  92.         {
  93.             tInstance___unregister          as private __instanceUnregister;
  94.             tInstance_get               as public instanceGet;
  95.             tInstance_register          as public instanceRegister;
  96.             tInstance_getName           as public instanceGetName;
  97.             tInstance_exists            as public instanceExists;
  98.             tInstance_getNames          as public instanceGetNames;
  99.         }
  100.        
  101.         protected $__Collection     = NULL;
  102.        
  103.         public function getCollection()
  104.         {
  105.             return $this->__Collection;
  106.         }
  107.        
  108.         public function __set($index, $value)
  109.         {
  110.             var_dump($this->adapterTriggerExists(__METHOD__), __METHOD__, func_get_args());
  111.             var_dump($this->adapterTriggerExists(get_called_class().'::'.__FUNCTION__), get_called_class().'::'.__FUNCTION__, func_get_args());
  112.             if(TRUE === $this->adapterTriggerExists(__METHOD__))
  113.                 return $this->adapterCallAlias(__METHOD__, $index, $value);
  114.            
  115.             $filtered   = $this->filterApply('args', __METHOD__, array('index' => $index, 'value' => $value));
  116.             $index      = $filtered['index'];
  117.             $value      = $filtered['value'];
  118.            
  119.             $this->__Collection->offsetSet($index, $value);
  120.            
  121.             $this->observerNotify(__METHOD__, $index, $value);
  122.         }
  123.        
  124.         public function __get($index)
  125.         {
  126.             if(TRUE === $this->adapterTriggerExists(__METHOD__))
  127.                 return $this->adapterCallAlias(__METHOD__, $index);
  128.                
  129.             $filtered   = $this->filterApply('args', __METHOD__, array('index' => $index));
  130.             $index      = $filtered['index'];
  131.             $value      = $this->__Collection->offsetGet($index);
  132.            
  133.             $this->observerNotify(__METHOD__, $index, $value);
  134.            
  135.             $value = $this->filterApply('return', __METHOD__, $value);
  136.            
  137.             return $value;
  138.         }
  139.        
  140.         public function __call($name, array $args = array())
  141.         {
  142.             if(TRUE === $this->adapterTriggerExists(__METHOD__))
  143.                 return $this->adapterCallAlias(__METHOD__, $args);
  144.            
  145.             $filtered   = $this->filterApply('args', __METHOD__, array('method' => $name, 'args' => $args));
  146.             $name       = $filtered['method'];
  147.             $args       = $filtered['args'];
  148.            
  149.             $value = $this->virtualMethodCall($name, $args);
  150.            
  151.             $this->observerNotify(__METHOD__, $name, $value, $args);
  152.            
  153.             $value = $this->filterApply('return', __METHOD__, $value);
  154.            
  155.             return $value;
  156.         }
  157.        
  158.         public function __destruct()
  159.         {
  160.             $this->__instanceUnregister($this);
  161.             $this->__splUnregister();
  162.         }
  163.        
  164.         public function __construct()
  165.         {
  166.             $this->__splRegister();
  167.             $this->__Collection = new Collection;
  168.         }
  169.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement