Example #1
0
 /**
  * @throws XMLDatatype\Exception\OutOfBoundsException
  * @param int $value
  */
 public function setValue($value)
 {
     if ($value < 0 || $value > 65535) {
         throw new \XMLDatatype\Exception\OutOfBoundsException('UnsignedShort out of bounds');
     }
     parent::setValue($value);
 }
 public static function init()
 {
     self::$classCRC32Cache = new IdentityHashMap();
     self::$CLASS_TO_SERIALIZER_INSTANCE = new IdentityHashMap();
     self::$NO_SUCH_SERIALIZER = new SerializabilityUtilEx_NoSuchSerializer();
     self::$SERIALIZED_PRIMITIVE_TYPE_NAMES = new HashMap();
     self::$TYPES_WHOSE_IMPLEMENTATION_IS_EXCLUDED_FROM_SIGNATURES = new HashSet();
     self::$SERIALIZED_PRIMITIVE_TYPE_NAMES->put(Boolean::typeClass()->getFullName(), "Z");
     self::$SERIALIZED_PRIMITIVE_TYPE_NAMES->put(Byte::typeClass()->getFullName(), "B");
     self::$SERIALIZED_PRIMITIVE_TYPE_NAMES->put(Character::typeClass()->getFullName(), "C");
     self::$SERIALIZED_PRIMITIVE_TYPE_NAMES->put(Double::typeClass()->getFullName(), "D");
     self::$SERIALIZED_PRIMITIVE_TYPE_NAMES->put(Float::typeClass()->getFullName(), "F");
     self::$SERIALIZED_PRIMITIVE_TYPE_NAMES->put(Integer::typeClass()->getFullName(), "I");
     self::$SERIALIZED_PRIMITIVE_TYPE_NAMES->put(Long::typeClass()->getFullName(), "J");
     self::$SERIALIZED_PRIMITIVE_TYPE_NAMES->put(Short::typeClass()->getFullName(), "S");
     self::$TYPES_WHOSE_IMPLEMENTATION_IS_EXCLUDED_FROM_SIGNATURES->add(Boolean::clazz());
     self::$TYPES_WHOSE_IMPLEMENTATION_IS_EXCLUDED_FROM_SIGNATURES->add(Byte::clazz());
     self::$TYPES_WHOSE_IMPLEMENTATION_IS_EXCLUDED_FROM_SIGNATURES->add(Character::clazz());
     self::$TYPES_WHOSE_IMPLEMENTATION_IS_EXCLUDED_FROM_SIGNATURES->add(Double::clazz());
     //TODO Exception class
     //self::$TYPES_WHOSE_IMPLEMENTATION_IS_EXCLUDED_FROM_SIGNATURES->add(Exception::clazz());
     self::$TYPES_WHOSE_IMPLEMENTATION_IS_EXCLUDED_FROM_SIGNATURES->add(Float::clazz());
     self::$TYPES_WHOSE_IMPLEMENTATION_IS_EXCLUDED_FROM_SIGNATURES->add(Integer::clazz());
     self::$TYPES_WHOSE_IMPLEMENTATION_IS_EXCLUDED_FROM_SIGNATURES->add(Long::clazz());
     self::$TYPES_WHOSE_IMPLEMENTATION_IS_EXCLUDED_FROM_SIGNATURES->add(Object::clazz());
     self::$TYPES_WHOSE_IMPLEMENTATION_IS_EXCLUDED_FROM_SIGNATURES->add(Short::clazz());
     self::$TYPES_WHOSE_IMPLEMENTATION_IS_EXCLUDED_FROM_SIGNATURES->add(String::clazz());
     self::$TYPES_WHOSE_IMPLEMENTATION_IS_EXCLUDED_FROM_SIGNATURES->add(Classes::classOf('Throwable'));
 }
