Advertisement
fruffl

PHP Tuple

Feb 13th, 2013
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.98 KB | None | 0 0
  1.     class typeFunction EXTENDS Tuple
  2.     {
  3.         CONST func  = 0x00;
  4.         CONST args  = 0x01;
  5.         CONST expected  = 0x02;
  6.        
  7.         function __construct(array $__define = [])
  8.         {
  9.             $defined =
  10.             [
  11.                 self::func  => \ILLI\Std\Def\constType::SPL_CLOSURE,
  12.                 self::args  => \ILLI\Std\Def\constType::SPL_TUPLE,
  13.                 self::expected  => \ILLI\Std\Def\constType::SPL_INTEGER
  14.             ];
  15.            
  16.             $define = $this->mergeTypes($defined, $__define);
  17.             parent::__construct($define);
  18.         }
  19.        
  20.         function __invoke()
  21.         {
  22.             $F = $this[self::func];
  23.             $r = $F();
  24.            
  25.             if(FALSE === $this->offsetValidate(self::expected, $r))
  26.                 throw new Exception('<<{:r}>{:f}>{:c}: result is <{:t}>{:s}.',
  27.                 [
  28.                     't' => $t = getType($r),
  29.                     's' => is_object($r) ? get_class($r) : (is_string($r) && (class_exists($r) || interface_exists($r)) ? $r : (is_scalar($r) ? $r : $t)),
  30.                     'c' => $this->getName(),
  31.                     'f' => implode('|', $this->offsetGetTypeDef(self::func)),
  32.                     'r' => implode('|', $this->offsetGetTypeDef(self::expected))
  33.                 ]);
  34.            
  35.             return $r;
  36.         }
  37.     }
  38.    
  39.     $f = new typeFunction;
  40.     $f->func = function()
  41.     {
  42.         return '4';
  43.     };
  44.    
  45.     var_dump($f());
  46.  
  47.  
  48. TRACK
  49.  
  50. OUTER   [UNSOLVED] <ILLI\Std\Exception:500>
  51.  
  52.     <<integer>closure>root\typeFunction: result is <string>4.
  53.  
  54.     NHADDR  NULL
  55.     PHADDR  NULL
  56.     CHADDR  000000005cf1508b0000000000e956e6: <ILLI\Std\Exception:500>
  57.     SYADDR  /var/www/dev/__MAIN__.ddl, line 69
  58.     RVADDR
  59.             <ILLI\Std\Exception:500>
  60.             0x01f4: line 0088 /var/www/dev/__MAIN__.ddl                         root\typeFunction->__invoke
  61.  
  62. CHADDR  000000005cf1508b0000000000e956e6
  63. ECADDR  500
  64. RVADDR 
  65.     OUTER   000000005cf1508b0000000000e956e6: [UNSOLVED]    <ILLI\Std\Exception:500>
  66.                                 <<integer>closure>root\typeFunction: result is <string>4.
  67.  
  68.  
  69. SET
  70.     CLASS: ILLI\Std\Exception
  71.     CH: 000000005cf1508b0000000000e956e6
  72.     CHADDR: 000000005cf1508b0000000000e956e6
  73.     ECADDR: 500
  74.     STATUS: UNSOLVED
  75.     MESSAGE: "<<integer>closure>root\\typeFunction: result is <string>4."
  76.     CODE: 500
  77.     FILE: /var/www/dev/__MAIN__.ddl
  78.     LINE: 69
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement