Advertisement
fruffl

Dec Type Hint Class

May 23rd, 2012
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 9.64 KB | None | 0 0
  1. <?PHP
  2.     /**
  3.      * ILLI
  4.      *
  5.      * @category   ILLI_System
  6.      * @package    ILLI
  7.      * @subpackage System
  8.      * @link       http://illi.be
  9.      * @license    http://l.illi.be
  10.      * @copyright  ILLI Conference
  11.      */
  12.     NAMESPACE ILLI\System;
  13.  
  14.     /**
  15.      * ILLI System Trait Numeric
  16.      */
  17.     TRAIT tDataTypeDecimal
  18.     {
  19.         # unary
  20.        
  21.         public function __bool()
  22.         {
  23.             return (bool) $this->__value;
  24.         }
  25.        
  26.         public function __bool_not()
  27.         {
  28.             return ! (bool) $this->__value;
  29.         }
  30.        
  31.         public function __bw_not()
  32.         {
  33.             return ~$this->__value;
  34.         }
  35.        
  36.         # binary
  37.        
  38.         public function __add($numericValue)
  39.         {
  40.             if($numericValue instanceOf DataTypeNumeric)
  41.                 $numericValue->get();
  42.            
  43.             if(FALSE === is_numeric($numericValue))
  44.                 throw new ArgumentException(E::ARGUMENT_EXPECTED_NUMERIC);
  45.            
  46.             return $this->__value + $numericValue;
  47.         }
  48.        
  49.         public function __sub($numericValue)
  50.         {
  51.             if($numericValue instanceOf DataTypeNumeric)
  52.                 $numericValue->get();
  53.            
  54.             if(FALSE === is_numeric($numericValue))
  55.                 throw new ArgumentException(E::ARGUMENT_EXPECTED_NUMERIC);
  56.            
  57.             return $this->__value - $numericValue;
  58.         }
  59.        
  60.         public function __mul($numericValue)
  61.         {
  62.             if($numericValue instanceOf DataTypeNumeric)
  63.                 $numericValue->get();
  64.            
  65.             if(FALSE === is_numeric($numericValue))
  66.                 throw new ArgumentException(E::ARGUMENT_EXPECTED_NUMERIC);
  67.            
  68.             return $this->__value * $numericValue;
  69.         }
  70.        
  71.         public function __div($numericValue)
  72.         {
  73.             if($numericValue instanceOf DataTypeNumeric)
  74.                 $numericValue->get();
  75.            
  76.             if(FALSE === is_numeric($numericValue))
  77.                 throw new ArgumentException(E::ARGUMENT_EXPECTED_NUMERIC);
  78.            
  79.             return $this->__value / $numericValue;
  80.         }
  81.        
  82.         public function __mod($numericValue)
  83.         {
  84.             if($numericValue instanceOf DataTypeNumeric)
  85.                 $numericValue->get();
  86.            
  87.             if(FALSE === is_numeric($numericValue))
  88.                 throw new ArgumentException(E::ARGUMENT_EXPECTED_NUMERIC);
  89.            
  90.             return $this->__value % $numericValue;
  91.         }
  92.        
  93.         public function __sl($numericValue)
  94.         {
  95.             if($numericValue instanceOf DataTypeNumeric)
  96.                 $numericValue->get();
  97.            
  98.             if(FALSE === is_numeric($numericValue))
  99.                 throw new ArgumentException(E::ARGUMENT_EXPECTED_NUMERIC);
  100.            
  101.             return $this->__value << $numericValue;
  102.         }
  103.        
  104.         public function __sr($numericValue)
  105.         {
  106.             if($numericValue instanceOf DataTypeNumeric)
  107.                 $numericValue->get();
  108.            
  109.             if(FALSE === is_numeric($numericValue))
  110.                 throw new ArgumentException(E::ARGUMENT_EXPECTED_NUMERIC);
  111.            
  112.             return $this->__value >> $numericValue;
  113.         }
  114.        
  115.         public function __concat($numericValue)
  116.         {
  117.             if($numericValue instanceOf DataTypeNumeric)
  118.                 $numericValue->get();
  119.            
  120.             if(FALSE === is_numeric($numericValue))
  121.                 throw new ArgumentException(E::ARGUMENT_EXPECTED_NUMERIC);
  122.            
  123.             return $this->__value . $numericValue;
  124.         }
  125.        
  126.         public function __bw_or($numericValue)
  127.         {
  128.             if($numericValue instanceOf DataTypeNumeric)
  129.                 $numericValue->get();
  130.            
  131.             if(FALSE === is_numeric($numericValue))
  132.                 throw new ArgumentException(E::ARGUMENT_EXPECTED_NUMERIC);
  133.            
  134.             return $this->__value | $numericValue;
  135.         }
  136.        
  137.         public function __bw_and($numericValue)
  138.         {
  139.             if($numericValue instanceOf DataTypeNumeric)
  140.                 $numericValue->get();
  141.            
  142.             if(FALSE === is_numeric($numericValue))
  143.                 throw new ArgumentException(E::ARGUMENT_EXPECTED_NUMERIC);
  144.            
  145.             return $this->__value & $numericValue;
  146.         }
  147.        
  148.         public function __bw_xor($numericValue)
  149.         {
  150.             if($numericValue instanceOf DataTypeNumeric)
  151.                 $numericValue->get();
  152.            
  153.             if(FALSE === is_numeric($numericValue))
  154.                 throw new ArgumentException(E::ARGUMENT_EXPECTED_NUMERIC);
  155.            
  156.             return $this->__value ^ $numericValue;
  157.         }
  158.        
  159.         # binary assign
  160.        
  161.         public function __assign_add($numericValue)
  162.         {
  163.             if($numericValue instanceOf DataTypeNumeric)
  164.                 $numericValue->get();
  165.            
  166.             if(FALSE === is_numeric($numericValue))
  167.                 throw new ArgumentException(E::ARGUMENT_EXPECTED_NUMERIC);
  168.            
  169.             return $this->__value += $numericValue;
  170.         }
  171.        
  172.         public function __assign_sub($numericValue)
  173.         {
  174.             if($numericValue instanceOf DataTypeNumeric)
  175.                 $numericValue->get();
  176.            
  177.             if(FALSE === is_numeric($numericValue))
  178.                 throw new ArgumentException(E::ARGUMENT_EXPECTED_NUMERIC);
  179.            
  180.             return $this->__value -= $numericValue;
  181.         }
  182.        
  183.         public function __assign_mul($numericValue)
  184.         {
  185.             if($numericValue instanceOf DataTypeNumeric)
  186.                 $numericValue->get();
  187.            
  188.             if(FALSE === is_numeric($numericValue))
  189.                 throw new ArgumentException(E::ARGUMENT_EXPECTED_NUMERIC);
  190.            
  191.             return $this->__value *= $numericValue;
  192.         }
  193.        
  194.         public function __assign_div($numericValue)
  195.         {
  196.             if($numericValue instanceOf DataTypeNumeric)
  197.                 $numericValue->get();
  198.            
  199.             if(FALSE === is_numeric($numericValue))
  200.                 throw new ArgumentException(E::ARGUMENT_EXPECTED_NUMERIC);
  201.            
  202.             return $this->__value /= $numericValue;
  203.         }
  204.        
  205.         public function __assign_mod($numericValue)
  206.         {
  207.             if($numericValue instanceOf DataTypeNumeric)
  208.                 $numericValue->get();
  209.            
  210.             if(FALSE === is_numeric($numericValue))
  211.                 throw new ArgumentException(E::ARGUMENT_EXPECTED_NUMERIC);
  212.            
  213.             return $this->__value %= $numericValue;
  214.         }
  215.        
  216.         public function __assign_sl($numericValue)
  217.         {
  218.             if($numericValue instanceOf DataTypeNumeric)
  219.                 $numericValue->get();
  220.            
  221.             if(FALSE === is_numeric($numericValue))
  222.                 throw new ArgumentException(E::ARGUMENT_EXPECTED_NUMERIC);
  223.            
  224.             return $this->__value <<= $numericValue;
  225.         }
  226.        
  227.         public function __assign_sr($numericValue)
  228.         {
  229.             if($numericValue instanceOf DataTypeNumeric)
  230.                 $numericValue->get();
  231.            
  232.             if(FALSE === is_numeric($numericValue))
  233.                 throw new ArgumentException(E::ARGUMENT_EXPECTED_NUMERIC);
  234.            
  235.             return $this->__value >>= $numericValue;
  236.         }
  237.        
  238.         public function __assign_concat($numericValue)
  239.         {
  240.             if($numericValue instanceOf DataTypeNumeric)
  241.                 $numericValue->get();
  242.            
  243.             if(FALSE === is_numeric($numericValue))
  244.                 throw new ArgumentException(E::ARGUMENT_EXPECTED_NUMERIC);
  245.            
  246.             return $this->__value .= $numericValue;
  247.         }
  248.        
  249.         public function __assign_bw_or($numericValue)
  250.         {
  251.             if($numericValue instanceOf DataTypeNumeric)
  252.                 $numericValue->get();
  253.            
  254.             if(FALSE === is_numeric($numericValue))
  255.                 throw new ArgumentException(E::ARGUMENT_EXPECTED_NUMERIC);
  256.            
  257.             return $this->__value |= $numericValue;
  258.         }
  259.        
  260.         public function __assign_bw_and($numericValue)
  261.         {
  262.             if($numericValue instanceOf DataTypeNumeric)
  263.                 $numericValue->get();
  264.            
  265.             if(FALSE === is_numeric($numericValue))
  266.                 throw new ArgumentException(E::ARGUMENT_EXPECTED_NUMERIC);
  267.            
  268.             return $this->__value &= $numericValue;
  269.         }
  270.        
  271.         public function __assign_bw_xor($numericValue)
  272.         {
  273.             if($numericValue instanceOf DataTypeNumeric)
  274.                 $numericValue->get();
  275.            
  276.             if(FALSE === is_numeric($numericValue))
  277.                 throw new ArgumentException(E::ARGUMENT_EXPECTED_NUMERIC);
  278.            
  279.             return $this->__value ^= $numericValue;
  280.         }
  281.        
  282.         # compare
  283.        
  284.         public function __is_identical($numericValue)
  285.         {
  286.             if($numericValue instanceOf DataTypeNumeric)
  287.                 $numericValue->get();
  288.            
  289.             if(FALSE === is_numeric($numericValue))
  290.                 throw new ArgumentException(E::ARGUMENT_EXPECTED_NUMERIC);
  291.            
  292.             return $this->__value === $numericValue;
  293.         }
  294.        
  295.         public function __is_not_identical($numericValue)
  296.         {
  297.             if($numericValue instanceOf DataTypeNumeric)
  298.                 $numericValue->get();
  299.            
  300.             if(FALSE === is_numeric($numericValue))
  301.                 throw new ArgumentException(E::ARGUMENT_EXPECTED_NUMERIC);
  302.            
  303.             return $this->__value !== $numericValue;
  304.         }
  305.        
  306.         public function __is_equal($numericValue)
  307.         {
  308.             if($numericValue instanceOf DataTypeNumeric)
  309.                 $numericValue->get();
  310.            
  311.             if(FALSE === is_numeric($numericValue))
  312.                 throw new ArgumentException(E::ARGUMENT_EXPECTED_NUMERIC);
  313.            
  314.             return $this->__value == $numericValue;
  315.         }
  316.        
  317.         public function __is_not_equal($numericValue)
  318.         {
  319.             if($numericValue instanceOf DataTypeNumeric)
  320.                 $numericValue->get();
  321.            
  322.             if(FALSE === is_numeric($numericValue))
  323.                 throw new ArgumentException(E::ARGUMENT_EXPECTED_NUMERIC);
  324.            
  325.             return $this->__value != $numericValue;
  326.         }
  327.        
  328.         public function __is_smaller($numericValue)
  329.         {
  330.             if($numericValue instanceOf DataTypeNumeric)
  331.                 $numericValue->get();
  332.            
  333.             if(FALSE === is_numeric($numericValue))
  334.                 throw new ArgumentException(E::ARGUMENT_EXPECTED_NUMERIC);
  335.            
  336.             return $this->__value < $numericValue;
  337.         }
  338.        
  339.         public function __is_smaller_or_equal($numericValue)
  340.         {
  341.             if($numericValue instanceOf DataTypeNumeric)
  342.                 $numericValue->get();
  343.            
  344.             if(FALSE === is_numeric($numericValue))
  345.                 throw new ArgumentException(E::ARGUMENT_EXPECTED_NUMERIC);
  346.            
  347.             return $this->__value <= $numericValue;
  348.         }
  349.        
  350.         public function __is_greater($numericValue)
  351.         {
  352.             if($numericValue instanceOf DataTypeNumeric)
  353.                 $numericValue->get();
  354.            
  355.             if(FALSE === is_numeric($numericValue))
  356.                 throw new ArgumentException(E::ARGUMENT_EXPECTED_NUMERIC);
  357.            
  358.             return $this->__value > $numericValue;
  359.         }
  360.        
  361.         public function __is_greater_or_equal($numericValue)
  362.         {
  363.             if($numericValue instanceOf DataTypeNumeric)
  364.                 $numericValue->get();
  365.            
  366.             if(FALSE === is_numeric($numericValue))
  367.                 throw new ArgumentException(E::ARGUMENT_EXPECTED_NUMERIC);
  368.            
  369.             return $this->__value >= $numericValue;
  370.         }
  371.        
  372.         public function __post_inc()
  373.         {
  374.             return $this->__value++;
  375.         }
  376.        
  377.         public function __post_dec()
  378.         {
  379.             return $this->__value--;
  380.         }
  381.        
  382.         public function __pre_inc()
  383.         {
  384.             $this->__value++;
  385.             return $this->__value;
  386.         }
  387.        
  388.         public function __pre_dec()
  389.         {
  390.             $this->__value--;
  391.             return $this->__value;
  392.         }
  393.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement