Exemplo n.º 1
0
 /**
  * @param   string  $name   The type name
  * @return  TIVarType
  * @throws  \Exception
  */
 public static function createFromName($name = '')
 {
     if (TIVarTypes::isValidName($name)) {
         $instance = new self();
         $instance->name = $name;
         $instance->id = TIVarTypes::getIDFromName($name);
         $instance->exts = TIVarTypes::getExtensionsFromName($name);
         $instance->typeHandler = self::determineTypeHandler($instance->id);
         return $instance;
     } else {
         throw new \RuntimeException('Invalid type name');
     }
 }
Exemplo n.º 2
0
echo "testReal.getReadableContent() : " . $testReal->getReadableContent() . "\n";
assert($testReal->getReadableContent() == "-42.1337");
$testData = tivars\TypeHandlers\TH_0x05::makeDataFromString("\"<\":Asm(prgmABCD");
$goodTypeForCalc = TIVarFile::createNew(TIVarType::createFromName("Program"), "Bla", TIModel::createFromName("83PCE"));
$goodTypeForCalc->setContentFromData($testData);
$test = $goodTypeForCalc->getReadableContent();
$goodTypeForCalc->setContentFromString($test);
echo $goodTypeForCalc->getReadableContent() . "\n";
//$goodTypeForCalc->saveVarToFile();
$badTypeForCalc = TIVarFile::createNew(TIVarType::createFromName('ExactComplexFrac'), 'Bla', TIModel::createFromName('83PCE'));
try {
    $goodTypeForCalc = TIVarFile::createNew(TIVarType::createFromName('ExactComplexFrac'), 'Bla', TIModel::createFromName('84+'));
    assert(false);
} catch (Exception $e) {
}
assert(TIVarTypes::getIDFromName("ExactRealPi") === 32);
$testPrgm = TIVarFile::loadFromFile('testData/Program.8xp');
echo "testPrgm->getHeader()['entries_len'] == " . $testPrgm->getHeader()['entries_len'] . "\n";
echo "testPrgm->size() - 57 == " . ($testPrgm->size() - 57) . "\n";
assert($testPrgm->getHeader()['entries_len'] === $testPrgm->size() - 57);
$newPrgm = TIVarFile::createNew(TIVarType::createFromName("Program"));
$testPrgmcontent = $testPrgm->getReadableContent(['lang' => 'fr']);
//echo "testPrgmContent :\n$testPrgmcontent\n";
$newPrgm->setContentFromString($testPrgmcontent);
assert($testPrgm->getRawContent() === $newPrgm->getRawContent());
$testPrgm = TIVarFile::loadFromFile('testData/ProtectedProgram_long.8xp');
$testPrgmcontent = $testPrgm->getReadableContent(['prettify' => true, 'reindent' => true]);
//echo "All prettified and reindented:\n" . $testPrgmcontent . "\n";
// For HTML output:
// echo '<pre><code>' . htmlentities($testPrgmcontent, ENT_QUOTES) . '</code></pre>';
//$testPrgm->saveVarToFile("testData", "ProtectedProgram_long_Resaved");