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'));
 }
Exemple #2
0
 /**
  * @throws XMLDatatype\Exception\UnexpectedValueException
  * @param string $value
  */
 public function setValue($value)
 {
     if ($value < 0) {
         throw new \XMLDatatype\Exception\OutOfBoundsException('Bad Character');
     }
     parent::setValue($value);
 }
 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();
 }
 public static function jsniName(Clazz $clazz)
 {
     if ($clazz->isPrimitive()) {
         if ($clazz === Boolean::typeClass()) {
             return 'Z';
         } else {
             if ($clazz === Byte::typeClass()) {
                 return 'B';
             } else {
                 if ($clazz === Character::typeClass()) {
                     return 'C';
                 } else {
                     if ($clazz === Short::typeClass()) {
                         return 'S';
                     } else {
                         if ($clazz === Integer::typeClass()) {
                             return 'I';
                         } else {
                             if ($clazz === Long::typeClass()) {
                                 return 'J';
                             } else {
                                 if ($clazz === Float::typeClass()) {
                                     return 'F';
                                 } else {
                                     if ($clazz === Double::typeClass()) {
                                         return 'D';
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         throw new RuntimeException('Unhandled primitive tye ' + $clazz->getName());
     } else {
         if ($clazz->isArray()) {
             return '[' . self::jsniName($clazz->getComponentType());
         } else {
             return 'L' . str_replace('.', '/', $clazz->getFullName()) . ';';
         }
     }
 }
 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);
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
 public function getTargetType()
 {
     return Byte::typeClass();
 }
 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());
 }
 public function readByte()
 {
     $value = $this->extract();
     try {
         return Byte::parseByte($value);
     } catch (NumberFormatException $e) {
         throw $this->getNumberFormatException($value, 'byte', Byte::MIN_VALUE, Byte::MAX_VALUE);
     }
 }
 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);
     }
 }
Exemple #10
0
 public function byteValue()
 {
     return Byte::asNative($this->value);
 }
 public static function init()
 {
     $JRE_BLACKLIST = array(Boolean::clazz(), Byte::clazz(), Clazz::clazz(), Double::clazz(), Float::clazz(), Integer::clazz(), Long::clazz(), Short::clazz(), String::clazz(), Classes::classOf('ArrayList'), Classes::classOf('Date'), Classes::classOf('HashMap'), Classes::classOf('HashSet'), Classes::classOf('Stack'), Classes::classOf('Vector'));
     self::$JRE_BLACKSET = new HashSet(self::$JRE_BLACKLIST);
     self::$sInstance = new LegacySerializationPolicy();
 }
 public static function init()
 {
     self::$JS_CHARS_ESCAPED[chr(0)] = '0';
     self::$JS_CHARS_ESCAPED[""] = 'b';
     self::$JS_CHARS_ESCAPED["\t"] = 't';
     self::$JS_CHARS_ESCAPED["\n"] = 'n';
     self::$JS_CHARS_ESCAPED["\f"] = 'f';
     self::$JS_CHARS_ESCAPED["\r"] = 'r';
     self::$JS_CHARS_ESCAPED[self::JS_ESCAPE_CHAR] = self::JS_ESCAPE_CHAR;
     self::$JS_CHARS_ESCAPED[self::JS_QUOTE_CHAR] = self::JS_QUOTE_CHAR;
     self::$CLASS_TO_VALUE_WRITER = new IdentityHashMap();
     self::$CLASS_TO_VECTOR_WRITER = new IdentityHashMap();
     self::$CLASS_TO_VECTOR_WRITER->put(Classes::classOf('boolean[]'), SSSW_VectorWriter::$BOOLEAN_VECTOR);
     self::$CLASS_TO_VECTOR_WRITER->put(Classes::classOf('byte[]'), SSSW_VectorWriter::$BYTE_VECTOR);
     self::$CLASS_TO_VECTOR_WRITER->put(Classes::classOf('char[]'), SSSW_VectorWriter::$CHAR_VECTOR);
     self::$CLASS_TO_VECTOR_WRITER->put(Classes::classOf('double[]'), SSSW_VectorWriter::$DOUBLE_VECTOR);
     self::$CLASS_TO_VECTOR_WRITER->put(Classes::classOf('float[]'), SSSW_VectorWriter::$FLOAT_VECTOR);
     self::$CLASS_TO_VECTOR_WRITER->put(Classes::classOf('int[]'), SSSW_VectorWriter::$INT_VECTOR);
     self::$CLASS_TO_VECTOR_WRITER->put(Classes::classOf('long[]'), SSSW_VectorWriter::$LONG_VECTOR);
     self::$CLASS_TO_VECTOR_WRITER->put(Classes::classOf('Object[]'), SSSW_VectorWriter::$OBJECT_VECTOR);
     self::$CLASS_TO_VECTOR_WRITER->put(Classes::classOf('short[]'), SSSW_VectorWriter::$SHORT_VECTOR);
     self::$CLASS_TO_VECTOR_WRITER->put(Classes::classOf('String[]'), SSSW_VectorWriter::$STRING_VECTOR);
     self::$CLASS_TO_VALUE_WRITER->put(Boolean::typeClass(), SSSW_ValueWriter::$BOOLEAN);
     self::$CLASS_TO_VALUE_WRITER->put(Byte::typeClass(), SSSW_ValueWriter::$BYTE);
     self::$CLASS_TO_VALUE_WRITER->put(Character::typeClass(), SSSW_ValueWriter::$CHAR);
     self::$CLASS_TO_VALUE_WRITER->put(Double::typeClass(), SSSW_ValueWriter::$DOUBLE);
     self::$CLASS_TO_VALUE_WRITER->put(Float::typeClass(), SSSW_ValueWriter::$FLOAT);
     self::$CLASS_TO_VALUE_WRITER->put(Integer::typeClass(), SSSW_ValueWriter::$INT);
     self::$CLASS_TO_VALUE_WRITER->put(Long::typeClass(), SSSW_ValueWriter::$LONG);
     self::$CLASS_TO_VALUE_WRITER->put(Object::clazz(), SSSW_ValueWriter::$OBJECT);
     self::$CLASS_TO_VALUE_WRITER->put(Short::typeClass(), SSSW_ValueWriter::$SHORT);
     self::$CLASS_TO_VALUE_WRITER->put(String::clazz(), SSSW_ValueWriter::$STRING);
 }
Classes::register('Byte', new JavaClazz('Byte', $objClass));
Classes::register('Long', new JavaClazz('Long', $objClass));
Classes::register('Short', new JavaClazz('Short', $objClass));
Classes::register('Integer', new JavaClazz('Integer', $objClass));
Classes::register('Character', new JavaClazz('Character', $objClass));
Classes::register('String', new JavaClazz('String', $objClass));
Classes::register('Float', new JavaClazz('Float', $objClass));
Classes::register('Double', new JavaClazz('Double', $objClass));
Classes::register('Void', new JavaClazz('Void', $objClass));
// Aliases
Classes::registerAlias('string', String::clazz());
Classes::registerAlias('bool', Boolean::typeClass());
// Signatures
Classes::registerSignature(Boolean::SIGNATURE, Boolean::typeClass());
Classes::registerSignature(Byte::SIGNATURE, Byte::typeClass());
Classes::registerSignature(Character::SIGNATURE, Character::typeClass());
Classes::registerSignature(Double::SIGNATURE, Double::typeClass());
Classes::registerSignature(Float::SIGNATURE, Float::typeClass());
Classes::registerSignature(Integer::SIGNATURE, Integer::typeClass());
Classes::registerSignature(Long::SIGNATURE, Long::typeClass());
Classes::registerSignature(Short::SIGNATURE, Short::typeClass());
// Assignable From
Long::typeClass()->registerAssignableFrom(array(Double::typeClass(), Integer::typeClass(), Character::typeClass(), Short::typeClass(), Byte::typeClass()));
Integer::typeClass()->registerAssignableFrom(array(Character::typeClass(), Short::typeClass(), Byte::typeClass()));
Character::typeClass()->registerAssignableFrom(array(Integer::typeClass(), Short::typeClass(), Byte::typeClass()));
Short::typeClass()->registerAssignableFrom(array(Integer::typeClass(), Byte::typeClass()));
Byte::typeClass()->registerAssignableFrom(array(Integer::typeClass()));
Double::typeClass()->registerAssignableFrom(array(Float::typeClass()));
Float::typeClass()->registerAssignableFrom(array(Double::typeClass()));
Character::typeClass()->registerAssignableFrom(array(String::clazz()));
String::clazz()->registerAssignableFrom(array(Character::typeClass()));
Exemple #14
0
 /**
  * This method handles every error from PHP and decides
  * wether this is a real error or not. The type hinting of
  * native types, widening and auto boxing is supported through this method.
  *
  * @access private
  * @param int $errorLevel
  * @param string $errorMessage
  * @return boolean False if an error occured, otherwise true
  */
 public static function systemErrorHandler($errorLevel, $errorMessage, $errorFile, $errorLine, &$errorContext)
 {
     switch ($errorLevel) {
         case E_USER_ERROR:
             // User error
         // User error
         case E_WARNING:
             // Runtime warnings
         // Runtime warnings
         case E_USER_WARNING:
             // User warning
         // User warning
         case E_NOTICE:
             // This could be used for operator overloading but the errorContext does not provide references to the objects
             //                var_dump($errorContext);
             //                $keys = array_keys($errorContext);
             //                $errorContext[$keys[count($keys) - 1]] = $errorContext[$keys[count($keys) - 1]]->toNative();
             //                var_dump($errorContext);
             //                return true;
             // Runtime notices
         // This could be used for operator overloading but the errorContext does not provide references to the objects
         //                var_dump($errorContext);
         //                $keys = array_keys($errorContext);
         //                $errorContext[$keys[count($keys) - 1]] = $errorContext[$keys[count($keys) - 1]]->toNative();
         //                var_dump($errorContext);
         //                return true;
         // Runtime notices
         case E_USER_NOTICE:
             // User notice
         // User notice
         case E_DEPRECATED:
         case E_USER_DEPRECATED:
         case E_STRICT:
             break;
             //                return false;
         //                return false;
         case E_RECOVERABLE_ERROR:
             $ok = false;
             $matches = null;
             if (array_key_exists($errorMessage, self::$cachedHints)) {
                 $matches = self::$cachedHints[$errorMessage];
             } else {
                 preg_match('/^Argument (?<argNumber>\\d+) passed to (?<namespace>(([a-zA-Z_]{1}[a-zA-Z0-9_]+)\\\\)+)?[:a-zA-Z0-9_]+\\(\\) must (be an instance of|be an|implement interface) (?<hintName>[a-zA-Z0-9_\\\\]+), (instance of )?(?<typeName>[a-zA-Z0-9_\\\\]+) given/AUD', $errorMessage, $matches);
             }
             if ($matches !== null) {
                 if ($matches['typeName'] === 'null') {
                     throw new NullPointerException();
                 }
                 $argNumber = (int) $matches['argNumber'] - 1;
                 $args = self::getArgsOfErrorCall();
                 switch ($matches['hintName']) {
                     case 'boolean':
                         if ($matches['typeName'] === 'blaze\\lang\\Boolean') {
                             var_dump('Unboxing does not work yet!');
                             $args[$argNumber] = $args[$argNumber]->toNative();
                             $ok = true;
                         } else {
                             $ok = $matches['typeName'] === 'boolean';
                         }
                         break;
                     case 'blaze\\lang\\Boolean':
                         if ($matches['typeName'] === 'boolean') {
                             $args[$argNumber] = new Boolean($args[$argNumber]);
                             $ok = true;
                         }
                         break;
                     case 'byte':
                         switch ($matches['typeName']) {
                             case 'blaze\\lang\\Byte':
                                 var_dump('Unboxing does not work yet!');
                                 $args[$argNumber] = $args[$argNumber]->toNative();
                                 $ok = true;
                                 break;
                             case 'integer':
                             case 'double':
                                 $ok = Byte::isNativeType($args[$argNumber]);
                                 if ($ok) {
                                     $args[$argNumber] = (int) $args[$argNumber];
                                 }
                         }
                         break;
                     case 'blaze\\lang\\Byte':
                         if ($matches['typeName'] === 'integer' || $matches['typeName'] === 'double') {
                             $ok = Byte::isNativeType($args[$argNumber]);
                             if ($ok) {
                                 $args[$argNumber] = new Byte($args[$argNumber]);
                             }
                         }
                         break;
                     case 'short':
                         switch ($matches['typeName']) {
                             case 'blaze\\lang\\Byte':
                             case 'blaze\\lang\\Short':
                                 var_dump('Unboxing does not work yet!');
                                 $args[$argNumber] = $args[$argNumber]->toNative();
                                 $ok = true;
                                 break;
                             case 'integer':
                             case 'double':
                                 $ok = Short::isNativeType($args[$argNumber]);
                                 if ($ok) {
                                     $args[$argNumber] = (int) $args[$argNumber];
                                 }
                         }
                         break;
                     case 'blaze\\lang\\Short':
                         switch ($matches['typeName']) {
                             case 'blaze\\lang\\Byte':
                                 $args[$argNumber] = new Short($args[$argNumber]->toNative());
                                 $ok = true;
                                 break;
                             case 'integer':
                             case 'double':
                                 $ok = Short::isNativeType($args[$argNumber]);
                                 if ($ok) {
                                     $args[$argNumber] = new Short($args[$argNumber]);
                                 }
                         }
                         break;
                     case 'int':
                         switch ($matches['typeName']) {
                             case 'integer':
                                 $ok = true;
                                 break;
                             case 'blaze\\lang\\Byte':
                             case 'blaze\\lang\\Short':
                             case 'blaze\\lang\\Integer':
                                 var_dump('Unboxing does not work yet!');
                                 $args[$argNumber] = $args[$argNumber]->toNative();
                                 $ok = true;
                                 break;
                             case 'double':
                                 $ok = Integer::isNativeType($args[$argNumber]);
                                 if ($ok) {
                                     $args[$argNumber] = (int) $args[$argNumber];
                                 }
                         }
                         break;
                     case 'blaze\\lang\\Integer':
                         switch ($matches['typeName']) {
                             case 'blaze\\lang\\Byte':
                             case 'blaze\\lang\\Short':
                                 $args[$argNumber] = new Integer($args[$argNumber]->toNative());
                                 $ok = true;
                                 break;
                             case 'integer':
                             case 'double':
                                 $ok = Integer::isNativeType($args[$argNumber]);
                                 if ($ok) {
                                     $args[$argNumber] = new Integer($args[$argNumber]);
                                 }
                         }
                         break;
                     case 'long':
                         switch ($matches['typeName']) {
                             case 'integer':
                                 $ok = true;
                                 break;
                             case 'blaze\\lang\\Byte':
                             case 'blaze\\lang\\Short':
                             case 'blaze\\lang\\Integer':
                             case 'blaze\\lang\\Long':
                                 var_dump('Unboxing does not work yet!');
                                 $args[$argNumber] = $args[$argNumber]->toNative();
                                 $ok = true;
                                 break;
                             case 'double':
                                 $ok = Long::isNativeType($args[$argNumber]);
                                 if ($ok) {
                                     $args[$argNumber] = (double) $args[$argNumber];
                                 }
                         }
                         break;
                     case 'blaze\\lang\\Long':
                         switch ($matches['typeName']) {
                             case 'blaze\\lang\\Byte':
                             case 'blaze\\lang\\Short':
                             case 'blaze\\lang\\Integer':
                                 $args[$argNumber] = new Long($args[$argNumber]->toNative());
                                 $ok = true;
                                 break;
                             case 'integer':
                             case 'double':
                                 $ok = Long::isNativeType($args[$argNumber]);
                                 if ($ok) {
                                     $args[$argNumber] = new Long($args[$argNumber]);
                                 }
                         }
                         break;
                     case 'float':
                         switch ($matches['typeName']) {
                             case 'integer':
                                 $ok = true;
                                 break;
                             case 'blaze\\lang\\Byte':
                             case 'blaze\\lang\\Short':
                             case 'blaze\\lang\\Integer':
                             case 'blaze\\lang\\Long':
                             case 'blaze\\lang\\Float':
                                 var_dump('Unboxing does not work yet!');
                                 $args[$argNumber] = $args[$argNumber]->toNative();
                                 $ok = true;
                                 break;
                             case 'double':
                                 $ok = Float::isNativeType($args[$argNumber]);
                                 if ($ok) {
                                     $args[$argNumber] = (double) $args[$argNumber];
                                 }
                         }
                         break;
                     case 'blaze\\lang\\Float':
                         switch ($matches['typeName']) {
                             case 'blaze\\lang\\Byte':
                             case 'blaze\\lang\\Short':
                             case 'blaze\\lang\\Integer':
                             case 'blaze\\lang\\Long':
                                 $args[$argNumber] = new Float($args[$argNumber]->toNative());
                                 $ok = true;
                                 break;
                             case 'integer':
                             case 'double':
                                 $ok = Float::isNativeType($args[$argNumber]);
                                 if ($ok) {
                                     $args[$argNumber] = new Float($args[$argNumber]);
                                 }
                         }
                         break;
                     case 'double':
                         switch ($matches['typeName']) {
                             case 'integer':
                                 $ok = true;
                                 break;
                             case 'blaze\\lang\\Byte':
                             case 'blaze\\lang\\Short':
                             case 'blaze\\lang\\Integer':
                             case 'blaze\\lang\\Long':
                             case 'blaze\\lang\\Float':
                             case 'blaze\\lang\\Double':
                                 var_dump('Unboxing does not work yet!');
                                 $args[$argNumber] = $args[$argNumber]->toNative();
                                 $ok = true;
                                 break;
                             case 'double':
                                 $ok = Double::isNativeType($args[$argNumber]);
                                 if ($ok) {
                                     $args[$argNumber] = (double) $args[$argNumber];
                                 }
                         }
                         break;
                     case 'blaze\\lang\\Double':
                         switch ($matches['typeName']) {
                             case 'blaze\\lang\\Byte':
                             case 'blaze\\lang\\Short':
                             case 'blaze\\lang\\Integer':
                             case 'blaze\\lang\\Long':
                             case 'blaze\\lang\\Float':
                                 $args[$argNumber] = new Double($args[$argNumber]->toNative());
                                 $ok = true;
                                 break;
                             case 'integer':
                             case 'double':
                                 $ok = Double::isNativeType($args[$argNumber]);
                                 if ($ok) {
                                     $args[$argNumber] = new Double($args[$argNumber]);
                                 }
                                 break;
                         }
                         break;
                     case 'char':
                         switch ($matches['typeName']) {
                             case 'string':
                                 $ok = Character::isNativeType($args[$argNumber]);
                                 break;
                             case 'blaze\\lang\\Character':
                                 var_dump('Unboxing does not work yet!');
                                 $args[$argNumber] = $args[$argNumber]->toNative();
                                 $ok = true;
                                 break;
                         }
                         break;
                     case 'blaze\\lang\\Character':
                         if ($matches['typeName'] === 'string') {
                             $ok = Character::isNativeType($args[$argNumber]);
                             if ($ok) {
                                 $args[$argNumber] = new Character($args[$argNumber]);
                             }
                         }
                         break;
                     case 'string':
                         switch ($matches['typeName']) {
                             case 'integer':
                             case 'double':
                                 $args[$argNumber] = (string) $args[$argNumber];
                                 $ok = true;
                                 break;
                             case 'blaze\\lang\\String':
                                 var_dump('Unboxing does not work yet!');
                                 $args[$argNumber] = $args[$argNumber]->toNative();
                                 $ok = true;
                                 break;
                         }
                         break;
                     case 'blaze\\lang\\String':
                         if ($matches['typeName'] === 'string') {
                             $args[$argNumber] = new String($args[$argNumber]);
                             $ok = true;
                         }
                         break;
                     case 'array':
                         switch ($matches['typeName']) {
                             case 'object':
                                 if (!$args[$argNumber] instanceof \blaze\collections\ArrayI) {
                                     break;
                                 }
                             case 'blaze\\collections\\arrays\\ArrayObject':
                                 var_dump('Unboxing does not work yet!');
                                 $args[$argNumber] = $args[$argNumber]->toNative();
                                 $ok = true;
                                 break;
                         }
                         break;
                     case 'blaze\\collections\\ArrayI':
                     case 'blaze\\collections\\arrays\\ArrayObject':
                         if ($matches['typeName'] === 'array') {
                             $ok = \blaze\collections\arrays\ArrayObject::isNativeType($args[$argNumber]);
                             if ($ok) {
                                 $args[$argNumber] = new \blaze\collections\arrays\ArrayObject($args[$argNumber]);
                             }
                         }
                         break;
                     case 'blaze\\math\\BigInteger':
                         switch ($matches['typeName']) {
                             case 'blaze\\lang\\Byte':
                             case 'blaze\\lang\\Short':
                             case 'blaze\\lang\\Integer':
                             case 'blaze\\lang\\Long':
                                 var_dump('Unboxing does not work yet!');
                                 $args[$argNumber] = new \blaze\math\BigInteger($args[$argNumber]->toNative());
                                 $ok = true;
                                 break;
                             case 'integer':
                             case 'double':
                             case 'string':
                                 $ok = \blaze\math\BigInteger::isNativeType($args[$argNumber]);
                                 if ($ok) {
                                     $args[$argNumber] = new \blaze\math\BigInteger($args[$argNumber]);
                                 }
                         }
                         break;
                     case 'blaze\\math\\BigDecimal':
                         switch ($matches['typeName']) {
                             case 'blaze\\lang\\Byte':
                             case 'blaze\\lang\\Short':
                             case 'blaze\\lang\\Integer':
                             case 'blaze\\lang\\Long':
                             case 'blaze\\lang\\Float':
                             case 'blaze\\lang\\Double':
                             case 'blaze\\math\\BigInteger':
                                 var_dump('Unboxing does not work yet!');
                                 $args[$argNumber] = new \blaze\math\BigDecimal($args[$argNumber]->toNative());
                                 $ok = true;
                                 break;
                             case 'integer':
                             case 'double':
                             case 'string':
                                 $ok = \blaze\math\BigDecimal::isNativeType($args[$argNumber]);
                                 if ($ok) {
                                     $args[$argNumber] = new \blaze\math\BigDecimal($args[$argNumber]);
                                 }
                         }
                         break;
                     case 'blaze\\lang\\Reflectable':
                     case 'blaze\\lang\\Object':
                         switch ($matches['typeName']) {
                             case 'boolean':
                                 $args[$argNumber] = new Boolean($args[$argNumber]);
                                 $ok = true;
                                 break;
                             case 'integer':
                             case 'double':
                                 if (($class = Number::getNumberClass($args[$argNumber])) != null) {
                                     if (Integer::isNativeType($args[$argNumber])) {
                                         $className = 'blaze\\lang\\Integer';
                                     } else {
                                         if (Double::isNativeType($args[$argNumber])) {
                                             $className = 'blaze\\lang\\Double';
                                         } else {
                                             $className = $class->getName()->toNative();
                                         }
                                     }
                                     $args[$argNumber] = $className::asWrapper($args[$argNumber]);
                                     $ok = true;
                                 }
                                 break;
                             case 'string':
                                 if (\blaze\math\BigInteger::isNativeType($args[$argNumber])) {
                                     $args[$argNumber] = new \blaze\math\BigInteger($args[$argNumber]);
                                 } else {
                                     if (\blaze\math\BigDecimal::isNativeType($args[$argNumber])) {
                                         $args[$argNumber] = new \blaze\math\BigDecimal($args[$argNumber]);
                                     } else {
                                         $args[$argNumber] = new String($args[$argNumber]);
                                     }
                                 }
                                 $ok = true;
                                 break;
                             case 'array':
                                 $args[$argNumber] = new \blaze\collections\arrays\ArrayObject($args[$argNumber]);
                                 $ok = true;
                                 break;
                         }
                         break;
                     default:
                         $ok = false;
                 }
                 if ($ok) {
                     self::$cachedHints[$errorMessage] = $matches;
                     return true;
                 }
                 return false;
             }
     }
     return false;
 }
Exemple #15
0
 public function getFitnessScoreBinary($string)
 {
     $current = str_split($this->getGeneBinaryString());
     $target = [];
     foreach (str_split($string) as $char) {
         $gene = new Byte(ord($char));
         foreach (str_split($gene->getBinaryString()) as $bit) {
             $target[] = $bit;
         }
     }
     $score = 0;
     foreach ($target as $i => $bit) {
         if ($bit == $current[$i]) {
             $score++;
         }
     }
     return $score;
 }
Exemple #16
0
 public static function getByteHash($value)
 {
     $value = Byte::asNative($value);
     return $value;
 }