Example #3
0
 /**
  * @throws XMLDatatype\Exception\OutOfBoundsException
  * @param int $value 
  */
 public function setValue($value)
 {
     if ($value < -32768 || $value > 32767) {
         throw new \XMLDatatype\Exception\OutOfBoundsException('Short out of bounds');
     }
     parent::setValue($value);
 }
Example #4
0
 public function __construct(array $options = array())
 {
     $this->_options['primary_key'] = true;
     $this->_options['auto_increment'] = true;
     $this->_options['editable'] = false;
     parent::__construct($options);
 }
Example #5
0
 /**
  * {@inheritdoc}
  */
 public function toInteger(RoundingMode $roundingMode = null)
 {
     if ($roundingMode === null) {
         $roundingMode = RoundingMode::HALF_UP();
     }
     return Integer::fromNative(\round($this->toNative(), 0, $roundingMode->toNative()));
 }
Example #6
0
 /**
  * Creates a new instance of a throwable object.
  *
  * @param blaze\lang\String|string $message The error message.
  * @param blaze\lang\Integer|int $code The error code.
  * @param blaze\lang\Throwable $previous The th
  */
 public function __construct($message = null, $code = null, $previous = null)
 {
     parent::__construct(String::asNative($message), Integer::asNative($code), $previous);
     if ($previous != null && !$previous instanceof Throwable) {
         new IllegalArgumentException('Previous element must be a subtype of Throwable', 0, $this);
     }
 }
Example #7
0
 /**
  * Converts from string to signed integer. The string can contains the "px" unit.
  * 
  * The minimum and maximum value depends on the system:
  * <ul>
  * <li>32 bit systems have a range of -2147483648 to 2147483647 and</li>
  * <li>32 bit systems have a range of -9223372036854775807 to 9223372036854775807.</li>
  * </ul>
  * 
  * Empty string throws an exception.
  * @param string|boolean $value A string or boolean <i>true</i>
  * @return int
  * @throws UserError When value is not a signed integer.
  */
 public function parse($value)
 {
     // remove the px unit
     if (is_string($value)) {
         $value = str_ireplace(array('px', 'p', 'pt', 'pixel'), '', $value);
     }
     return parent::parse($value);
 }
Example #8
0
 /**
  * Declares the widget's parameters:
  * <ul>
  * <li>instanciates Parameter objects,</li>
  * <li>configures them and</li>
  * <li>calls addParameter() for each of them.</li>
  * </ul>
  * 
  * @return void
  */
 protected function declareParameters()
 {
     global $wgWFMKMaxWidth;
     $track = new Integer('track');
     $track->setMin(0);
     $user = new Integer('user');
     $user->setMin(0);
     $playlist = new Integer('playlist');
     $playlist->setMin(0);
     $this->source = new XorParameter('source');
     $this->source->addParameter($track);
     $this->source->addParameter($user);
     $this->source->addParameter($playlist);
     $this->source->setRequired();
     // user need to set one of these parameter
     $this->source->setDefaultParameter($track);
     // user don't need to type "track=xxx", just "xxx" at right position
     $this->addParameter($this->source);
     $this->width = new IntegerInPixel('width');
     $this->width->setDefaultValue($wgWFMKMaxWidth);
     $this->width->setMax($wgWFMKMaxWidth);
     $this->addParameter($this->width);
     $this->height = new IntegerInPixel('height');
     $this->height->setDefaultValue(450);
     // updated later to 166 if source is "track"
     $this->addParameter($this->height);
     $this->autoplay = new Boolean('autoplay');
     $this->addParameter($this->autoplay);
     $this->artwork = new Boolean('artwork');
     $this->addParameter($this->artwork);
     $this->comments = new Boolean('comments');
     $this->addParameter($this->comments);
     $this->playcount = new Boolean('playcount');
     $this->addParameter($this->playcount);
     $this->like = new Boolean('like');
     $this->addParameter($this->like);
     $float = new XorParameter('float');
     $this->right = new Option('right');
     $float->addParameter($this->right);
     $this->left = new Option('left');
     $float->addParameter($this->left);
     $this->addParameter($float);
 }
Example #9
0
 public static function init()
 {
     self::$TYPE_NAMES[' Z'] = Boolean::typeClass();
     self::$TYPE_NAMES[' B'] = Byte::typeClass();
     self::$TYPE_NAMES[' C'] = Character::typeClass();
     self::$TYPE_NAMES[' D'] = Double::typeClass();
     self::$TYPE_NAMES[' F'] = Float::typeClass();
     self::$TYPE_NAMES[' I'] = Integer::typeClass();
     self::$TYPE_NAMES[' J'] = Long::typeClass();
     self::$TYPE_NAMES[' S'] = Short::typeClass();
 }
 /**
  * 
  * function val - This function checks if the value valid if isn't throw an exception.
  * 
  * @param null $val
  * @return void
  * @throws \SimplOn\DataValidationException
  */
 public function val($val = null)
 {
     if ($val) {
         if (in_array($val, $this->options)) {
             parent::val($val);
         } else {
             throw new \SimplOn\DataValidationException($this->valudationNotAnOption);
         }
     } else {
         return $this->val;
     }
 }
Example #11
0
    public function testIntegerProperty()
    {
        $min = 1;
        $max = 100;
        $validInteger = 5;
        $toLarge = 102;
        $toSmall = 0;
        $property = new Integer('AProperty', null, $min, $max);

        $property->setValue($validInteger);
        $this->assertEquals($validInteger, $property->getValue());

        $property->setValue($toLarge);
        $this->assertEquals($max, $property->getValue());

        $property->setValue($toSmall);
        $this->assertEquals($min, $property->getValue());
    }
Example #12
0
 public function getType($object)
 {
     $type = \strtolower(\gettype($object));
     if (is_int($type)) {
         $int = Integer::parse($object);
         //If an integer type was not enough to store the value
         //let it fall through to string type
         if ($int !== null) {
             return $int;
         }
     }
     if (\is_float($object)) {
         //Prefer decimal over floating point
         return Decimal::parse($object);
     }
     if (\is_bool($object)) {
         return Boolean::parse($object);
     }
     return String::parse($object);
 }
Example #13
0
 /**
  * Answer the result of multiplying the receiver and aNumber.
  * 
  * @param object Number $aNumber
  * @return object Number
  * @access public
  * @since 7/14/05
  */
 function multipliedBy($aNumber)
 {
     if (!(strtolower($class) == strtolower('Integer') || is_subclass_of(new $class(), 'Integer'))) {
         $obj = Integer::withValue($this->value() * $aNumber->value());
         return $obj;
     } else {
         $obj = Float::withValue($this->value() * $aNumber->value());
         return $obj;
     }
 }
 public function makeBackRef(ValueCommand $x)
 {
     $toReturn = $this->valueBackRefs->get($x);
     if (is_null($toReturn)) {
         if (empty($this->freeBackRefs)) {
             $idx = $this->valueBackRefs->size();
             $toReturn = CommandClientSerializationStreamReader::BACKREF_IDENT . '._' . Integer::toString($idx, Character::MAX_RADIX);
         } else {
             $toReturn = array_pop($this->freeBackRefs);
         }
         $this->valueBackRefs->put($x, $toReturn);
     }
     return $toReturn;
 }
 public function writeValue(Clazz $clazz, $instance)
 {
     if ($clazz === Boolean::typeClass()) {
         $this->writeObject(new Boolean($instance));
     } else {
         if ($clazz === Byte::typeClass()) {
             $this->writeObject(new Byte($instance));
         } else {
             if ($clazz === Character::typeClass()) {
                 $this->writeObject(new Character($instance));
             } else {
                 if ($clazz === Double::typeClass()) {
                     $this->writeObject(new Double($instance));
                 } else {
                     if ($clazz === Float::typeClass()) {
                         $this->writeObject(new Float($instance));
                     } else {
                         if ($clazz === Integer::typeClass()) {
                             $this->writeObject(new Integer($instance));
                         } else {
                             if ($clazz === Long::typeClass()) {
                                 $this->writeObject(new Long($instance));
                             } else {
                                 if ($clazz === Short::typeClass()) {
                                     $this->writeObject(new Short($instance));
                                 } else {
                                     if ($clazz === String::clazz()) {
                                         $this->writeString($instance);
                                     } else {
                                         if ($clazz->isEnum()) {
                                             $this->writeEnum($clazz, $instance);
                                         } else {
                                             $this->writeObject($instance);
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Example #16
0
 public function intValue()
 {
     return Integer::asNative($this->value);
 }
Example #17
0
 protected function __construct($input)
 {
     parent::__construct($input, __CLASS__);
 }
Example #18
0
 /**
  * @param strig $label
  * @param array $sources
  * @param string $flags
  * @param type $searchOp
  */
 public function __construct($label, $sources, $flags = null, $searchOp = null)
 {
     $this->sources = $sources;
     parent::__construct($label, $flags, null, $searchOp);
 }
 /**
  * @see \Components\Object::hashCode() \Components\Object::hashCode()
  */
 public function hashCode()
 {
     return Integer::hash($this->m_value);
 }
Example #20
0
 public function testToString()
 {
     $s = new Integer(5);
     $this->assertEquals("5", $s->__toString());
 }
Example #21
0
 /**
  * Constructor
  *
  * @param int|string $number
  */
 public function __construct($number)
 {
     parent::__construct($number);
     $this->_typeTag = self::TYPE_ENUMERATED;
 }
 private function decodeCommand()
 {
     $command = $this->next();
     if ($command == NL_CHAR) {
         $command = $this->next();
     }
     $token = $this->token();
     switch ($command) {
         case BOOLEAN_TYPE:
             $this->pushScalar(new BooleanValueCommand($token == '1'));
             break;
         case BYTE_TYPE:
             $this->pushScalar(new ByteValueCommand(Byte::valueOf($token)));
             break;
         case CHAR_TYPE:
             $this->pushScalar(new CharValueCommand(Character::chr(intval($token))));
             break;
         case DOUBLE_TYPE:
             $this->pushScalar(new DoubleValueCommand(Double::valueOf($token)));
             break;
         case FLOAT_TYPE:
             $this->pushScalar(new FloatValueCommand(Float::valueOf($token)));
             break;
         case INT_TYPE:
             $this->pushScalar(new IntValueCommand(Integer::valueOf($token)));
             break;
         case LONG_TYPE:
             $this->pushScalar(new LongValueCommand(Long::valueOf($token)));
             break;
         case VOID_TYPE:
             $this->pushScalar(NullValueCommand::INSTANCE());
             break;
         case SHORT_TYPE:
             $this->pushScalar(new ShortValueCommand(Short::valueOf($token)));
             break;
         case STRING_TYPE:
             // "4~abcd
             $length = Integer::valueOf($token);
             $value = $this->nextCount($length);
             if ($this->next() != RPC_SEPARATOR_CHAR) {
                 throw new RuntimeException('Overran string');
             }
             $this->pushString(new StringValueCommand($value));
             break;
         case ENUM_TYPE:
             // ETypeSeedName~IOrdinal~
             $ordinal = $this->readCommand('IntValueCommand')->getValue();
             $clazz = $this->findClass($token);
             $x = new EnumValueCommand($clazz);
             $this->pushIdentity($x);
             $x->setValue($ordinal);
             break;
         case ARRAY_TYPE:
             // Encoded as (leafType, dimensions, length, ...)
             $leaf = $this->findClass($token);
             $numDims = $this->readCommand('IntValueCommand')->getValue();
             $clazz = null;
             if ($numDims > 1) {
                 $clazz = ArrayType::clazz($leaf, $numDims);
             } else {
                 $clazz = $leaf;
             }
             $x = new ArrayValueCommand($clazz);
             $this->pushIdentity($x);
             $length = $this->readCommand('IntValueCommand')->getValue();
             for ($i = 0; $i < $length; $i++) {
                 $x->add($this->readCommand('ValueCommand'));
             }
             break;
         case OBJECT_TYPE:
             // LTypeSeedName~3... N-many setters ...
             $clazz = $this->findClass($token);
             $x = new InstantiateCommand($clazz);
             $this->pushIdentity($x);
             $this->readSetters($clazz, $x);
             break;
         case INVOKE_TYPE:
             // !TypeSeedName~Number of objects written by CFS~...CFS objects...~
             // Number of extra fields~...N-many setters...
             $clazz = $this->findClass($token);
             $serializerClass = null;
             $manualType = $clazz;
             while ($manualType != null) {
                 $serializerClass = SerializabilityUtil::hasCustomFieldSerializer($manualType);
                 if ($serializerClass != null) {
                     break;
                 }
                 $manualType = $manualType->getSuperClass();
             }
             if ($serializerClass == null) {
                 throw new IncompatibleRemoteServiceException('Class [' . $clazz->getName() . '] has no custom serializer on server');
             }
             $x = new InvokeCustomFieldSerializerCommand($clazz, $serializerClass, $manualType);
             $this->pushIdentity($x);
             $this->readFields($x);
             $this->readSetters($clazz, $x);
             break;
         case RETURN_TYPE:
             // R4~...values...
             $this->toReturn = new ReturnCommand();
             $toRead = Integer::valueOf($token);
             for ($i = 0; $i < $toRead; $i++) {
                 $this->toReturn->addValue($this->readCommand('ValueCommand'));
             }
             break;
         case THROW_TYPE:
             // T...value...
             $this->toThrow = $this->readCommand('ValueCommand');
             break;
         case BACKREF_TYPE:
             // @backrefNumber~
             $x = $this->backRefs[Integer::valueOf($token)];
             assert($x != null);
             array_push($this->commands, $x);
             break;
         case RPC_SEPARATOR_CHAR:
             throw new RuntimeException('Segmentation overrun at ' + $this->idx);
         default:
             throw new RuntimeException('Unknown Command ' + $command);
     }
 }
Example #23
0
 private static function printTypeName(Clazz $type)
 {
     // Primitives
     //
     if ($type === Integer::typeClass()) {
         return 'int';
     } else {
         if ($type === Long::typeClass()) {
             return 'long';
         } else {
             if ($type === Short::typeClass()) {
                 return 'short';
             } else {
                 if ($type === Byte::typeClass()) {
                     return 'byte';
                 } else {
                     if ($type === Character::typeClass()) {
                         return 'char';
                     } else {
                         if ($type === Boolean::typeClass()) {
                             return 'boolean';
                         } else {
                             if ($type === Float::typeClass()) {
                                 return 'float';
                             } else {
                                 if ($type === Double::typeClass()) {
                                     return 'double';
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     // Arrays
     //
     if ($type->isArray()) {
         $componentType = $type->getComponentType();
         return self::printTypeName($componentType) . '[]';
     }
     // Everything else
     //
     return str_replace('$', '.', $type->getName());
 }
 private function deserializeStringTable()
 {
     $typeNameCount = $this->readInt();
     $buffer = new SSSR_BoundedList(String::clazz(), $typeNameCount);
     for ($typeNameIndex = 0; $typeNameIndex < $typeNameCount; ++$typeNameIndex) {
         $str = $this->extract();
         // Change quoted characters back.
         $idx = mb_strpos($str, '\\');
         if ($idx !== false) {
             $buf = '';
             $pos = 0;
             while ($idx >= 0) {
                 $buf .= mb_substr($str, $pos, $idx - $pos);
                 if (++$idx == mb_strlen($str)) {
                     throw new SerializationException("Unmatched backslash: \"{$str}\"");
                 }
                 $ch = mb_substr($str, $idx, 1);
                 $pos = $idx + 1;
                 switch (Character::ord($ch)) {
                     case Character::ord('0'):
                         $buf .= '\\u0000';
                         break;
                     case Character::ord('!'):
                         $buf .= self::RPC_SEPARATOR_CHAR;
                         break;
                     case Character::ord('\\'):
                         $buf .= $ch;
                         break;
                     case Character::ord('u'):
                         try {
                             $ch = Character::chr(Integer::parseHex(mb_substr($str, $idx + 1, 4)));
                         } catch (NumberFormatException $e) {
                             throw new SerializationException("Invalid Unicode escape sequence \"{$str}\"");
                         }
                         $buf .= $ch;
                         $pos += 4;
                         break;
                     default:
                         throw new SerializationException("Unexpected escape character {$ch} after backslash: \"{$str}\"");
                 }
                 $idx = mb_strpos($str, '\\', $pos);
             }
             $buf .= mb_substr($str, $pos);
             $str = buf;
         }
         $buffer->add($str);
     }
     if ($buffer->size() != $buffer->getExpectedSize()) {
         throw new SerializationException('Expected ' . $buffer->getExpectedSize() . ' string table elements; received ' . $buffer->size());
     }
     $this->stringTable = $buffer->toArray();
 }
 /**
  * creates appropriate object from given ids
  * 
  * @param Id $structureId
  * @param Id $partStructureId
  * @param String $part
  * @return object mixed
  * @access public
  * @since 7/21/05
  */
 function getPartObject($structureId, $partStructureId, $part)
 {
     $structure = $this->_destinationRepository->getRecordStructure($structureId);
     $partStructure = $structure->getPartStructure($partStructureId);
     $type = $partStructure->getType();
     $typeString = $type->getKeyword();
     switch ($typeString) {
         case "shortstring":
         case "string":
             $obj = String::withValue($part);
             return $obj;
             break;
         case "integer":
             $obj = Integer::withValue($part);
             return $obj;
             break;
         case "boolean":
             $obj = Boolean::withValue($part);
             return $obj;
             break;
         case "float":
             $obj = Float::withValue($part);
             return $obj;
             break;
         case "datetime":
             $obj = DateAndTime::fromString($part);
             return $obj;
             break;
         case "type":
             $obj = HarmoniType::fromString($part);
             return $obj;
             break;
         default:
             $this->addError("Unsupported PartStructure DataType: " . HarmoniType::typeToString($type) . ".");
             $false = false;
             return $false;
     }
 }
 public function getTargetType()
 {
     return Integer::typeClass();
 }
Example #27
0
 public function getInput()
 {
     $input = parent::getInput();
     $input->setSize(10, 10);
     return $input;
 }
Example #28
0
 /**
  * @param mixed $nullOrValue
  */
 protected function setValue($nullOrValue)
 {
     if (is_null($nullOrValue)) {
         $this->value = $nullOrValue;
     } else {
         parent::setValue($nullOrValue);
     }
 }
 /**
  * Returns the values of wizard-components. Should return an array if children are involved,
  * otherwise a whatever type of object is expected.
  * @access public
  * @return mixed
  */
 function getAllValues()
 {
     $obj = Integer::withValue($this->_value ? intval($this->_value) : 0);
     return $obj;
 }
Example #30
0
 /**
  * Answer a new object with the value zero
  * 
  * @param optional string $class The class to instantiate. Do NOT use outside 
  *		of this package.
  * @return object ByteSize
  * @access public
  * @static
  * @since 7/14/05
  */
 static function zero($class = 'ByteSize')
 {
     return parent::zero($class);
 }