Advertisement
fruffl

GC ADT in PHP

Feb 25th, 2013
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 26.29 KB | None | 0 0
  1. <?PHP
  2.     NAMESPACE ILLI\Core\Std\Def;
  3.     USE ILLI\Core\Std\Def\__const_ADTClass;
  4.     USE ILLI\Core\Std\Def\__const_Type;
  5.     USE ILLI\Core\Std\Def\ADTInstance;
  6.     USE ILLI\Core\Std\Def\ADT\ComponentInitializationException;
  7.     USE ILLI\Core\Std\Def\ADT\ComponentMethodCallException;
  8.     USE ILLI\Core\Std\Exception\ArgumentExpectedException;
  9.     USE ILLI\Core\Std\Exception\ArgumentLengthZeroException;
  10.     USE ILLI\Core\Std\Exception\ArgumentInUseException;
  11.     USE ILLI\Core\Std\Exception\NotSupportedException;
  12.     USE ILLI\Core\Std\Invoke;
  13.     USE ILLI\Core\Std\Spl\Fsb;
  14.     USE ILLI\Core\Util\Spl;
  15.    
  16.     CLASS ADT EXTENDS \ILLI\Core\Std\Spl\Fsb
  17.     {
  18.         /**
  19.          * Instantiate a new Abstract Data Type Definition.
  20.          *
  21.          * ADT is the definition as is and doesn't store data.
  22.          *
  23.          * A definition can be a base-type or a collection of base-types:
  24.          *  <long> forbids all except integers.
  25.          *  <string|array> forbids all except strings and arrays.
  26.          *
  27.          * define ADT:
  28.          *
  29.          * :offset<long>
  30.          *  zero-based index
  31.          *
  32.          * :gcType<string>
  33.          *  a valid __const_Type
  34.          *
  35.          * @param   array $__defineTypes [{:offset} => {:gcType}]
  36.          * @catchable   ILLI\Core\Std\Def\ADT\ComponentInitializationException
  37.          * @fires   ILLI\Core\Std\Exception\ArgumentLengthZeroException when definition is an empty array
  38.          * @throws  ILLI\Core\Std\Def\ADT\ComponentMethodCallException::ERROR_M_CTOR_E_DEFINITION_LENGTH_ZERO
  39.          * @see     ::validate()
  40.          * @see     ::__destruct()
  41.          * @see     ILLI\Core\Std\Def\__const_Type
  42.          * @see     ILLI\Core\Std\Def\ADTInstance
  43.          */
  44.         public function __construct(array $__defineTypes = [])
  45.         {
  46.             $c = get_called_class();
  47.             $e = $c.'\ComponentMethodCallException';
  48.            
  49.             try
  50.             {
  51.                 if([] === $__defineTypes)
  52.                     throw ($c === __CLASS__ || FALSE === class_exists($e))
  53.                         ? new ComponentMethodCallException(new ArgumentLengthZeroException, ['method' => __METHOD__], ComponentMethodCallException::ERROR_M_CTOR_E_DEFINITION_LENGTH_ZERO)
  54.                         : new $e(new ArgumentLengthZeroException, ['method' => __METHOD__], $e::ERROR_M_CTOR_E_DEFINITION_LENGTH_ZERO);
  55.                
  56.                 $n = $this->createHashAddr($__defineTypes);
  57.                 $t = &self::$__gc[$n];     
  58.                
  59.                 parent::setSize(1);
  60.                 parent::offsetSet(0, $n);
  61.                
  62.                 if(FALSE === isset($t))
  63.                     $t = Fsb::fromArray($this->parseDef($__defineTypes));
  64.             }
  65.             catch(\Exception $E)
  66.             {
  67.                 $e = $c.'\ComponentInitializationException';
  68.                 throw ($c === __CLASS__ || FALSE === class_exists($e))
  69.                     ? new ComponentInitializationException($E, ['class' => get_called_class()])
  70.                     : new $e($E, ['class' => get_called_class()]);
  71.             }
  72.         }
  73.        
  74.         /**
  75.          * value validation
  76.          *
  77.          * The type of given value equals with one of the registered gc-types.
  78.          *
  79.          * @param   mixed $__value
  80.          * @return  boolean
  81.          * @catchable   ILLI\Core\Std\Def\ADT\ComponentMethodCallException
  82.          * @throws  ILLI\Core\Std\Def\ADT\ComponentMethodCallException::ERROR_M_VALIDATE
  83.          * @see     ILLI\Core\Std\Def\__const_Type
  84.          */
  85.         public function validate($__value)
  86.         {
  87.             try
  88.             {
  89.                 $v = &$__value;
  90.                 $t = getType($v);
  91.                
  92.                 foreach($this->getGC() as $h)
  93.                 {
  94.                     if($t === $h
  95.                     ||($t === __const_Type::SPL_OBJECT && (class_exists($h) || interface_exists($h)) && (is_subclass_of($v, $h) || $v instanceOf $h)))
  96.                         return TRUE;
  97.                 }
  98.                
  99.                 return FALSE;
  100.             }
  101.             catch(\Exception $E)
  102.             {
  103.                 $c = get_called_class();
  104.                 $e = $c.'\ComponentMethodCallException';
  105.                 throw ($c === __CLASS__ || FALSE === class_exists($e))
  106.                     ? new ComponentMethodCallException($E, ComponentMethodCallException::ERROR_M_VALIDATE, ['method' => __METHOD__])
  107.                     : new $e($E, $e::ERROR_M_VALIDATE, ['method' => __METHOD__]);
  108.             }
  109.         }
  110.        
  111.         #:define:
  112.             /**
  113.              * ADT class-mapping
  114.              *
  115.              * :gcType<string>
  116.              *  a valid __const_Type
  117.              *
  118.              * :adtClass<string>
  119.              *  a valid __const_ADTClass
  120.              *
  121.              * @var     array [{:gcType} => {:adtClass}]
  122.              * @see     ::define()
  123.              * @see     ILLI\Core\Std\Def\__const_ADTClass
  124.              * @see     ILLI\Core\Std\Def\__const_Type
  125.              * @note    ILLI\Core\Std\Def\__const_ADTClass::SPL_INSTANCE will be created by undefined type-requests in ::define()
  126.              */
  127.             private static $__def =
  128.             [
  129.                 __const_Type::SPL_ARRAY         => __const_ADTClass::SPL_ARRAY,
  130.                 __const_Type::SPL_BOOLEAN       => __const_ADTClass::SPL_BOOLEAN,
  131.                 __const_Type::SPL_CALLABLE      => __const_ADTClass::SPL_CALLABLE,
  132.                 __const_Type::SPL_CLASS         => __const_ADTClass::SPL_CLASS,
  133.                 __const_Type::SPL_CLOSURE       => __const_ADTClass::SPL_CLOSURE,
  134.                 __const_Type::SPL_DIRECTORY     => __const_ADTClass::SPL_DIRECTORY,
  135.                 __const_Type::SPL_DOUBLE        => __const_ADTClass::SPL_DOUBLE,
  136.                 __const_Type::SPL_FILE          => __const_ADTClass::SPL_FILE,
  137.                 __const_Type::SPL_FLOAT         => __const_ADTClass::SPL_DOUBLE,
  138.                 __const_Type::SPL_FUNCTION      => __const_ADTClass::SPL_FUNCTION,
  139.                 __const_Type::SPL_INTERFACE     => __const_ADTClass::SPL_INTERFACE,
  140.                 __const_Type::SPL_INTEGER       => __const_ADTClass::SPL_LONG,
  141.                 __const_Type::SPL_LONG          => __const_ADTClass::SPL_LONG,
  142.                 __const_Type::SPL_METHOD        => __const_ADTClass::SPL_METHOD,
  143.                 __const_Type::SPL_NULL          => __const_ADTClass::SPL_NULL,
  144.                 __const_Type::SPL_OBJECT        => __const_ADTClass::SPL_OBJECT,
  145.                 __const_Type::SPL_RESOURCE      => __const_ADTClass::SPL_RESOURCE,
  146.                 __const_Type::SPL_STRING        => __const_ADTClass::SPL_STRING,
  147.                 __const_Type::SPL_TRAIT         => __const_ADTClass::SPL_TRAIT
  148.             ];
  149.            
  150.             /**
  151.              * create ADT from __const_Type
  152.              *
  153.              * :rOffset<long>
  154.              *  offset in result-array
  155.              *
  156.              * :gcOffset<long>
  157.              *  zero-based index
  158.              *
  159.              * :gcType<string>
  160.              *   a valid __const_Type or class-/interface-name
  161.              *
  162.              * @param   string  $__type     {:gcType}
  163.              * @param   array   $__type     [{:rOffset} => {:gcType}]
  164.              * @param   array   $__type     [{:rOffset} => [{:gcOffset} => {:gcType}]]
  165.              * @return  ILLI\Core\Std\Def\Type
  166.              * @see     ::$__def
  167.              * @see     ILLI\Core\Std\Def\ADT
  168.              * @see     ILLI\Core\Std\Def\ADTInstance
  169.              * @note    unlisted types: interpreting {:gcType} as class/interface and define the abstract-data-type as ADTInstance
  170.              */
  171.             final public static function define($__type)
  172.             {
  173.                 if(!is_string($__type))
  174.                 {
  175.                     if(is_array($__type))
  176.                     {
  177.                         $r = [];
  178.                        
  179.                         foreach($__type as $k => $v)
  180.                             $r[$k] = self::define($v);
  181.                        
  182.                         return $r;
  183.                     }
  184.                    
  185.                     throw new ArgumentExpectedException([
  186.                         'target'    => __METHOD__,
  187.                         'expected'  => 'string ILLI\Core\Std\Def\__const_Type::SPL*|string className|array [className:1, …, className:N]',
  188.                         'detected'  => getType($v = $__type),
  189.                         'value'     => is_object($v) ? get_class($v) : (is_scalar($v) ? $v : NULL)
  190.                     ]);
  191.                 }
  192.                
  193.                 $n = &self::$__def[$__type];
  194.                 $a = func_get_args();
  195.                
  196.                 if(FALSE === isset($n))
  197.                 {
  198.                     $a[0] = (array) $a[0];
  199.                     #+ instance-based ADT: ADTInstance<instanceOf myClass>
  200.                     #+ allow definition of ADT as subADT (ADT-classes are not listed as array-keys in ::$__def): ADTInstance<instanceOf ADT*>
  201.                     return Invoke::emitClass('ILLI\Core\Std\Def\ADTInstance', $a);
  202.                 }
  203.                
  204.                 array_shift($a);
  205.                
  206.                 #+ default ADT: ADTArray, ADTBoolean, ..., ADT*
  207.                 return Invoke::emitClass($n, $a);
  208.             }
  209.         #::
  210.        
  211.         #:gc:
  212.             /**
  213.              * ADT definition gc
  214.              *
  215.              * :hashAddr<string>
  216.              *  absolute ADT:
  217.              *      instance of get_called_class(): ILLI\Core\Std\Def\ADT*
  218.              *  anonymous ADT:
  219.              *      instance of __CLASS__:      ILLI\Core\Std\Def\ADT<hash>
  220.              *
  221.              * :adtDef<ILLI\Core\Std\Spl\Fsb>
  222.              *  collection of defined __const_Type(s)
  223.              *
  224.              * @var     array [{:hashAddr} => {:adtDef}]
  225.              * @note    anonymous ADT: temporary gc; absolute ADT: permanent gc
  226.              * @note    gc[{:hashAddr}] is traversable
  227.              * @see     :gc:ILLI\Core\Std\Spl\Fsb:
  228.              */
  229.             private static $__gc = [];
  230.        
  231.             /**
  232.              * get gc hash address
  233.              *
  234.              * @return  string
  235.              * @catchable   ILLI\Core\Std\Def\ADT\ComponentMethodCallException
  236.              * @throws  ILLI\Core\Std\Def\ADT\ComponentMethodCallException::ERROR_M_GET_NAME
  237.              * @see     ::$__gc
  238.              */
  239.             final public function getName()
  240.             {
  241.                 try
  242.                 {
  243.                     return parent::offsetGet(0);
  244.                 }
  245.                 catch(\Exception $E)
  246.                 {
  247.                     $c = get_called_class();
  248.                     $e = $c.'\ComponentMethodCallException';
  249.                     throw ($c === __CLASS__ || FALSE === class_exists($e))
  250.                         ? new ComponentMethodCallException($E, ComponentMethodCallException::ERROR_M_GET_NAME, ['method' => __METHOD__])
  251.                         : new $e($E, $e::ERROR_M_GET_NAME, ['method' => __METHOD__]);
  252.                 }
  253.             }
  254.        
  255.             /**
  256.              * get ADT-gc
  257.              *
  258.              * @return  ILLI\Core\Std\Spl\Fsb
  259.              * @catchable   ILLI\Core\Std\Def\ADT\ComponentMethodCallException
  260.              * @throws  ILLI\Core\Std\Def\ADT\ComponentMethodCallException::ERROR_M_GET_GC
  261.              * @see     ::$__gc
  262.              */
  263.             final public function getGC()
  264.             {
  265.                 try
  266.                 {
  267.                     return self::$__gc[$this->getName()];
  268.                 }
  269.                 catch(\Exception $E)
  270.                 {
  271.                     $c = get_called_class();
  272.                     $e = $c.'\ComponentMethodCallException';
  273.                     throw ($c === __CLASS__ || FALSE === class_exists($e))
  274.                         ? new ComponentMethodCallException($E, ComponentMethodCallException::ERROR_M_GET_GC, ['method' => __METHOD__])
  275.                         : new $e($E, $e::ERROR_M_GET_GC, ['method' => __METHOD__]);
  276.                 }
  277.             }
  278.            
  279.             /**
  280.              * join registered gc-type(s)
  281.              *
  282.              * @return  ILLI\Core\Std\Spl\Fsb
  283.              * @catchable   ILLI\Core\Std\Def\ADT\ComponentMethodCallException
  284.              * @throws  ILLI\Core\Std\Def\ADT\ComponentMethodCallException::ERROR_M_TO_STRING
  285.              * @see     ::$__gc
  286.              * @see     ILLI\Core\Std\Def\__const_Type
  287.              */
  288.             final public function toString()
  289.             {
  290.                 try
  291.                 {
  292.                     return implode('|', $this->getGC()->toArray());
  293.                 }
  294.                 catch(\Exception $E)
  295.                 {
  296.                     $c = get_called_class();
  297.                     $e = $c.'\ComponentMethodCallException';
  298.                     throw ($c === __CLASS__ || FALSE === class_exists($e))
  299.                         ? new ComponentMethodCallException($E, ComponentMethodCallException::ERROR_M_TO_STRING, ['method' => __METHOD__])
  300.                         : new $e($E, $e::ERROR_M_TO_STRING, ['method' => __METHOD__]);
  301.                 }
  302.             }
  303.        
  304.             /**
  305.              * validate typedef request
  306.              *
  307.              * :offset<long>
  308.              *  zero-based index
  309.              *
  310.              * :gcType<string>
  311.              *  a valid __const_Type
  312.              *
  313.              * @param   array $__defineTypes [{:offset} => {:gcType}]
  314.              * @catchable   ILLI\Core\Std\Def\ADT\ComponentMethodCallException
  315.              * @fires   ILLI\Core\Std\Exception\ArgumentExpectedException when {:gcType} is not of type string
  316.              * @fires   ILLI\Core\Std\Exception\ArgumentLengthZeroException when result-array is empty
  317.              * @throws  ILLI\Core\Std\Def\ADT\ComponentMethodCallException::ERROR_M_PARSE_DEF_E_EXPECTED_STRING
  318.              * @throws  ILLI\Core\Std\Def\ADT\ComponentMethodCallException::ERROR_M_PARSE_DEF_E_RESULT_LENGTH_ZERO
  319.              * @throws  ILLI\Core\Std\Def\ADT\ComponentMethodCallException::ERROR_M_PARSE_DEF
  320.              */
  321.             final protected function parseDef(array $__defineTypes)
  322.             {
  323.                 $c = get_called_class();
  324.                 $e = $c.'\ComponentMethodCallException';
  325.                
  326.                 try
  327.                 {
  328.                     $r = [];
  329.                    
  330.                     foreach($__defineTypes as $k => $v)
  331.                     {
  332.                         if(TRUE === is_string($v))
  333.                         {
  334.                             $r[$k] = $v;
  335.                             continue;
  336.                         }
  337.                        
  338.                         $E = new ArgumentExpectedException([
  339.                             'target'    => $this->getName().'['.$k.']',
  340.                             'expected'  => 'string',
  341.                             'detected'  => $t = getType($v),
  342.                             'value'     => is_object($v) ? get_class($v) : (is_scalar($v) ? $v : NULL)
  343.                         ]);
  344.                        
  345.                         $a =
  346.                         [
  347.                             'offset'    => $k,
  348.                             'class'     => get_called_class()
  349.                         ];
  350.                        
  351.                         throw ($c === __CLASS__ || FALSE === class_exists($e))
  352.                             ? new ComponentMethodCallException($E, $a, ComponentMethodCallException::ERROR_M_PARSE_DEF_E_EXPECTED_STRING)
  353.                             : new $e($E, $a, $e::ERROR_M_PARSE_DEF_E_EXPECTED_STRING);
  354.                            
  355.                     }
  356.                    
  357.                     if([] !== $r)
  358.                         return $r;
  359.                    
  360.                     throw ($c === __CLASS__ || FALSE === class_exists($e))
  361.                         ? new ComponentMethodCallException(new ArgumentLengthZeroException, ['method' => __METHOD__], ComponentMethodCallException::ERROR_M_PARSE_DEF_E_RESULT_LENGTH_ZERO)
  362.                         : new $e(new ArgumentLengthZeroException, ['method' => __METHOD__], $e::ERROR_M_PARSE_DEF_E_RESULT_LENGTH_ZERO);
  363.                 }
  364.                 catch(ComponentMethodCallException $E)
  365.                 {
  366.                     throw $E;
  367.                 }
  368.                 catch(\Exception $E)
  369.                 {
  370.                     throw ($c === __CLASS__ || FALSE === class_exists($e))
  371.                         ? new ComponentMethodCallException($E, ComponentMethodCallException::ERROR_M_PARSE_DEF, ['method' => __METHOD__])
  372.                         : new $e($E, $e::ERROR_M_PARSE_DEF, ['method' => __METHOD__]);
  373.                 }
  374.             }
  375.        
  376.             /**
  377.              * Destroy anonymous ATD definitions
  378.              *
  379.              * @catchable   ILLI\Core\Std\Def\ADT\ComponentMethodCallException
  380.              * @throws  ILLI\Core\Std\Def\ADT\ComponentMethodCallException::ERROR_DTOR
  381.              * @void
  382.              */
  383.             public function __destruct()
  384.             {
  385.                 try
  386.                 {
  387.                     if(($c = get_called_class()) === __CLASS__)
  388.                         unset(self::$__gc[$this->getName()]);
  389.                 }
  390.                 catch(\Exception $E)
  391.                 {
  392.                     $c = get_called_class();
  393.                     $e = $c.'\ComponentMethodCallException';
  394.                     throw ($c === __CLASS__ || FALSE === class_exists($e))
  395.                         ? new ComponentMethodCallException($E, ComponentMethodCallException::ERROR_DTOR, ['method' => __METHOD__])
  396.                         : new $e($E, $e::ERROR_DTOR, ['method' => __METHOD__]);
  397.                 }
  398.             }
  399.        
  400.             /**
  401.              * generate gc-hash-address from called-class or from spl_object_hash
  402.              *
  403.              * :offset<long>
  404.              *  zero-based index
  405.              *
  406.              * :gcType<string>
  407.              *  a valid __const_Type
  408.              *
  409.              * @param   array $__defineTypes [{:offset} => {:gcType}]
  410.              * @return  string
  411.              * @catchable   ILLI\Core\Std\Def\ADT\ComponentMethodCallException
  412.              * @throws  ILLI\Core\Std\Def\ADT\ComponentMethodCallException::ERROR_M_CREATE_HASH_ADDR
  413.              * @see     ::$__gc
  414.              */
  415.             protected function createHashAddr(array $__defineTypes = [])
  416.             {
  417.                 try
  418.                 {
  419.                     #~ performanced ADT: cache request by called-class; otherwise by hash
  420.                     return ($c = get_called_class()) === __CLASS__ ? Spl::nameWithHash($c, $this) : $c;
  421.                 }
  422.                 catch(\Exception $E)
  423.                 {
  424.                     $c = get_called_class();
  425.                     $e = $c.'\ComponentMethodCallException';
  426.                     throw ($c === __CLASS__ || FALSE === class_exists($e))
  427.                         ? new ComponentMethodCallException($E, ComponentMethodCallException::ERROR_M_CREATE_HASH_ADDR, ['method' => __METHOD__])
  428.                         : new $e($E, $e::ERROR_M_CREATE_HASH_ADDR, ['method' => __METHOD__]);
  429.                 }
  430.             }
  431.            
  432.             #:ILLI\Core\Std\Spl\Fsb:
  433.                 #+ forward Fsb::*() to ::$__gc::*()
  434.            
  435.                 /**
  436.                  * @return  integer
  437.                  * @catchable   ILLI\Core\Std\Def\ADT\ComponentMethodCallException
  438.                  * @throws  ILLI\Core\Std\Def\ADT\ComponentMethodCallException::ERROR_M_GET_SIZE
  439.                  */
  440.                 final public function getSize()
  441.                 {
  442.                     try
  443.                     {
  444.                         return $this->getGC()->getSize();
  445.                     }
  446.                     catch(\Exception $E)
  447.                     {
  448.                         $c = get_called_class();
  449.                         $e = $c.'\ComponentMethodCallException';
  450.                         throw ($c === __CLASS__ || FALSE === class_exists($e))
  451.                             ? new ComponentMethodCallException($E, ComponentMethodCallException::ERROR_M_GET_SIZE, ['method' => __METHOD__])
  452.                             : new $e($E, $e::ERROR_M_GET_SIZE, ['method' => __METHOD__]);
  453.                     }
  454.                 }
  455.                
  456.                 /**
  457.                  * @return  integer
  458.                  * @catchable   ILLI\Core\Std\Def\ADT\ComponentMethodCallException
  459.                  * @throws  ILLI\Core\Std\Def\ADT\ComponentMethodCallException::ERROR_M_OFFSET_EXISTS
  460.                  */
  461.                 final public function offsetExists($__offset)
  462.                 {
  463.                     try
  464.                     {
  465.                         return $this->getGC()->offsetExists($__offset);
  466.                     }
  467.                     catch(\Exception $E)
  468.                     {
  469.                         $c = get_called_class();
  470.                         $e = $c.'\ComponentMethodCallException';
  471.                         throw ($c === __CLASS__ || FALSE === class_exists($e))
  472.                             ? new ComponentMethodCallException($E, ComponentMethodCallException::ERROR_M_OFFSET_EXISTS, ['method' => __METHOD__])
  473.                             : new $e($E, $e::ERROR_M_OFFSET_EXISTS, ['method' => __METHOD__]);
  474.                     }
  475.                 }
  476.                
  477.                 /**
  478.                  * @return  integer
  479.                  * @catchable   ILLI\Core\Std\Def\ADT\ComponentMethodCallException
  480.                  * @throws  ILLI\Core\Std\Def\ADT\ComponentMethodCallException::ERROR_M_OFFSET_GET
  481.                  */
  482.                 final public function offsetGet($__offset)
  483.                 {
  484.                     try
  485.                     {
  486.                         return $this->getGC()->offsetGet($__offset);
  487.                     }
  488.                     catch(\Exception $E)
  489.                     {
  490.                         $c = get_called_class();
  491.                         $e = $c.'\ComponentMethodCallException';
  492.                         throw ($c === __CLASS__ || FALSE === class_exists($e))
  493.                             ? new ComponentMethodCallException($E, ComponentMethodCallException::ERROR_M_OFFSET_GET, ['method' => __METHOD__])
  494.                             : new $e($E, $e::ERROR_M_OFFSET_GET, ['method' => __METHOD__]);
  495.                     }
  496.                 }
  497.                
  498.                 /**
  499.                  * @return  integer
  500.                  * @catchable   ILLI\Core\Std\Def\ADT\ComponentMethodCallException
  501.                  * @throws  ILLI\Core\Std\Def\ADT\ComponentMethodCallException::ERROR_M_COUNT
  502.                  */
  503.                 final public function count()
  504.                 {
  505.                     try
  506.                     {
  507.                         return $this->getGC()->count();
  508.                     }
  509.                     catch(\Exception $E)
  510.                     {
  511.                         $c = get_called_class();
  512.                         $e = $c.'\ComponentMethodCallException';
  513.                         throw ($c === __CLASS__ || FALSE === class_exists($e))
  514.                             ? new ComponentMethodCallException($E, ComponentMethodCallException::ERROR_M_COUNT, ['method' => __METHOD__])
  515.                             : new $e($E, $e::ERROR_M_COUNT, ['method' => __METHOD__]);
  516.                     }
  517.                 }
  518.                
  519.                 /**
  520.                  * @return  integer
  521.                  * @catchable   ILLI\Core\Std\Def\ADT\ComponentMethodCallException
  522.                  * @throws  ILLI\Core\Std\Def\ADT\ComponentMethodCallException::ERROR_M_CURRENT
  523.                  */
  524.                 final public function current()
  525.                 {
  526.                     try
  527.                     {
  528.                         return $this->getGC()->current();
  529.                     }
  530.                     catch(\Exception $E)
  531.                     {
  532.                         $c = get_called_class();
  533.                         $e = $c.'\ComponentMethodCallException';
  534.                         throw ($c === __CLASS__ || FALSE === class_exists($e))
  535.                             ? new ComponentMethodCallException($E, ComponentMethodCallException::ERROR_M_CURRENT, ['method' => __METHOD__])
  536.                             : new $e($E, $e::ERROR_M_CURRENT, ['method' => __METHOD__]);
  537.                     }
  538.                 }
  539.                
  540.                 /**
  541.                  * @return  integer
  542.                  * @catchable   ILLI\Core\Std\Def\ADT\ComponentMethodCallException
  543.                  * @throws  ILLI\Core\Std\Def\ADT\ComponentMethodCallException::ERROR_M_KEY
  544.                  */
  545.                 final public function key()
  546.                 {
  547.                     try
  548.                     {
  549.                         return $this->getGC()->key();
  550.                     }
  551.                     catch(\Exception $E)
  552.                     {
  553.                         $c = get_called_class();
  554.                         $e = $c.'\ComponentMethodCallException';
  555.                         throw ($c === __CLASS__ || FALSE === class_exists($e))
  556.                             ? new ComponentMethodCallException($E, ComponentMethodCallException::ERROR_M_KEY, ['method' => __METHOD__])
  557.                             : new $e($E, $e::ERROR_M_KEY, ['method' => __METHOD__]);
  558.                     }
  559.                 }
  560.                
  561.                 /**
  562.                  * @return  integer
  563.                  * @catchable   ILLI\Core\Std\Def\ADT\ComponentMethodCallException
  564.                  * @throws  ILLI\Core\Std\Def\ADT\ComponentMethodCallException::ERROR_M_NEXT
  565.                  */
  566.                 final public function next()
  567.                 {
  568.                     try
  569.                     {
  570.                         return $this->getGC()->next();
  571.                     }
  572.                     catch(\Exception $E)
  573.                     {
  574.                         $c = get_called_class();
  575.                         $e = $c.'\ComponentMethodCallException';
  576.                         throw ($c === __CLASS__ || FALSE === class_exists($e))
  577.                             ? new ComponentMethodCallException($E, ComponentMethodCallException::ERROR_M_NEXT, ['method' => __METHOD__])
  578.                             : new $e($E, $e::ERROR_M_NEXT, ['method' => __METHOD__]);
  579.                     }
  580.                 }
  581.                
  582.                 /**
  583.                  * @return  integer
  584.                  * @catchable   ILLI\Core\Std\Def\ADT\ComponentMethodCallException
  585.                  * @throws  ILLI\Core\Std\Def\ADT\ComponentMethodCallException::ERROR_M_REWIND
  586.                  */
  587.                 final public function rewind()
  588.                 {
  589.                     try
  590.                     {
  591.                         return $this->getGC()->rewind();
  592.                     }
  593.                     catch(\Exception $E)
  594.                     {
  595.                         $c = get_called_class();
  596.                         $e = $c.'\ComponentMethodCallException';
  597.                         throw ($c === __CLASS__ || FALSE === class_exists($e))
  598.                             ? new ComponentMethodCallException($E, ComponentMethodCallException::ERROR_M_REWIND, ['method' => __METHOD__])
  599.                             : new $e($E, $e::ERROR_M_REWIND, ['method' => __METHOD__]);
  600.                     }
  601.                 }
  602.                
  603.                 /**
  604.                  * @return  integer
  605.                  * @catchable   ILLI\Core\Std\Def\ADT\ComponentMethodCallException
  606.                  * @throws  ILLI\Core\Std\Def\ADT\ComponentMethodCallException::ERROR_M_VALID
  607.                  */
  608.                 final public function valid()
  609.                 {
  610.                     try
  611.                     {
  612.                         return $this->getGC()->valid();
  613.                     }
  614.                     catch(\Exception $E)
  615.                     {
  616.                         $c = get_called_class();
  617.                         $e = $c.'\ComponentMethodCallException';
  618.                         throw ($c === __CLASS__ || FALSE === class_exists($e))
  619.                             ? new ComponentMethodCallException($E, ComponentMethodCallException::ERROR_M_VALID, ['method' => __METHOD__])
  620.                             : new $e($E, $e::ERROR_M_VALID, ['method' => __METHOD__]);
  621.                     }
  622.                 }
  623.                
  624.                 /**
  625.                  * @return  integer
  626.                  * @catchable   ILLI\Core\Std\Def\ADT\ComponentMethodCallException
  627.                  * @throws  ILLI\Core\Std\Def\ADT\ComponentMethodCallException::ERROR_M_END
  628.                  */
  629.                 final public function end()
  630.                 {
  631.                     try
  632.                     {
  633.                         return $this->getGC()->end();
  634.                     }
  635.                     catch(\Exception $E)
  636.                     {
  637.                         $c = get_called_class();
  638.                         $e = $c.'\ComponentMethodCallException';
  639.                         throw ($c === __CLASS__ || FALSE === class_exists($e))
  640.                             ? new ComponentMethodCallException($E, ComponentMethodCallException::ERROR_M_END, ['method' => __METHOD__])
  641.                             : new $e($E, $e::ERROR_M_END, ['method' => __METHOD__]);
  642.                     }
  643.                 }
  644.                
  645.                 /**
  646.                  * @return  integer
  647.                  * @catchable   ILLI\Core\Std\Def\ADT\ComponentMethodCallException
  648.                  * @throws  ILLI\Core\Std\Def\ADT\ComponentMethodCallException::ERROR_M_KEYS
  649.                  */
  650.                 final public function keys()
  651.                 {
  652.                     try
  653.                     {
  654.                         return $this->getGC()->keys();
  655.                     }
  656.                     catch(\Exception $E)
  657.                     {
  658.                         $c = get_called_class();
  659.                         $e = $c.'\ComponentMethodCallException';
  660.                         throw ($c === __CLASS__ || FALSE === class_exists($e))
  661.                             ? new ComponentMethodCallException($E, ComponentMethodCallException::ERROR_M_KEYS, ['method' => __METHOD__])
  662.                             : new $e($E, $e::ERROR_M_KEYS, ['method' => __METHOD__]);
  663.                     }
  664.                 }
  665.                
  666.                 /**
  667.                  * @return  integer
  668.                  * @catchable   ILLI\Core\Std\Def\ADT\ComponentMethodCallException
  669.                  * @throws  ILLI\Core\Std\Def\ADT\ComponentMethodCallException::ERROR_M_PREV
  670.                  */
  671.                 final public function prev()
  672.                 {
  673.                     try
  674.                     {
  675.                         return $this->getGC()->prev();
  676.                     }
  677.                     catch(\Exception $E)
  678.                     {
  679.                         $c = get_called_class();
  680.                         $e = $c.'\ComponentMethodCallException';
  681.                         throw ($c === __CLASS__ || FALSE === class_exists($e))
  682.                             ? new ComponentMethodCallException($E, ComponentMethodCallException::ERROR_M_PREV, ['method' => __METHOD__])
  683.                             : new $e($E, $e::ERROR_M_PREV, ['method' => __METHOD__]);
  684.                     }
  685.                 }
  686.                
  687.                 /**
  688.                  * @return  integer
  689.                  * @catchable   ILLI\Core\Std\Def\ADT\ComponentMethodCallException
  690.                  * @throws  ILLI\Core\Std\Def\ADT\ComponentMethodCallException::ERROR_M_VALUES
  691.                  */
  692.                 final public function values()
  693.                 {
  694.                     try
  695.                     {
  696.                         return $this->getGC()->values();
  697.                     }
  698.                     catch(\Exception $E)
  699.                     {
  700.                         $c = get_called_class();
  701.                         $e = $c.'\ComponentMethodCallException';
  702.                         throw ($c === __CLASS__ || FALSE === class_exists($e))
  703.                             ? new ComponentMethodCallException($E, ComponentMethodCallException::ERROR_M_VALUES, ['method' => __METHOD__])
  704.                             : new $e($E, $e::ERROR_M_VALUES, ['method' => __METHOD__]);
  705.                     }
  706.                 }
  707.            
  708.                 #:NotSupported:
  709.                     #! disable Fsb element modifiers
  710.                    
  711.                     /**
  712.                      * @notSupported
  713.                      * @throws  ILLI\Core\Std\Exception\NotSupportedException
  714.                      */
  715.                     final public function setSize($__size)
  716.                     {
  717.                         $c = get_called_class();
  718.                         $e = $c.'\ComponentMethodCallException';
  719.                         $E = new NotSupportedException(['target' => __METHOD__]);
  720.                         throw ($c === __CLASS__ || FALSE === class_exists($e))
  721.                             ? new ComponentMethodCallException($E, ComponentMethodCallException::ERROR_M_SET_SIZE, ['method' => __METHOD__])
  722.                             : new $e($E, $e::ERROR_M_SET_SIZE, ['method' => __METHOD__]);
  723.                     }
  724.                    
  725.                     /**
  726.                      * @notSupported
  727.                      * @throws  ILLI\Core\Std\Exception\NotSupportedException
  728.                      */
  729.                     final public function offsetSet($__offset, $__value)
  730.                     {
  731.                         $c = get_called_class();
  732.                         $e = $c.'\ComponentMethodCallException';
  733.                         $E = new NotSupportedException(['target' => __METHOD__]);
  734.                         throw ($c === __CLASS__ || FALSE === class_exists($e))
  735.                             ? new ComponentMethodCallException($E, ComponentMethodCallException::ERROR_M_OFFSET_SET, ['method' => __METHOD__])
  736.                             : new $e($E, $e::ERROR_M_OFFSET_SET, ['method' => __METHOD__]);
  737.                     }
  738.                    
  739.                     /**
  740.                      * @notSupported
  741.                      * @throws  ILLI\Core\Std\Exception\NotSupportedException
  742.                      */
  743.                     final public function offsetUnset($__offset)
  744.                     {
  745.                         $c = get_called_class();
  746.                         $e = $c.'\ComponentMethodCallException';
  747.                         $E = new NotSupportedException(['target' => __METHOD__]);
  748.                         throw ($c === __CLASS__ || FALSE === class_exists($e))
  749.                             ? new ComponentMethodCallException($E, ComponentMethodCallException::ERROR_M_OFFSET_UNSET, ['method' => __METHOD__])
  750.                             : new $e($E, $e::ERROR_M_OFFSET_UNSET, ['method' => __METHOD__]);
  751.                     }
  752.                    
  753.                     /**
  754.                      * @notSupported
  755.                      * @throws  ILLI\Core\Std\Exception\NotSupportedException
  756.                      */
  757.                     final public static function fromArray($__array, $__saveIndexes = TRUE)
  758.                     {
  759.                         $c = get_called_class();
  760.                         $e = $c.'\ComponentMethodCallException';
  761.                         $E = new NotSupportedException(['target' => __METHOD__]);
  762.                         throw ($c === __CLASS__ || FALSE === class_exists($e))
  763.                             ? new ComponentMethodCallException($E, ComponentMethodCallException::ERROR_M_FROM_ARRAY, ['method' => __METHOD__])
  764.                             : new $e($E, $e::ERROR_M_FROM_ARRAY, ['method' => __METHOD__]);
  765.                     }
  766.                 #::
  767.             #::
  768.         #::
  769.        
  770.         #:deprecated:
  771.             /**
  772.              * @deprecated
  773.              */
  774.             final protected function mergeTypes(array $__definedTypes, array $__defineTypes)
  775.             {
  776.                     throw new NotSupportedException([
  777.                         'target' => __METHOD__
  778.                     ]);
  779.                 $a = func_get_args();
  780.                 $r = [];
  781.                
  782.                 foreach($a as $t)
  783.                 {
  784.                     foreach($t as $k => $v)
  785.                     {
  786.                         if(FALSE === is_integer($k))
  787.                             throw new ArgumentExpectedException([
  788.                                 'target'    => get_called_class().'['.$k.']',
  789.                                 'expected'  => 'integer',
  790.                                 'detected'  => $t = getType($v),
  791.                                 'value'     => is_object($v) ? get_class($v) : (is_scalar($v) ? $v : NULL)
  792.                             ]);
  793.                            
  794.                         if(isset($r[$k]))
  795.                             throw new ArgumentInUseException([
  796.                                 'target' => get_called_class().'['.$k.']'
  797.                             ]);
  798.                            
  799.                         $r[$k] = $v;
  800.                     }
  801.                 }
  802.                
  803.                 return $r;
  804.             }
  805.         #::
  806.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement