コード例 #1
0
ファイル: BitSet.php プロジェクト: sheepguru/php-enum-set
 /**
  * Detect if an integer is binary or not
  * Uses some nifty bit-hackery.
  * If i is even then i & ( i - 1 ) == 0
  * Look at that in base 2, it's neat to see it in action :)
  * @param int $i Integer to test
  * @return boolean is base 2
  * @static
  */
 public static function isBase2($i)
 {
     if (!EDataType::isInt($i)) {
         return false;
     }
     return $i != 0 && ($i & $i - 1) == 0;
 }
コード例 #2
0
ファイル: IntStr.php プロジェクト: sheepguru/php-enum-set
 /**
  * Create a new IntStr instance
  * @param int $int Int
  * @param string $str String
  * @throws InvalidArgumentException if int is not an integer
  */
 public static function create($int, $str)
 {
     if (!EDataType::isInt($int)) {
         throw new InvalidArgumentException('int must be an integer');
     }
     if (empty($str)) {
         $str = (string) $int;
     }
     $c = __CLASS__;
     return new $c($int, $str);
 }
コード例 #3
0
ファイル: EDataType.php プロジェクト: sheepguru/php-enum-set
 /**
  * Create a new IDataType instance based on the value of $val
  * @param mixed $val Value
  * @return IDataType instance
  * @static
  */
 public static function create($val)
 {
     $i = new EDataType();
     $i->setValue($i->detectType($val));
     return $i;
 }
コード例 #4
0
ファイル: UnitRec.php プロジェクト: sheepguru/php-enum-set
 /**
  * Sets the units. defaults to "px"
  * @param string $units Units
  */
 public function setUnits($units)
 {
     if (empty($units) || EDataType::isInt($units)) {
         $units = 'px';
     }
     $this->units = $units;
 }
コード例 #5
0
 /**
  * Sets the value
  * @param int $value Value
  * @throws InvalidArgumentException if $value is not an integer
  */
 public function setValue($value)
 {
     $parts = explode(' ', $value);
     if (empty($parts)) {
         return '';
     }
     if (isset($parts[0])) {
         if (!EDataType::isInt((int) $parts[0])) {
             throw new InvalidArgumentException("value must be an integer");
         }
         $this->value = (int) $parts[0];
     }
     if (isset($parts[1])) {
         $this->setUnits($parts[1]);
     }
 }