Esempio n. 1
0
 public static function createNew(TIVarType $type = null, $name = '', TIModel $version = null)
 {
     if ($type !== null) {
         if ($name === '') {
             $name = 'FILE' . (count($type->getExts()) > 0 ? $type->getExts()[0] : '');
         }
         $newName = preg_replace('/[^a-zA-Z0-9]/', '', $name);
         if ($newName !== $name || strlen($newName) > 8 || $newName === '' || is_numeric($newName[0])) {
             throw new \Exception("Invalid name given. 8 chars (A-Z, 0-9) max, starting by a letter");
         }
         $name = strtoupper(substr($name, 0, 8));
         $instance = new self();
         $instance->type = $type;
         $instance->calcModel = $version !== null ? $version : TIModel::createFromName('84+');
         // default
         if (!$instance->calcModel->supportsType($instance->type)) {
             throw new \Exception('This calculator model (' . $instance->calcModel->getName() . ') does not support the type ' . $instance->type->getName());
         }
         $instance->header = ['signature' => $instance->calcModel->getSig(), 'sig_extra' => [0x1a, 0xa, 0x0], 'comment' => str_pad("Created by tivars_lib on " . date("M j, Y"), 42, ""), 'entries_len' => 0];
         $calcFlags = $instance->calcModel->getFlags();
         $instance->varEntry = ['constBytes' => [0xd, 0x0], 'data_length' => 0, 'typeID' => $type->getId(), 'varname' => str_pad($name, 8, ""), 'version' => $calcFlags >= TIFeatureFlags::hasFlash ? 0 : null, 'archivedFlag' => $calcFlags >= TIFeatureFlags::hasFlash ? 0 : null, 'data_length2' => 0, 'data' => []];
         return $instance;
     } else {
         throw new \Exception("No type given");
     }
 }
Esempio n. 2
0
 private function fixVarName($name = '')
 {
     if ($name === '') {
         $name = 'FILE' . (count($this->type->getExts()) > 0 ? $this->type->getExts()[0] : '');
     }
     $newName = preg_replace('/[^a-zA-Z0-9]/', '', $name);
     if ($newName !== $name || strlen($newName) > 8 || $newName === '' || is_numeric($newName[0])) {
         throw new \InvalidArgumentException('Invalid name given. 8 chars (A-Z, 0-9) max, starting by a letter');
     }
     $name = strtoupper(substr($name, 0, 8));
     return $name;
 }
Esempio n. 3
0
 public function supportsType(TIVarType $type)
 {
     $exts = $type->getExts();
     return isset($exts[$this->orderID]) && $exts[$this->orderID] !== null;
 }